Use new elkm1-lib module's LD log data support to correctly identify user_ids (#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 https://github.com/home-assistant/core/issues/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
This commit is contained in:
gjbadros 2020-05-28 16:26:03 -07:00 committed by GitHub
parent b928d5d4b6
commit f9aff4fc41
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 5 deletions

View file

@ -125,8 +125,10 @@ class ElkArea(ElkAttachedEntity, AlarmControlPanelEntity, RestoreEntity):
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()
@ -152,6 +154,21 @@ class ElkArea(ElkAttachedEntity, AlarmControlPanelEntity, RestoreEntity):
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."""