From 71cb4df817f1cd5e70e22900d35f92928a7a6fab Mon Sep 17 00:00:00 2001 From: Joe Lu Date: Tue, 30 Jan 2018 03:20:20 -0800 Subject: [PATCH] Return all attributes that are not None in base lock entity class (#12049) * Return all attributes that are not None in base lock entity class * Update __init__.py --- homeassistant/components/lock/__init__.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/lock/__init__.py b/homeassistant/components/lock/__init__.py index 80abce4ec3e..d03bbebd696 100644 --- a/homeassistant/components/lock/__init__.py +++ b/homeassistant/components/lock/__init__.py @@ -41,6 +41,11 @@ LOCK_SERVICE_SCHEMA = vol.Schema({ _LOGGER = logging.getLogger(__name__) +PROP_TO_ATTR = { + 'changed_by': ATTR_CHANGED_BY, + 'code_format': ATTR_CODE_FORMAT, +} + @bind_hass def is_locked(hass, entity_id=None): @@ -156,12 +161,11 @@ class LockDevice(Entity): @property def state_attributes(self): """Return the state attributes.""" - if self.code_format is None: - return None - state_attr = { - ATTR_CODE_FORMAT: self.code_format, - ATTR_CHANGED_BY: self.changed_by - } + state_attr = {} + for prop, attr in PROP_TO_ATTR.items(): + value = getattr(self, prop) + if value is not None: + state_attr[attr] = value return state_attr @property