From c52b18d7c845b9566f5d93dcad8278747a262485 Mon Sep 17 00:00:00 2001 From: Albert Lee Date: Thu, 8 Jun 2017 17:21:56 -0500 Subject: [PATCH] lock.sesame: Update pysesame, add state attributes (#7953) * Update pysesame requirement to 0.1.0 to support caching * Set `available` property based on API enabled status * Add state attributes for device ID and battery level --- homeassistant/components/lock/sesame.py | 22 ++++++++++++++++++---- requirements_all.txt | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/lock/sesame.py b/homeassistant/components/lock/sesame.py index 316f4f0f5bc..02b049618d2 100644 --- a/homeassistant/components/lock/sesame.py +++ b/homeassistant/components/lock/sesame.py @@ -10,10 +10,13 @@ import voluptuous as vol import homeassistant.helpers.config_validation as cv from homeassistant.components.lock import LockDevice, PLATFORM_SCHEMA from homeassistant.const import ( - CONF_EMAIL, CONF_PASSWORD, STATE_LOCKED, STATE_UNLOCKED) + ATTR_BATTERY_LEVEL, CONF_EMAIL, CONF_PASSWORD, + STATE_LOCKED, STATE_UNLOCKED) from homeassistant.helpers.typing import ConfigType -REQUIREMENTS = ['pysesame==0.0.2'] +REQUIREMENTS = ['pysesame==0.1.0'] + +ATTR_DEVICE_ID = 'device_id' PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ vol.Required(CONF_EMAIL): cv.string, @@ -37,12 +40,10 @@ def setup_platform(hass, config: ConfigType, class SesameDevice(LockDevice): """Representation of a Sesame device.""" - device_id = None _sesame = None def __init__(self, sesame: object) -> None: """Initialize the Sesame device.""" - self.device_id = sesame.device_id self._sesame = sesame @property @@ -50,6 +51,11 @@ class SesameDevice(LockDevice): """Return the name of the device.""" return self._sesame.nickname + @property + def available(self) -> bool: + """Return True if entity is available.""" + return self._sesame.api_enabled + @property def is_locked(self) -> bool: """Return True if the device is currently locked, else False.""" @@ -73,3 +79,11 @@ class SesameDevice(LockDevice): def update(self) -> None: """Update the internal state of the device.""" self._sesame.update_state() + + @property + def device_state_attributes(self) -> dict: + """Return the state attributes.""" + attributes = {} + attributes[ATTR_DEVICE_ID] = self._sesame.device_id + attributes[ATTR_BATTERY_LEVEL] = self._sesame.battery + return attributes diff --git a/requirements_all.txt b/requirements_all.txt index 34cd42a7cf6..6e0e331f563 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -632,7 +632,7 @@ pysensibo==1.0.1 pyserial==3.1.1 # homeassistant.components.lock.sesame -pysesame==0.0.2 +pysesame==0.1.0 # homeassistant.components.sensor.sma pysma==0.1.3