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): async def async_added_to_hass(self):
"""Register callback for ElkM1 changes.""" """Register callback for ElkM1 changes."""
await super().async_added_to_hass() await super().async_added_to_hass()
for keypad in self._elk.keypads: if len(self._elk.areas.elements) == 1:
keypad.add_callback(self._watch_keypad) 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. # We do not get changed_by back from resync.
last_state = await self.async_get_last_state() 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._changed_by = username(self._elk, keypad.last_user)
self.async_write_ha_state() 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 @property
def code_format(self): def code_format(self):
"""Return the alarm code format.""" """Return the alarm code format."""

View file

@ -2,7 +2,7 @@
"domain": "elkm1", "domain": "elkm1",
"name": "Elk-M1 Control", "name": "Elk-M1 Control",
"documentation": "https://www.home-assistant.io/integrations/elkm1", "documentation": "https://www.home-assistant.io/integrations/elkm1",
"requirements": ["elkm1-lib==0.7.17"], "requirements": ["elkm1-lib==0.7.18"],
"codeowners": ["@bdraco"], "codeowners": ["@bdraco"],
"config_flow": true "config_flow": true
} }

View file

@ -526,7 +526,7 @@ elgato==0.2.0
eliqonline==1.2.2 eliqonline==1.2.2
# homeassistant.components.elkm1 # homeassistant.components.elkm1
elkm1-lib==0.7.17 elkm1-lib==0.7.18
# homeassistant.components.emulated_roku # homeassistant.components.emulated_roku
emulated_roku==0.2.1 emulated_roku==0.2.1

View file

@ -233,7 +233,7 @@ eebrightbox==0.0.4
elgato==0.2.0 elgato==0.2.0
# homeassistant.components.elkm1 # homeassistant.components.elkm1
elkm1-lib==0.7.17 elkm1-lib==0.7.18
# homeassistant.components.emulated_roku # homeassistant.components.emulated_roku
emulated_roku==0.2.1 emulated_roku==0.2.1