Update Sesame component to use Candy House's library using the V3 API (#23621)

* Update Sesame component to use Candy House's library using the V3 API

* Updated requirements_all.txt

* Fix pylint warning

* Revert back to ATTR_DEVICE_ID
This commit is contained in:
Jerry Chong 2019-05-08 23:34:00 +08:00 committed by Paulus Schoutsen
parent c26af22edd
commit 07126266dd
3 changed files with 22 additions and 22 deletions

View File

@ -5,15 +5,15 @@ import voluptuous as vol
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.components.lock import LockDevice, PLATFORM_SCHEMA from homeassistant.components.lock import LockDevice, PLATFORM_SCHEMA
from homeassistant.const import ( from homeassistant.const import (
ATTR_BATTERY_LEVEL, CONF_EMAIL, CONF_PASSWORD, ATTR_BATTERY_LEVEL, CONF_API_KEY,
STATE_LOCKED, STATE_UNLOCKED) STATE_LOCKED, STATE_UNLOCKED)
from homeassistant.helpers.typing import ConfigType from homeassistant.helpers.typing import ConfigType
ATTR_DEVICE_ID = 'device_id' ATTR_DEVICE_ID = 'device_id'
ATTR_SERIAL_NO = 'serial'
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_EMAIL): cv.string, vol.Required(CONF_API_KEY): cv.string
vol.Required(CONF_PASSWORD): cv.string
}) })
@ -21,13 +21,12 @@ def setup_platform(
hass, config: ConfigType, hass, config: ConfigType,
add_entities: Callable[[list], None], discovery_info=None): add_entities: Callable[[list], None], discovery_info=None):
"""Set up the Sesame platform.""" """Set up the Sesame platform."""
import pysesame import pysesame2
email = config.get(CONF_EMAIL) api_key = config.get(CONF_API_KEY)
password = config.get(CONF_PASSWORD)
add_entities([SesameDevice(sesame) for sesame in add_entities([SesameDevice(sesame) for sesame in
pysesame.get_sesames(email, password)], pysesame2.get_sesames(api_key)],
update_before_add=True) update_before_add=True)
@ -40,9 +39,10 @@ class SesameDevice(LockDevice):
# Cached properties from pysesame object. # Cached properties from pysesame object.
self._device_id = None self._device_id = None
self._serial = None
self._nickname = None self._nickname = None
self._is_unlocked = False self._is_locked = False
self._api_enabled = False self._responsive = False
self._battery = -1 self._battery = -1
@property @property
@ -53,19 +53,17 @@ class SesameDevice(LockDevice):
@property @property
def available(self) -> bool: def available(self) -> bool:
"""Return True if entity is available.""" """Return True if entity is available."""
return self._api_enabled return self._responsive
@property @property
def is_locked(self) -> bool: def is_locked(self) -> bool:
"""Return True if the device is currently locked, else False.""" """Return True if the device is currently locked, else False."""
return not self._is_unlocked return self._is_locked
@property @property
def state(self) -> str: def state(self) -> str:
"""Get the state of the device.""" """Get the state of the device."""
if self._is_unlocked: return STATE_LOCKED if self._is_locked else STATE_UNLOCKED
return STATE_UNLOCKED
return STATE_LOCKED
def lock(self, **kwargs) -> None: def lock(self, **kwargs) -> None:
"""Lock the device.""" """Lock the device."""
@ -77,17 +75,19 @@ class SesameDevice(LockDevice):
def update(self) -> None: def update(self) -> None:
"""Update the internal state of the device.""" """Update the internal state of the device."""
self._sesame.update_state() status = self._sesame.get_status()
self._nickname = self._sesame.nickname self._nickname = self._sesame.nickname
self._api_enabled = self._sesame.api_enabled self._device_id = str(self._sesame.id)
self._is_unlocked = self._sesame.is_unlocked self._serial = self._sesame.serial
self._device_id = self._sesame.device_id self._battery = status['battery']
self._battery = self._sesame.battery self._is_locked = status['locked']
self._responsive = status['responsive']
@property @property
def device_state_attributes(self) -> dict: def device_state_attributes(self) -> dict:
"""Return the state attributes.""" """Return the state attributes."""
attributes = {} attributes = {}
attributes[ATTR_DEVICE_ID] = self._device_id attributes[ATTR_DEVICE_ID] = self._device_id
attributes[ATTR_SERIAL_NO] = self._serial
attributes[ATTR_BATTERY_LEVEL] = self._battery attributes[ATTR_BATTERY_LEVEL] = self._battery
return attributes return attributes

View File

@ -1,9 +1,9 @@
{ {
"domain": "sesame", "domain": "sesame",
"name": "Sesame", "name": "Sesame Smart Lock",
"documentation": "https://www.home-assistant.io/components/sesame", "documentation": "https://www.home-assistant.io/components/sesame",
"requirements": [ "requirements": [
"pysesame==0.1.0" "pysesame2==1.0.1"
], ],
"dependencies": [], "dependencies": [],
"codeowners": [] "codeowners": []

View File

@ -1288,7 +1288,7 @@ pyserial-asyncio==0.4
pyserial==3.1.1 pyserial==3.1.1
# homeassistant.components.sesame # homeassistant.components.sesame
pysesame==0.1.0 pysesame2==1.0.1
# homeassistant.components.goalfeed # homeassistant.components.goalfeed
pysher==1.0.1 pysher==1.0.1