-
Notifications
You must be signed in to change notification settings - Fork 712
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into add_aqaraH2Plug
- Loading branch information
Showing
96 changed files
with
8,755 additions
and
2,313 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,10 +11,10 @@ authors = [ | |
{name = "David F. Mulcahey", email = "[email protected]"} | ||
] | ||
readme = "README.md" | ||
license = {text = "Apache License Version 2.0"} | ||
license = {text = "Apache-2.0"} | ||
requires-python = ">=3.12" | ||
dependencies = [ | ||
"zigpy>=0.65.2", | ||
"zigpy>=0.70.0", | ||
] | ||
|
||
[tool.setuptools.packages.find] | ||
|
@@ -79,7 +79,7 @@ norecursedirs = ".git testing_config" | |
|
||
[tool.codespell] | ||
skip = "Contributors.md" | ||
ignore-words-list = "hass, dout, potentiels" | ||
ignore-words-list = "hass, dout, potentiels, checkin" | ||
quiet-level = 2 | ||
|
||
[tool.ruff] | ||
|
@@ -218,4 +218,4 @@ split-on-trailing-comma = false | |
"script/*" = ["T20"] | ||
|
||
[tool.ruff.lint.mccabe] | ||
max-complexity = 27 | ||
max-complexity = 27 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""Mock utilities that are async aware.""" | ||
|
||
from unittest.mock import * # noqa: F401, F403 | ||
|
||
|
||
class _IntSentinelObject(int): | ||
"""Sentinel-like object that is also an integer subclass. | ||
Allows sentinels to be used | ||
in loggers that perform int-specific string formatting. | ||
""" | ||
|
||
def __new__(cls, name): | ||
instance = super().__new__(cls, 0) | ||
instance.name = name | ||
return instance | ||
|
||
def __repr__(self): | ||
return f"int_sentinel.{self.name}" | ||
|
||
def __hash__(self): | ||
return hash((int(self), self.name)) | ||
|
||
def __eq__(self, other): | ||
return self is other | ||
|
||
__str__ = __reduce__ = __repr__ | ||
|
||
|
||
class _IntSentinel: | ||
def __init__(self): | ||
self._sentinels = {} | ||
|
||
def __getattr__(self, name): | ||
if name == "__bases__": | ||
raise AttributeError | ||
return self._sentinels.setdefault(name, _IntSentinelObject(name)) | ||
|
||
def __reduce__(self): | ||
return "int_sentinel" | ||
|
||
|
||
int_sentinel = _IntSentinel() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
"""Tests for Linxura quirks.""" | ||
|
||
from unittest import mock | ||
|
||
import pytest | ||
from zigpy.zcl.clusters.security import IasZone | ||
|
||
import zhaquirks | ||
import zhaquirks.linxura | ||
|
||
zhaquirks.setup() | ||
|
||
|
||
async def test_button_ias(zigpy_device_from_quirk): | ||
"""Test Linxura button remotes.""" | ||
|
||
device = zigpy_device_from_quirk(zhaquirks.linxura.button.LinxuraButton) | ||
ias_zone_status_attr_id = IasZone.AttributeDefs.zone_status.id | ||
cluster = device.endpoints[1].ias_zone | ||
listener = mock.MagicMock() | ||
cluster.add_listener(listener) | ||
|
||
for i in range(0, 24): | ||
# button press | ||
cluster.update_attribute(ias_zone_status_attr_id, i) | ||
|
||
# update_attribute on the IasZone cluster is always called | ||
assert listener.attribute_updated.call_args[0][0] == ias_zone_status_attr_id | ||
assert listener.attribute_updated.call_args[0][1] == i | ||
|
||
# we get 20 events, 4 are discarded as invalid (0, 6, 12, 18) | ||
assert listener.attribute_updated.call_count == 24 | ||
assert listener.zha_send_event.call_count == 20 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"message, button, press_type", | ||
[ | ||
( | ||
b"\x18\n\n\x02\x00\x19\x01\x00\xfe\xff0\x01", | ||
"button_1", | ||
"remote_button_short_press", | ||
), | ||
( | ||
b"\x18\n\n\x02\x00\x19\x03\x00\xfe\xff0\x01", | ||
"button_1", | ||
"remote_button_double_press", | ||
), | ||
( | ||
b"\x18\n\n\x02\x00\x19\x05\x00\xfe\xff0\x01", | ||
"button_1", | ||
"remote_button_long_press", | ||
), | ||
( | ||
b"\x18\n\n\x02\x00\x19\x07\x00\xfe\xff0\x01", | ||
"button_2", | ||
"remote_button_short_press", | ||
), | ||
( | ||
b"\x18\n\n\x02\x00\x19\x09\x00\xfe\xff0\x01", | ||
"button_2", | ||
"remote_button_double_press", | ||
), | ||
( | ||
b"\x18\n\n\x02\x00\x19\x0b\x00\xfe\xff0\x01", | ||
"button_2", | ||
"remote_button_long_press", | ||
), | ||
( | ||
b"\x18\n\n\x02\x00\x19\x0d\x00\xfe\xff0\x01", | ||
"button_3", | ||
"remote_button_short_press", | ||
), | ||
( | ||
b"\x18\n\n\x02\x00\x19\x0f\x00\xfe\xff0\x01", | ||
"button_3", | ||
"remote_button_double_press", | ||
), | ||
( | ||
b"\x18\n\n\x02\x00\x19\x11\x00\xfe\xff0\x01", | ||
"button_3", | ||
"remote_button_long_press", | ||
), | ||
( | ||
b"\x18\n\n\x02\x00\x19\x13\x00\xfe\xff0\x01", | ||
"button_4", | ||
"remote_button_short_press", | ||
), | ||
( | ||
b"\x18\n\n\x02\x00\x19\x15\x00\xfe\xff0\x01", | ||
"button_4", | ||
"remote_button_double_press", | ||
), | ||
( | ||
b"\x18\n\n\x02\x00\x19\x17\x00\xfe\xff0\x01", | ||
"button_4", | ||
"remote_button_long_press", | ||
), | ||
], | ||
) | ||
async def test_button_triggers(zigpy_device_from_quirk, message, button, press_type): | ||
"""Test ZHA_SEND_EVENT case.""" | ||
device = zigpy_device_from_quirk(zhaquirks.linxura.button.LinxuraButton) | ||
cluster = device.endpoints[1].ias_zone | ||
listener = mock.MagicMock() | ||
cluster.add_listener(listener) | ||
|
||
device.handle_message(260, cluster.cluster_id, 1, 1, message) | ||
assert listener.zha_send_event.call_count == 1 | ||
assert listener.zha_send_event.call_args == mock.call( | ||
f"{button}_{press_type}", | ||
{ | ||
"button": button, | ||
"press_type": press_type, | ||
}, | ||
) |
Oops, something went wrong.