Skip to content

Commit 1770aa3

Browse files
committed
Fix unique_id for Zigbee binary sensors
1 parent da68dff commit 1770aa3

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

custom_components/sonoff/core/devices.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ def spec(cls, base: str = None, enabled: bool = None, **kwargs) -> type:
126126
22: [XLightB1, RSSI], # Sonoff B1 (only cloud)
127127
# https://github.com/AlexxIT/SonoffLAN/issues/173
128128
25: [
129-
XDiffuserFan, XDiffuserLight, spec(XBinarySensor, param="water"), RSSI,
129+
XDiffuserFan, XDiffuserLight, RSSI,
130+
spec(XBinarySensor, param="water", uid=""),
130131
], # Diffuser
131132
28: [XRemote, LED, RSSI], # Sonoff RF Brigde 433
132133
29: SPEC_2CH,
@@ -214,9 +215,14 @@ def spec(cls, base: str = None, enabled: bool = None, **kwargs) -> type:
214215
], # ZCL_HA_DEVICEID_TEMPERATURE_SENSOR
215216
2026: [XZigbeeMotion, Battery], # ZIGBEE_MOBILE_SENSOR
216217
# ZIGBEE_DOOR_AND_WINDOW_SENSOR
217-
3026: [spec(XBinarySensor, param="lock", default_class="door"), Battery],
218+
3026: [
219+
# backward compatibility for unique_id
220+
spec(XBinarySensor, param="lock", uid="", default_class="door"),
221+
Battery,
222+
],
218223
4026: [
219-
spec(XBinarySensor, param="water", default_class="moisture"), Battery,
224+
spec(XBinarySensor, param="water", uid="", default_class="moisture"),
225+
Battery,
220226
], # https://github.com/AlexxIT/SonoffLAN/issues/852
221227
4256: [
222228
spec(XZigbeeSwitches, channel=0, uid="1"),

tests/test_entity.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ def test_diffuser():
417417
water = next(e for e in entitites if isinstance(e, XBinarySensor))
418418
assert water.state == "off"
419419
assert water.device_class is None
420-
assert water.unique_id == "1000123abc_water"
420+
assert water.unique_id == DEVICEID
421421

422422

423423
def test_sonoff_sc():
@@ -696,7 +696,7 @@ def test_zigbee_door():
696696
lock: XBinarySensor = entities[0]
697697
assert lock.state == "off"
698698
assert lock.device_class.value == "door"
699-
assert lock.unique_id == "1000123abc_lock"
699+
assert lock.unique_id == DEVICEID
700700

701701

702702
def test_zigbee_water():
@@ -711,7 +711,7 @@ def test_zigbee_water():
711711
water: XBinarySensor = entities[0]
712712
assert water.state == "on"
713713
assert water.device_class.value == "moisture"
714-
assert water.entity_id.endswith(".sonoff_1000123abc_water")
714+
assert water.unique_id == DEVICEID
715715

716716

717717
def test_zigbee_cover():

0 commit comments

Comments
 (0)