Bump simplisafe-python to 4.0.0 + add additional SimpliSafe attributes (#25202)
* Bump simplisafe-python to 4.0.0 + add additional SimpliSafe attributes * Fixed incorrect attr assignment * Member comments * Add system ID as a state attributepull/25221/head
parent
a5012f39da
commit
4e20e4964e
|
@ -10,7 +10,7 @@ from homeassistant.const import (
|
|||
CONF_CODE, CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_TOKEN, CONF_USERNAME)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers import aiohttp_client
|
||||
from homeassistant.helpers import aiohttp_client, device_registry as dr
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
from homeassistant.helpers.event import async_track_time_interval
|
||||
|
||||
|
@ -49,6 +49,20 @@ def _async_save_refresh_token(hass, config_entry, token):
|
|||
})
|
||||
|
||||
|
||||
async def async_register_base_station(hass, system, config_entry_id):
|
||||
"""Register a new bridge."""
|
||||
device_registry = await dr.async_get_registry(hass)
|
||||
device_registry.async_get_or_create(
|
||||
config_entry_id=config_entry_id,
|
||||
identifiers={
|
||||
(DOMAIN, system.serial)
|
||||
},
|
||||
manufacturer='SimpliSafe',
|
||||
model=system.version,
|
||||
name=system.address,
|
||||
)
|
||||
|
||||
|
||||
async def async_setup(hass, config):
|
||||
"""Set up the SimpliSafe component."""
|
||||
hass.data[DOMAIN] = {}
|
||||
|
@ -106,9 +120,9 @@ async def async_setup_entry(hass, config_entry):
|
|||
|
||||
async def refresh(event_time):
|
||||
"""Refresh data from the SimpliSafe account."""
|
||||
tasks = [system.update() for system in systems]
|
||||
tasks = [system.update() for system in systems.values()]
|
||||
results = await asyncio.gather(*tasks, return_exceptions=True)
|
||||
for system, result in zip(systems, results):
|
||||
for system, result in zip(systems.values(), results):
|
||||
if isinstance(result, SimplipyError):
|
||||
_LOGGER.error(
|
||||
'There was error updating "%s": %s', system.address,
|
||||
|
@ -129,6 +143,12 @@ async def async_setup_entry(hass, config_entry):
|
|||
refresh,
|
||||
timedelta(seconds=config_entry.data[CONF_SCAN_INTERVAL]))
|
||||
|
||||
# Register the base station for each system:
|
||||
for system in systems.values():
|
||||
hass.async_create_task(
|
||||
async_register_base_station(
|
||||
hass, system, config_entry.entry_id))
|
||||
|
||||
return True
|
||||
|
||||
|
||||
|
|
|
@ -14,6 +14,12 @@ from .const import DATA_CLIENT, DOMAIN, TOPIC_UPDATE
|
|||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
ATTR_ALARM_ACTIVE = 'alarm_active'
|
||||
ATTR_BATTERY_BACKUP_POWER_LEVEL = 'battery_backup_power_level'
|
||||
ATTR_GSM_STRENGTH = 'gsm_strength'
|
||||
ATTR_RF_JAMMING = 'rf_jamming'
|
||||
ATTR_SYSTEM_ID = 'system_id'
|
||||
ATTR_WALL_POWER_LEVEL = 'wall_power_level'
|
||||
ATTR_WIFI_STRENGTH = 'wifi_strength'
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
|
@ -27,7 +33,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||
systems = hass.data[DOMAIN][DATA_CLIENT][entry.entry_id]
|
||||
async_add_entities([
|
||||
SimpliSafeAlarm(system, entry.data.get(CONF_CODE))
|
||||
for system in systems
|
||||
for system in systems.values()
|
||||
], True)
|
||||
|
||||
|
||||
|
@ -37,20 +43,18 @@ class SimpliSafeAlarm(alarm.AlarmControlPanel):
|
|||
def __init__(self, system, code):
|
||||
"""Initialize the SimpliSafe alarm."""
|
||||
self._async_unsub_dispatcher_connect = None
|
||||
self._attrs = {}
|
||||
self._attrs = {ATTR_SYSTEM_ID: system.system_id}
|
||||
self._code = code
|
||||
self._system = system
|
||||
self._state = None
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return the unique ID."""
|
||||
return self._system.system_id
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the device."""
|
||||
return self._system.address
|
||||
# Some properties only exist for V2 or V3 systems:
|
||||
for prop in (
|
||||
ATTR_BATTERY_BACKUP_POWER_LEVEL, ATTR_GSM_STRENGTH,
|
||||
ATTR_RF_JAMMING, ATTR_WALL_POWER_LEVEL, ATTR_WIFI_STRENGTH):
|
||||
# value = getattr(system, prop, None)
|
||||
if hasattr(system, prop):
|
||||
self._attrs[prop] = getattr(system, prop)
|
||||
|
||||
@property
|
||||
def code_format(self):
|
||||
|
@ -62,15 +66,40 @@ class SimpliSafeAlarm(alarm.AlarmControlPanel):
|
|||
return alarm.FORMAT_TEXT
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state of the device."""
|
||||
return self._state
|
||||
def device_info(self):
|
||||
"""Return device registry information for this entity."""
|
||||
return {
|
||||
'identifiers': {
|
||||
(DOMAIN, self._system.system_id)
|
||||
},
|
||||
'manufacturer': 'SimpliSafe',
|
||||
'model': self._system.version,
|
||||
# The name should become more dynamic once we deduce a way to
|
||||
# get various other sensors from SimpliSafe in a reliable manner:
|
||||
'name': 'Keypad',
|
||||
'via_device': (DOMAIN, self._system.serial)
|
||||
}
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
return self._attrs
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the device."""
|
||||
return self._system.address
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state of the device."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return the unique ID."""
|
||||
return self._system.system_id
|
||||
|
||||
def _validate_code(self, code, state):
|
||||
"""Validate given code."""
|
||||
check = self._code is None or code == self._code
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/components/simplisafe",
|
||||
"requirements": [
|
||||
"simplisafe-python==3.4.2"
|
||||
"simplisafe-python==4.0.0"
|
||||
],
|
||||
"dependencies": [],
|
||||
"codeowners": [
|
||||
|
|
|
@ -1676,7 +1676,7 @@ shodan==1.13.0
|
|||
simplepush==1.1.4
|
||||
|
||||
# homeassistant.components.simplisafe
|
||||
simplisafe-python==3.4.2
|
||||
simplisafe-python==4.0.0
|
||||
|
||||
# homeassistant.components.sisyphus
|
||||
sisyphus-control==2.2
|
||||
|
|
|
@ -334,7 +334,7 @@ ring_doorbell==0.2.3
|
|||
rxv==0.6.0
|
||||
|
||||
# homeassistant.components.simplisafe
|
||||
simplisafe-python==3.4.2
|
||||
simplisafe-python==4.0.0
|
||||
|
||||
# homeassistant.components.sleepiq
|
||||
sleepyq==0.7
|
||||
|
|
Loading…
Reference in New Issue