add changed_by attribute to lock (#2766)

This commit is contained in:
Per Sandström 2016-08-10 04:37:46 +02:00 committed by Paulus Schoutsen
parent 431f0fd236
commit 180a7ec295
2 changed files with 14 additions and 0 deletions

View File

@ -22,6 +22,7 @@ from homeassistant.components import group
DOMAIN = 'lock'
SCAN_INTERVAL = 30
ATTR_CHANGED_BY = 'changed_by'
GROUP_NAME_ALL_LOCKS = 'all locks'
ENTITY_ID_ALL_LOCKS = group.ENTITY_ID_FORMAT.format('all_locks')
@ -101,6 +102,11 @@ def setup(hass, config):
class LockDevice(Entity):
"""Representation of a lock."""
@property
def changed_by(self):
"""Last change triggered by."""
return None
# pylint: disable=no-self-use
@property
def code_format(self):
@ -127,6 +133,7 @@ class LockDevice(Entity):
return None
state_attr = {
ATTR_CODE_FORMAT: self.code_format,
ATTR_CHANGED_BY: self.changed_by
}
return state_attr

View File

@ -35,6 +35,7 @@ class VerisureDoorlock(LockDevice):
self._id = device_id
self._state = STATE_UNKNOWN
self._digits = int(hub.config.get('code_digits', '4'))
self._changed_by = None
@property
def name(self):
@ -51,6 +52,11 @@ class VerisureDoorlock(LockDevice):
"""Return True if entity is available."""
return hub.available
@property
def changed_by(self):
"""Last change triggered by."""
return self._changed_by
@property
def code_format(self):
"""Return the required six digit code."""
@ -68,6 +74,7 @@ class VerisureDoorlock(LockDevice):
_LOGGER.error(
'Unknown lock state %s',
hub.lock_status[self._id].status)
self._changed_by = hub.lock_status[self._id].name
@property
def is_locked(self):