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 attribute
This commit is contained in:
parent
a5012f39da
commit
4e20e4964e
5 changed files with 69 additions and 20 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue