Skip to content

Commit

Permalink
Fix time pattern for giot.light.v5ssm #1142
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Mar 24, 2024
1 parent e212d4a commit 393743c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
28 changes: 28 additions & 0 deletions custom_components/xiaomi_gateway3/core/converters/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,31 @@ def encode(self, device: "XDevice", payload: dict, value: str):
if v in "+xv":
mask |= 1 << i
super().encode(device, payload, mask)


class GiotTimePatternConv(BaseConv):
"""
Period encoding:
8-digit number: HHMMhhmm
HH = start hour
MM = start minute
hh = end hour
mm = end minute
Example:
Period: 23:59 - 10:44
Encoded: 23591044
"""

pattern = "^[0-2][0-9]:[0-5][0-9]-[0-2][0-9]:[0-5][0-9]$"

def decode(self, device: "XDevice", payload: dict, value: int):
value = str(value)
if len(value) != 8:
return
payload[self.attr] = f"{value[:2]}:{value[2:4]}-{value[4:6]}:{value[6:]}"

def encode(self, device: "XDevice", payload: dict, value: str):
value = value.replace(":", "").replace("-", "")
if len(value) != 8:
return
super().encode(device, payload, int(value))
2 changes: 1 addition & 1 deletion custom_components/xiaomi_gateway3/core/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -2777,7 +2777,7 @@
MathConv("turn_off_transit_sec", "number", mi="3.p.18", multiply=0.001, min=100, max=30000, step=100, round=1, entity=ENTITY_CONFIG),
MathConv("change_transit_sec", "number", mi="3.p.19", multiply=0.001, min=100, max=30000, step=100, round=1, entity=ENTITY_CONFIG),
MathConv("min_brightness", "number", mi="3.p.23", multiply=0.1, min=1, max=500, step=1, round=1, entity=ENTITY_CONFIG),
# TODO GiotTimePatternConv("night_light_time", "text", mi="3.p.16")
GiotTimePatternConv("night_light_time", "text", mi="3.p.16", entity=ENTITY_CONFIG)
# Converter("fill_light_detection", "sensor", mi="3.p.20"),
# Converter("fill_light_switch", "switch", mi="3.p.21"),
# MathConv("min_bri_factory", "number", mi="3.p.16", min=1, max=500),
Expand Down
10 changes: 10 additions & 0 deletions tests/test_conv_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,13 @@ def test_es1():

p = device.encode({"induction_range": "0+0.8+1.5+2.3+3.0_3.8_4.5_5.3_6"})
assert p == {"mi_spec": [{"piid": 2, "siid": 3, "value": 15}]}


def test_11724():
device = XDevice(11724)

p = device.decode({"did": "123", "siid": 3, "piid": 16, "value": 23591044})
assert p == {"night_light_time": "23:59-10:44"}

p = device.encode({"night_light_time": "23:59-10:44"})
assert p == {"mi_spec": [{"siid": 3, "piid": 16, "value": 23591044}]}

0 comments on commit 393743c

Please sign in to comment.