Skip to content

Commit ae06bdc

Browse files
authored
Silence swapped direction warning for Aqara devices (#4239)
* Silence swapped direction for Xiaomi devices * Update test * Bump zigpy to latest
1 parent ad0dc81 commit ae06bdc

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ readme = "README.md"
1414
license = {text = "Apache-2.0"}
1515
requires-python = ">=3.12"
1616
dependencies = [
17-
"zigpy>=0.82.0",
17+
"zigpy>=0.82.2",
1818
]
1919

2020
[tool.setuptools.packages.find]

tests/test_xiaomi.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2259,22 +2259,26 @@ def test_t1m_ceiling_light(zigpy_device_from_v2_quirk, endpoint):
22592259
assert cluster_listener.attribute_updates[1][1] == LumiPowerOnStateMode.Off
22602260

22612261

2262-
async def test_lumi_magnet_sensor_aq2_bad_direction(zigpy_device_from_quirk):
2262+
async def test_lumi_magnet_sensor_aq2_bad_direction(zigpy_device_from_quirk, caplog):
22632263
"""Test Aqara Magnet Sensor AQ2 quirk dealing with bad ZCL command direction."""
22642264

22652265
device = zigpy_device_from_quirk(zhaquirks.xiaomi.aqara.magnet_aq2.MagnetAQ2)
22662266
listener = ClusterListener(device.endpoints[1].out_clusters[OnOff.cluster_id])
22672267

22682268
# The device has a bad ZCL header and reports the incorrect direction for commands
2269-
device.packet_received(
2270-
t.ZigbeePacket(
2271-
profile_id=260,
2272-
cluster_id=6,
2273-
src_ep=1,
2274-
dst_ep=1,
2275-
data=t.SerializableBytes(bytes.fromhex("18930A00001001")),
2269+
with caplog.at_level(logging.WARNING):
2270+
device.packet_received(
2271+
t.ZigbeePacket(
2272+
profile_id=260,
2273+
cluster_id=6,
2274+
src_ep=1,
2275+
dst_ep=1,
2276+
data=t.SerializableBytes(bytes.fromhex("18930A00001001")),
2277+
)
22762278
)
2277-
)
2279+
2280+
# No warning gets logged
2281+
assert not caplog.text
22782282

22792283
# Our matching logic should be forgiving
22802284
assert listener.attribute_updates == [(0, t.Bool.true)]

zhaquirks/xiaomi/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,13 @@ def _find_zcl_cluster(
130130
# Aqara devices seem to be very lax with their ZCL header's `direction` field,
131131
# we should try "flipping" it if matching doesn't work normally.
132132
try:
133-
return super()._find_zcl_cluster(hdr, packet)
133+
return super()._find_zcl_cluster_strict(hdr, packet)
134134
except KeyError:
135135
_LOGGER.debug(
136136
"Packet is coming in the wrong direction, swapping direction and trying again",
137137
)
138138

139-
return super()._find_zcl_cluster(
139+
return super()._find_zcl_cluster_strict(
140140
hdr.replace(
141141
frame_control=hdr.frame_control.replace(
142142
direction=hdr.frame_control.direction.flip()

0 commit comments

Comments
 (0)