Skip to content

Commit

Permalink
Update converters for water_leak, gas and smoke
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Apr 6, 2024
1 parent 69ccb7d commit 1b24b52
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 26 deletions.
40 changes: 16 additions & 24 deletions custom_components/xiaomi_gateway3/core/converters/zigbee.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,35 +445,27 @@ def decode(self, device: "XDevice", payload: dict, data: dict):
)


# Gateway doesn't unpack moisture status for sensor on firmware 4, don't know why.
class ZLumiWaterLeak(ZConverter):
"""Decode moisture status from Lumi Basic cluster."""

cluster_id = Basic.cluster_id

def decode(self, device: "XDevice", payload: dict, data: dict):
if value := data.get(0xFF01):
payload[self.attr] = bool(value[100])


# Gateway doesn't unpack gas status, don't know why.
class ZLumiGasHeartbeat(ZConverter):
"""Decode gas status from Lumi Basic cluster."""

@dataclass
class ZLumiBasicAlarm(ZConverter):
cluster_id = Basic.cluster_id
basic_attr: int = None

def decode(self, device: "XDevice", payload: dict, data: dict):
# Some old lumi sensors doesn't sends periodic "no alarm" status.
# But they all has this status in the heartbeats (basic cluster).
# For "lumi.sensor_wleak.aq1" on firmware 4 sensor:
# 100: 1 - water leak (sometimes correct, sometimes not)
# 100: 0 - no water leak
# For "lumi.sensor_natgas" and "lumi.sensor_smoke" sensor:
# 150: 0x42000000 - gas
# 150: 0x43000000 - gas and button click
# 150: 0x08000000 - no gas button click
# 150: 0x02040200 - smoke
# 150: 0x03000000 - smoke and button click
# 150: 0 - no gas, no smoke
if value := data.get(0xFF01):
if value[150] == 0:
payload[self.attr] = False
elif value[150] == 0x42000000:
payload[self.attr] = True
elif value[150] == 0x43000000:
payload[self.attr] = True
payload["action"] = BUTTON_SINGLE
elif value[150] == 0x08000000:
if value[self.basic_attr] == 0:
payload[self.attr] = False
payload["action"] = BUTTON_SINGLE


class ZLumiSensConv(ZConverter):
Expand Down
5 changes: 3 additions & 2 deletions custom_components/xiaomi_gateway3/core/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@
BoolConv("moisture", "binary_sensor", mi="3.1.85"),
BatVoltConv("battery", "sensor", mi="8.0.2008"),
BaseConv("battery_original", mi="8.0.2001"), # diagnostic
ZLumiWaterLeak("moisture"), # fix bug for sensors on firmware 4
ZLumiBasicAlarm("moisture", basic_attr=100), # read "no alarm" from heartbeats
],
}, {
# vibration sensor
Expand Down Expand Up @@ -474,6 +474,7 @@
BatVoltConv("battery", "sensor", mi="8.0.2008"),
BaseConv("battery_original", mi="8.0.2001"), # diagnostic
ZLumiSensConv("sensitivity", "select"), # config
ZLumiBasicAlarm("smoke", basic_attr=150), # read "no alarm" from heartbeats
],
}, {
"lumi.sensor_natgas": ["Honeywell", "Gas Sensor", "JTQJ-BF-01LM/BW"],
Expand All @@ -482,7 +483,7 @@
BaseConv("gas_density", "sensor", mi="0.1.85"),
BoolConv("gas", "binary_sensor", mi="13.1.85"),
ZLumiSensConv("sensitivity", "select"), # config
ZLumiGasHeartbeat("gas"),
ZLumiBasicAlarm("gas", basic_attr=150), # read "no alarm" from heartbeats
],
}, {
"lumi.curtain": ["Aqara", "Curtain", "ZNCLDJ11LM"],
Expand Down

0 comments on commit 1b24b52

Please sign in to comment.