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

View File

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

View File

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