mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Upgrade to simplisafe-python v2 to use new SimpliSafe API (#15542)
* Upgrade to simplisafe-python v2 to use new SimpliSafe API
This commit is contained in:
parent
33ee91a748
commit
a42288d056
@ -9,23 +9,22 @@ import re
|
|||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
import homeassistant.components.alarm_control_panel as alarm
|
from homeassistant.components.alarm_control_panel import (
|
||||||
from homeassistant.components.alarm_control_panel import PLATFORM_SCHEMA
|
PLATFORM_SCHEMA, AlarmControlPanel)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_CODE, CONF_NAME, CONF_PASSWORD, CONF_USERNAME,
|
CONF_CODE, CONF_NAME, CONF_PASSWORD, CONF_USERNAME,
|
||||||
EVENT_HOMEASSISTANT_STOP, STATE_ALARM_ARMED_AWAY, STATE_ALARM_ARMED_HOME,
|
STATE_ALARM_ARMED_AWAY, STATE_ALARM_ARMED_HOME,
|
||||||
STATE_ALARM_DISARMED, STATE_UNKNOWN)
|
STATE_ALARM_DISARMED, STATE_UNKNOWN)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
REQUIREMENTS = ['simplisafe-python==1.0.5']
|
REQUIREMENTS = ['simplisafe-python==2.0.2']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DEFAULT_NAME = 'SimpliSafe'
|
DEFAULT_NAME = 'SimpliSafe'
|
||||||
DOMAIN = 'simplisafe'
|
|
||||||
|
|
||||||
NOTIFICATION_ID = 'simplisafe_notification'
|
ATTR_ALARM_ACTIVE = "alarm_active"
|
||||||
NOTIFICATION_TITLE = 'SimpliSafe Setup'
|
ATTR_TEMPERATURE = "temperature"
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
vol.Required(CONF_PASSWORD): cv.string,
|
vol.Required(CONF_PASSWORD): cv.string,
|
||||||
@ -37,36 +36,27 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Set up the SimpliSafe platform."""
|
"""Set up the SimpliSafe platform."""
|
||||||
from simplipy.api import SimpliSafeApiInterface, get_systems
|
from simplipy.api import SimpliSafeApiInterface, SimpliSafeAPIException
|
||||||
name = config.get(CONF_NAME)
|
name = config.get(CONF_NAME)
|
||||||
code = config.get(CONF_CODE)
|
code = config.get(CONF_CODE)
|
||||||
username = config.get(CONF_USERNAME)
|
username = config.get(CONF_USERNAME)
|
||||||
password = config.get(CONF_PASSWORD)
|
password = config.get(CONF_PASSWORD)
|
||||||
|
|
||||||
simplisafe = SimpliSafeApiInterface()
|
try:
|
||||||
status = simplisafe.set_credentials(username, password)
|
simplisafe = SimpliSafeApiInterface(username, password)
|
||||||
if status:
|
except SimpliSafeAPIException:
|
||||||
hass.data[DOMAIN] = simplisafe
|
_LOGGER.error("Failed to setup SimpliSafe")
|
||||||
locations = get_systems(simplisafe)
|
return
|
||||||
for location in locations:
|
|
||||||
add_devices([SimpliSafeAlarm(location, name, code)])
|
|
||||||
else:
|
|
||||||
message = 'Failed to log into SimpliSafe. Check credentials.'
|
|
||||||
_LOGGER.error(message)
|
|
||||||
hass.components.persistent_notification.create(
|
|
||||||
message,
|
|
||||||
title=NOTIFICATION_TITLE,
|
|
||||||
notification_id=NOTIFICATION_ID)
|
|
||||||
return False
|
|
||||||
|
|
||||||
def logout(event):
|
systems = []
|
||||||
"""Logout of the SimpliSafe API."""
|
|
||||||
hass.data[DOMAIN].logout()
|
|
||||||
|
|
||||||
hass.bus.listen(EVENT_HOMEASSISTANT_STOP, logout)
|
for system in simplisafe.get_systems():
|
||||||
|
systems.append(SimpliSafeAlarm(system, name, code))
|
||||||
|
|
||||||
|
add_devices(systems)
|
||||||
|
|
||||||
|
|
||||||
class SimpliSafeAlarm(alarm.AlarmControlPanel):
|
class SimpliSafeAlarm(AlarmControlPanel):
|
||||||
"""Representation of a SimpliSafe alarm."""
|
"""Representation of a SimpliSafe alarm."""
|
||||||
|
|
||||||
def __init__(self, simplisafe, name, code):
|
def __init__(self, simplisafe, name, code):
|
||||||
@ -75,12 +65,17 @@ class SimpliSafeAlarm(alarm.AlarmControlPanel):
|
|||||||
self._name = name
|
self._name = name
|
||||||
self._code = str(code) if code else None
|
self._code = str(code) if code else None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def unique_id(self):
|
||||||
|
"""Return the unique ID."""
|
||||||
|
return self.simplisafe.location_id
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the device."""
|
"""Return the name of the device."""
|
||||||
if self._name is not None:
|
if self._name is not None:
|
||||||
return self._name
|
return self._name
|
||||||
return 'Alarm {}'.format(self.simplisafe.location_id())
|
return 'Alarm {}'.format(self.simplisafe.location_id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def code_format(self):
|
def code_format(self):
|
||||||
@ -94,12 +89,13 @@ class SimpliSafeAlarm(alarm.AlarmControlPanel):
|
|||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Return the state of the device."""
|
"""Return the state of the device."""
|
||||||
status = self.simplisafe.state()
|
status = self.simplisafe.state
|
||||||
if status == 'off':
|
if status.lower() == 'off':
|
||||||
state = STATE_ALARM_DISARMED
|
state = STATE_ALARM_DISARMED
|
||||||
elif status == 'home':
|
elif status.lower() == 'home' or status.lower() == 'home_count':
|
||||||
state = STATE_ALARM_ARMED_HOME
|
state = STATE_ALARM_ARMED_HOME
|
||||||
elif status == 'away':
|
elif (status.lower() == 'away' or status.lower() == 'exitDelay' or
|
||||||
|
status.lower() == 'away_count'):
|
||||||
state = STATE_ALARM_ARMED_AWAY
|
state = STATE_ALARM_ARMED_AWAY
|
||||||
else:
|
else:
|
||||||
state = STATE_UNKNOWN
|
state = STATE_UNKNOWN
|
||||||
@ -108,14 +104,13 @@ class SimpliSafeAlarm(alarm.AlarmControlPanel):
|
|||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
return {
|
attributes = {}
|
||||||
'alarm': self.simplisafe.alarm(),
|
|
||||||
'co': self.simplisafe.carbon_monoxide(),
|
attributes[ATTR_ALARM_ACTIVE] = self.simplisafe.alarm_active
|
||||||
'fire': self.simplisafe.fire(),
|
if self.simplisafe.temperature is not None:
|
||||||
'flood': self.simplisafe.flood(),
|
attributes[ATTR_TEMPERATURE] = self.simplisafe.temperature
|
||||||
'last_event': self.simplisafe.last_event(),
|
|
||||||
'temperature': self.simplisafe.temperature(),
|
return attributes
|
||||||
}
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update alarm status."""
|
"""Update alarm status."""
|
||||||
|
@ -1241,7 +1241,7 @@ shodan==1.8.1
|
|||||||
simplepush==1.1.4
|
simplepush==1.1.4
|
||||||
|
|
||||||
# homeassistant.components.alarm_control_panel.simplisafe
|
# homeassistant.components.alarm_control_panel.simplisafe
|
||||||
simplisafe-python==1.0.5
|
simplisafe-python==2.0.2
|
||||||
|
|
||||||
# homeassistant.components.skybell
|
# homeassistant.components.skybell
|
||||||
skybellpy==0.1.2
|
skybellpy==0.1.2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user