Skip to content

Commit

Permalink
Use new elkm1-lib module's LD log data support to correctly identify …
Browse files Browse the repository at this point in the history
…user_ids (home-assistant#36211)

* Requires 0.7.18 of elkm1 library to decode LD messages, and uses those messages to reliably set the arming/disarming user when there are more than one area.  See home-assistant#35310.

* Fixed typo

* Fixed off by one error -- LD command reports 1-based user-numbers which is the changed_by_id we want, but we need 0-based indices as argument to username.

* Bump required version of elkm1, remove logging message I was using for testing; prepping for PR.

* Black formatted

* Fixed bug whereby I needed to ref elements when running against released build of elkm1-lib
  • Loading branch information
gjbadros authored May 28, 2020
1 parent b928d5d commit f9aff4f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
21 changes: 19 additions & 2 deletions homeassistant/components/elkm1/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ def __init__(self, element, elk, elk_data):
async def async_added_to_hass(self):
"""Register callback for ElkM1 changes."""
await super().async_added_to_hass()
for keypad in self._elk.keypads:
keypad.add_callback(self._watch_keypad)
if len(self._elk.areas.elements) == 1:
for keypad in self._elk.keypads:
keypad.add_callback(self._watch_keypad)
self._element.add_callback(self._watch_area)

# We do not get changed_by back from resync.
last_state = await self.async_get_last_state()
Expand All @@ -152,6 +154,21 @@ def _watch_keypad(self, keypad, changeset):
self._changed_by = username(self._elk, keypad.last_user)
self.async_write_ha_state()

def _watch_area(self, area, changeset):
if not changeset.get("log_event"):
return
self._changed_by_keypad = None
self._changed_by_id = area.log_number
self._changed_by = username(self._elk, area.log_number - 1)
self._changed_by_time = "%04d-%02d-%02dT%02d:%02d" % (
area.log_year,
area.log_month,
area.log_day,
area.log_hour,
area.log_minute,
)
self.async_write_ha_state()

@property
def code_format(self):
"""Return the alarm code format."""
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/elkm1/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"domain": "elkm1",
"name": "Elk-M1 Control",
"documentation": "https://www.home-assistant.io/integrations/elkm1",
"requirements": ["elkm1-lib==0.7.17"],
"requirements": ["elkm1-lib==0.7.18"],
"codeowners": ["@bdraco"],
"config_flow": true
}
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ elgato==0.2.0
eliqonline==1.2.2

# homeassistant.components.elkm1
elkm1-lib==0.7.17
elkm1-lib==0.7.18

# homeassistant.components.emulated_roku
emulated_roku==0.2.1
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ eebrightbox==0.0.4
elgato==0.2.0

# homeassistant.components.elkm1
elkm1-lib==0.7.17
elkm1-lib==0.7.18

# homeassistant.components.emulated_roku
emulated_roku==0.2.1
Expand Down

0 comments on commit f9aff4f

Please sign in to comment.