Skip to content

Commit

Permalink
filter illegal device states add water test alarm (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbouwh committed Jun 15, 2022
1 parent 4089479 commit 8a02a79
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion elro/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Elro connects P1 API."""

__version__ = "0.4.2"
__version__ = "0.4.3"
10 changes: 10 additions & 0 deletions elro/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ class CommandAttributes(TypedDict):
content_sync_finished=2,
content_transformer=None,
)
# TEST_ALARM for water detector
TEST_ALARM_WATER = CommandAttributes(
cmd_id=Command.EQUIPMENT_CONTROL,
attribute_transformer=None,
additional_attributes={"device_ID": 0, "device_status": "BB000000"},
receive_types=[Command.ANSWER_YES_OR_NO],
content_field="answer_yes_or_no",
content_sync_finished=2,
content_transformer=None,
)

SILENCE_ALARM = CommandAttributes(
cmd_id=Command.EQUIPMENT_CONTROL,
Expand Down
16 changes: 10 additions & 6 deletions elro/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,17 +273,21 @@ def set_device_name(argv: dict) -> None:

def get_device_states(content: list) -> dict:
"""Return device states."""

return {
hexdata["device_ID"]: {
"device_type": DeviceType(hexdata["device_name"]).name,
hexdata = {}
for hexdata in content:
try:
device_type = DeviceType(hexdata["device_name"]).name
except ValueError:
# Unsupported record, skip and continue silently
continue
hexdata["device_ID"] = {
"device_type": device_type,
"signal": int(hexdata["device_status"][0:2], 16),
"battery": int(hexdata["device_status"][2:4], 16),
"device_state": DEVICE_STATE.get(hexdata["device_status"][4:6], "n/a"),
"device_status_data": hexdata,
}
for hexdata in content
}
return hexdata


def get_default(content: list) -> dict:
Expand Down
3 changes: 2 additions & 1 deletion examples/fire_alarm_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ async def async_demo(self) -> None:
await self.async_disconnect()

# Test alarm (assuming there are 3 fire alarms)
# Be aware they cannot be fired alle together, silence an alarm befor testing the next alarm.
# Be aware they cannot be fired alle together, silence an alarm before testing the next alarm.
# Use TEST_ALARM_WATER for water detectors
await self.async_connect()
print("Test alarm 1")
await self.async_process_command(TEST_ALARM, device_ID=1)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[metadata]
name = lib-elro-connects
author = Jan Bouwhuis, Bas van den Berg, Johannes Kulick
version = 0.4.2
version = 0.4.3
description = Provides an API to the Elro Connects K1 Connector
long_description = file: README.md, LICENSE
license = MIT License
Expand Down

0 comments on commit 8a02a79

Please sign in to comment.