Skip to content

Commit

Permalink
Fix duplicates in device triggers
Browse files Browse the repository at this point in the history
AlexxIT committed Sep 4, 2024

Verified

This commit was signed with the committer’s verified signature.
1 parent 8f6078a commit 6a1f3d7
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions custom_components/xiaomi_gateway3/device_trigger.py
Original file line number Diff line number Diff line change
@@ -38,6 +38,12 @@
BUTTONS = [BUTTON_SINGLE, BUTTON_DOUBLE, BUTTON_TRIPLE, BUTTON_HOLD, BUTTON_RELEASE]


def append(dst: list, src):
for i in src:
if i not in dst:
dst.append(i)


def get_actions(human_model: str) -> list[str] | None:
"""Gets a list of actions (buttons) using the device human model."""
if m := re.search(": ([^,]+)", human_model):
@@ -51,15 +57,15 @@ def get_actions(human_model: str) -> list[str] | None:
for conv in converters:
if conv.attr == "action":
if isinstance(conv, ConstConv):
actions.append(conv.value)
append(actions, [conv.value])
elif isinstance(conv, MapConv):
actions += list(conv.map.values())
append(actions, conv.map.values())
elif isinstance(conv, BLEMapConv):
actions += list(conv.map.values())
append(actions, conv.map.values())
elif conv.attr == "button":
actions += BUTTONS
append(actions, BUTTONS)
elif conv.attr.startswith("button"):
actions += [f"{conv.attr}_{i}" for i in BUTTONS]
append(actions, [f"{conv.attr}_{i}" for i in BUTTONS])

return actions

0 comments on commit 6a1f3d7

Please sign in to comment.