mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 23:27:37 +00:00
Remove redundant property definitions in SimpliSafe (#52458)
* Remove redundant property definitions in SimpliSafe * Remove useless init
This commit is contained in:
parent
513bcbc02b
commit
413c3afa12
@ -403,25 +403,25 @@ class SimpliSafeEntity(CoordinatorEntity):
|
|||||||
def __init__(self, simplisafe, system, name, *, serial=None):
|
def __init__(self, simplisafe, system, name, *, serial=None):
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
super().__init__(simplisafe.coordinator)
|
super().__init__(simplisafe.coordinator)
|
||||||
self._name = name
|
|
||||||
self._online = True
|
|
||||||
self._simplisafe = simplisafe
|
|
||||||
self._system = system
|
|
||||||
|
|
||||||
if serial:
|
if serial:
|
||||||
self._serial = serial
|
self._serial = serial
|
||||||
else:
|
else:
|
||||||
self._serial = system.serial
|
self._serial = system.serial
|
||||||
|
|
||||||
self._attrs = {ATTR_SYSTEM_ID: system.system_id}
|
self._attr_extra_state_attributes = {ATTR_SYSTEM_ID: system.system_id}
|
||||||
|
self._attr_device_info = {
|
||||||
self._device_info = {
|
|
||||||
"identifiers": {(DOMAIN, system.system_id)},
|
"identifiers": {(DOMAIN, system.system_id)},
|
||||||
"manufacturer": "SimpliSafe",
|
"manufacturer": "SimpliSafe",
|
||||||
"model": system.version,
|
"model": system.version,
|
||||||
"name": name,
|
"name": name,
|
||||||
"via_device": (DOMAIN, system.serial),
|
"via_device": (DOMAIN, system.serial),
|
||||||
}
|
}
|
||||||
|
self._attr_name = f"{system.address} {name}"
|
||||||
|
self._attr_unique_id = self._serial
|
||||||
|
self._online = True
|
||||||
|
self._simplisafe = simplisafe
|
||||||
|
self._system = system
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self):
|
def available(self):
|
||||||
@ -431,27 +431,11 @@ class SimpliSafeEntity(CoordinatorEntity):
|
|||||||
# the entity as available if:
|
# the entity as available if:
|
||||||
# 1. We can verify that the system is online (assuming True if we can't)
|
# 1. We can verify that the system is online (assuming True if we can't)
|
||||||
# 2. We can verify that the entity is online
|
# 2. We can verify that the entity is online
|
||||||
return not (self._system.version == 3 and self._system.offline) and self._online
|
return (
|
||||||
|
super().available
|
||||||
@property
|
and self._online
|
||||||
def device_info(self):
|
and not (self._system.version == 3 and self._system.offline)
|
||||||
"""Return device registry information for this entity."""
|
)
|
||||||
return self._device_info
|
|
||||||
|
|
||||||
@property
|
|
||||||
def extra_state_attributes(self):
|
|
||||||
"""Return the state attributes."""
|
|
||||||
return self._attrs
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the entity."""
|
|
||||||
return f"{self._system.address} {self._name}"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self):
|
|
||||||
"""Return the unique ID of the entity."""
|
|
||||||
return self._serial
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _handle_coordinator_update(self):
|
def _handle_coordinator_update(self):
|
||||||
@ -476,15 +460,12 @@ class SimpliSafeBaseSensor(SimpliSafeEntity):
|
|||||||
def __init__(self, simplisafe, system, sensor):
|
def __init__(self, simplisafe, system, sensor):
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
super().__init__(simplisafe, system, sensor.name, serial=sensor.serial)
|
super().__init__(simplisafe, system, sensor.name, serial=sensor.serial)
|
||||||
self._device_info["identifiers"] = {(DOMAIN, sensor.serial)}
|
|
||||||
self._device_info["model"] = sensor.type.name
|
|
||||||
self._device_info["name"] = sensor.name
|
|
||||||
self._sensor = sensor
|
|
||||||
self._sensor_type_human_name = " ".join(
|
|
||||||
[w.title() for w in self._sensor.type.name.split("_")]
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
self._attr_device_info["identifiers"] = {(DOMAIN, sensor.serial)}
|
||||||
def name(self):
|
self._attr_device_info["model"] = sensor.type.name
|
||||||
"""Return the name of the sensor."""
|
self._attr_device_info["name"] = sensor.name
|
||||||
return f"{self._system.address} {self._name} {self._sensor_type_human_name}"
|
|
||||||
|
human_friendly_name = " ".join([w.title() for w in sensor.type.name.split("_")])
|
||||||
|
self._attr_name = f"{super().name} {human_friendly_name}"
|
||||||
|
|
||||||
|
self._sensor = sensor
|
||||||
|
@ -63,51 +63,32 @@ class SimpliSafeAlarm(SimpliSafeEntity, AlarmControlPanelEntity):
|
|||||||
def __init__(self, simplisafe, system):
|
def __init__(self, simplisafe, system):
|
||||||
"""Initialize the SimpliSafe alarm."""
|
"""Initialize the SimpliSafe alarm."""
|
||||||
super().__init__(simplisafe, system, "Alarm Control Panel")
|
super().__init__(simplisafe, system, "Alarm Control Panel")
|
||||||
self._changed_by = None
|
|
||||||
|
if isinstance(
|
||||||
|
self._simplisafe.config_entry.options.get(CONF_CODE), str
|
||||||
|
) and re.search("^\\d+$", self._simplisafe.config_entry.options[CONF_CODE]):
|
||||||
|
self._attr_code_format = FORMAT_NUMBER
|
||||||
|
else:
|
||||||
|
self._attr_code_format = FORMAT_TEXT
|
||||||
|
self._attr_supported_features = SUPPORT_ALARM_ARM_HOME | SUPPORT_ALARM_ARM_AWAY
|
||||||
self._last_event = None
|
self._last_event = None
|
||||||
|
|
||||||
if system.alarm_going_off:
|
if system.alarm_going_off:
|
||||||
self._state = STATE_ALARM_TRIGGERED
|
self._attr_state = STATE_ALARM_TRIGGERED
|
||||||
elif system.state == SystemStates.away:
|
elif system.state == SystemStates.away:
|
||||||
self._state = STATE_ALARM_ARMED_AWAY
|
self._attr_state = STATE_ALARM_ARMED_AWAY
|
||||||
elif system.state in (
|
elif system.state in (
|
||||||
SystemStates.away_count,
|
SystemStates.away_count,
|
||||||
SystemStates.exit_delay,
|
SystemStates.exit_delay,
|
||||||
SystemStates.home_count,
|
SystemStates.home_count,
|
||||||
):
|
):
|
||||||
self._state = STATE_ALARM_ARMING
|
self._attr_state = STATE_ALARM_ARMING
|
||||||
elif system.state == SystemStates.home:
|
elif system.state == SystemStates.home:
|
||||||
self._state = STATE_ALARM_ARMED_HOME
|
self._attr_state = STATE_ALARM_ARMED_HOME
|
||||||
elif system.state == SystemStates.off:
|
elif system.state == SystemStates.off:
|
||||||
self._state = STATE_ALARM_DISARMED
|
self._attr_state = STATE_ALARM_DISARMED
|
||||||
else:
|
else:
|
||||||
self._state = None
|
self._attr_state = None
|
||||||
|
|
||||||
@property
|
|
||||||
def changed_by(self):
|
|
||||||
"""Return info about who changed the alarm last."""
|
|
||||||
return self._changed_by
|
|
||||||
|
|
||||||
@property
|
|
||||||
def code_format(self):
|
|
||||||
"""Return one or more digits/characters."""
|
|
||||||
if not self._simplisafe.config_entry.options.get(CONF_CODE):
|
|
||||||
return None
|
|
||||||
if isinstance(
|
|
||||||
self._simplisafe.config_entry.options[CONF_CODE], str
|
|
||||||
) and re.search("^\\d+$", self._simplisafe.config_entry.options[CONF_CODE]):
|
|
||||||
return FORMAT_NUMBER
|
|
||||||
return FORMAT_TEXT
|
|
||||||
|
|
||||||
@property
|
|
||||||
def state(self):
|
|
||||||
"""Return the state of the entity."""
|
|
||||||
return self._state
|
|
||||||
|
|
||||||
@property
|
|
||||||
def supported_features(self) -> int:
|
|
||||||
"""Return the list of supported features."""
|
|
||||||
return SUPPORT_ALARM_ARM_HOME | SUPPORT_ALARM_ARM_AWAY
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _is_code_valid(self, code, state):
|
def _is_code_valid(self, code, state):
|
||||||
@ -134,7 +115,7 @@ class SimpliSafeAlarm(SimpliSafeEntity, AlarmControlPanelEntity):
|
|||||||
LOGGER.error('Error while disarming "%s": %s', self._system.system_id, err)
|
LOGGER.error('Error while disarming "%s": %s', self._system.system_id, err)
|
||||||
return
|
return
|
||||||
|
|
||||||
self._state = STATE_ALARM_DISARMED
|
self._attr_state = STATE_ALARM_DISARMED
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
async def async_alarm_arm_home(self, code=None):
|
async def async_alarm_arm_home(self, code=None):
|
||||||
@ -150,7 +131,7 @@ class SimpliSafeAlarm(SimpliSafeEntity, AlarmControlPanelEntity):
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
self._state = STATE_ALARM_ARMED_HOME
|
self._attr_state = STATE_ALARM_ARMED_HOME
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
async def async_alarm_arm_away(self, code=None):
|
async def async_alarm_arm_away(self, code=None):
|
||||||
@ -166,14 +147,14 @@ class SimpliSafeAlarm(SimpliSafeEntity, AlarmControlPanelEntity):
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
self._state = STATE_ALARM_ARMING
|
self._attr_state = STATE_ALARM_ARMING
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_update_from_rest_api(self):
|
def async_update_from_rest_api(self):
|
||||||
"""Update the entity with the provided REST API data."""
|
"""Update the entity with the provided REST API data."""
|
||||||
if self._system.version == 3:
|
if self._system.version == 3:
|
||||||
self._attrs.update(
|
self._attr_extra_state_attributes.update(
|
||||||
{
|
{
|
||||||
ATTR_ALARM_DURATION: self._system.alarm_duration,
|
ATTR_ALARM_DURATION: self._system.alarm_duration,
|
||||||
ATTR_ALARM_VOLUME: VOLUME_STRING_MAP[self._system.alarm_volume],
|
ATTR_ALARM_VOLUME: VOLUME_STRING_MAP[self._system.alarm_volume],
|
||||||
@ -198,14 +179,14 @@ class SimpliSafeAlarm(SimpliSafeEntity, AlarmControlPanelEntity):
|
|||||||
# SimpliSafe cloud can sporadically fail to send those updates as expected; so,
|
# SimpliSafe cloud can sporadically fail to send those updates as expected; so,
|
||||||
# just in case, we synchronize the state via the REST API, too:
|
# just in case, we synchronize the state via the REST API, too:
|
||||||
if self._system.state == SystemStates.alarm:
|
if self._system.state == SystemStates.alarm:
|
||||||
self._state = STATE_ALARM_TRIGGERED
|
self._attr_state = STATE_ALARM_TRIGGERED
|
||||||
elif self._system.state == SystemStates.away:
|
elif self._system.state == SystemStates.away:
|
||||||
self._state = STATE_ALARM_ARMED_AWAY
|
self._attr_state = STATE_ALARM_ARMED_AWAY
|
||||||
elif self._system.state in (SystemStates.away_count, SystemStates.exit_delay):
|
elif self._system.state in (SystemStates.away_count, SystemStates.exit_delay):
|
||||||
self._state = STATE_ALARM_ARMING
|
self._attr_state = STATE_ALARM_ARMING
|
||||||
elif self._system.state == SystemStates.home:
|
elif self._system.state == SystemStates.home:
|
||||||
self._state = STATE_ALARM_ARMED_HOME
|
self._attr_state = STATE_ALARM_ARMED_HOME
|
||||||
elif self._system.state == SystemStates.off:
|
elif self._system.state == SystemStates.off:
|
||||||
self._state = STATE_ALARM_DISARMED
|
self._attr_state = STATE_ALARM_DISARMED
|
||||||
else:
|
else:
|
||||||
self._state = None
|
self._attr_state = None
|
||||||
|
@ -71,49 +71,27 @@ class TriggeredBinarySensor(SimpliSafeBaseSensor, BinarySensorEntity):
|
|||||||
def __init__(self, simplisafe, system, sensor, device_class):
|
def __init__(self, simplisafe, system, sensor, device_class):
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
super().__init__(simplisafe, system, sensor)
|
super().__init__(simplisafe, system, sensor)
|
||||||
self._device_class = device_class
|
|
||||||
self._is_on = False
|
|
||||||
|
|
||||||
@property
|
self._attr_device_class = device_class
|
||||||
def device_class(self):
|
|
||||||
"""Return type of sensor."""
|
|
||||||
return self._device_class
|
|
||||||
|
|
||||||
@property
|
|
||||||
def is_on(self):
|
|
||||||
"""Return true if the sensor is on."""
|
|
||||||
return self._is_on
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_update_from_rest_api(self):
|
def async_update_from_rest_api(self):
|
||||||
"""Update the entity with the provided REST API data."""
|
"""Update the entity with the provided REST API data."""
|
||||||
self._is_on = self._sensor.triggered
|
self._attr_is_on = self._sensor.triggered
|
||||||
|
|
||||||
|
|
||||||
class BatteryBinarySensor(SimpliSafeBaseSensor, BinarySensorEntity):
|
class BatteryBinarySensor(SimpliSafeBaseSensor, BinarySensorEntity):
|
||||||
"""Define a SimpliSafe battery binary sensor entity."""
|
"""Define a SimpliSafe battery binary sensor entity."""
|
||||||
|
|
||||||
|
_attr_device_class = DEVICE_CLASS_BATTERY
|
||||||
|
|
||||||
def __init__(self, simplisafe, system, sensor):
|
def __init__(self, simplisafe, system, sensor):
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
super().__init__(simplisafe, system, sensor)
|
super().__init__(simplisafe, system, sensor)
|
||||||
self._is_low = False
|
|
||||||
|
|
||||||
@property
|
self._attr_unique_id = f"{super().unique_id}-battery"
|
||||||
def device_class(self):
|
|
||||||
"""Return type of sensor."""
|
|
||||||
return DEVICE_CLASS_BATTERY
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self):
|
|
||||||
"""Return unique ID of sensor."""
|
|
||||||
return f"{self._sensor.serial}-battery"
|
|
||||||
|
|
||||||
@property
|
|
||||||
def is_on(self):
|
|
||||||
"""Return true if the battery is low."""
|
|
||||||
return self._is_low
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_update_from_rest_api(self):
|
def async_update_from_rest_api(self):
|
||||||
"""Update the entity with the provided REST API data."""
|
"""Update the entity with the provided REST API data."""
|
||||||
self._is_low = self._sensor.low_battery
|
self._attr_is_on = self._sensor.low_battery
|
||||||
|
@ -35,13 +35,8 @@ class SimpliSafeLock(SimpliSafeEntity, LockEntity):
|
|||||||
def __init__(self, simplisafe, system, lock):
|
def __init__(self, simplisafe, system, lock):
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
super().__init__(simplisafe, system, lock.name, serial=lock.serial)
|
super().__init__(simplisafe, system, lock.name, serial=lock.serial)
|
||||||
self._lock = lock
|
|
||||||
self._is_locked = None
|
|
||||||
|
|
||||||
@property
|
self._lock = lock
|
||||||
def is_locked(self):
|
|
||||||
"""Return true if the lock is locked."""
|
|
||||||
return self._is_locked
|
|
||||||
|
|
||||||
async def async_lock(self, **kwargs):
|
async def async_lock(self, **kwargs):
|
||||||
"""Lock the lock."""
|
"""Lock the lock."""
|
||||||
@ -51,7 +46,7 @@ class SimpliSafeLock(SimpliSafeEntity, LockEntity):
|
|||||||
LOGGER.error('Error while locking "%s": %s', self._lock.name, err)
|
LOGGER.error('Error while locking "%s": %s', self._lock.name, err)
|
||||||
return
|
return
|
||||||
|
|
||||||
self._is_locked = True
|
self._attr_is_locked = True
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
async def async_unlock(self, **kwargs):
|
async def async_unlock(self, **kwargs):
|
||||||
@ -62,13 +57,13 @@ class SimpliSafeLock(SimpliSafeEntity, LockEntity):
|
|||||||
LOGGER.error('Error while unlocking "%s": %s', self._lock.name, err)
|
LOGGER.error('Error while unlocking "%s": %s', self._lock.name, err)
|
||||||
return
|
return
|
||||||
|
|
||||||
self._is_locked = False
|
self._attr_is_locked = False
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_update_from_rest_api(self):
|
def async_update_from_rest_api(self):
|
||||||
"""Update the entity with the provided REST API data."""
|
"""Update the entity with the provided REST API data."""
|
||||||
self._attrs.update(
|
self._attr_extra_state_attributes.update(
|
||||||
{
|
{
|
||||||
ATTR_LOCK_LOW_BATTERY: self._lock.lock_low_battery,
|
ATTR_LOCK_LOW_BATTERY: self._lock.lock_low_battery,
|
||||||
ATTR_JAMMED: self._lock.state == LockStates.jammed,
|
ATTR_JAMMED: self._lock.state == LockStates.jammed,
|
||||||
@ -76,4 +71,4 @@ class SimpliSafeLock(SimpliSafeEntity, LockEntity):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
self._is_locked = self._lock.state == LockStates.locked
|
self._attr_is_locked = self._lock.state == LockStates.locked
|
||||||
|
@ -29,32 +29,10 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||||||
class SimplisafeFreezeSensor(SimpliSafeBaseSensor, SensorEntity):
|
class SimplisafeFreezeSensor(SimpliSafeBaseSensor, SensorEntity):
|
||||||
"""Define a SimpliSafe freeze sensor entity."""
|
"""Define a SimpliSafe freeze sensor entity."""
|
||||||
|
|
||||||
def __init__(self, simplisafe, system, sensor):
|
_attr_device_class = DEVICE_CLASS_TEMPERATURE
|
||||||
"""Initialize."""
|
_attr_unit_of_measurement = TEMP_FAHRENHEIT
|
||||||
super().__init__(simplisafe, system, sensor)
|
|
||||||
self._state = None
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_class(self):
|
|
||||||
"""Return type of sensor."""
|
|
||||||
return DEVICE_CLASS_TEMPERATURE
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self):
|
|
||||||
"""Return unique ID of sensor."""
|
|
||||||
return self._sensor.serial
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unit_of_measurement(self):
|
|
||||||
"""Return the unit of measurement."""
|
|
||||||
return TEMP_FAHRENHEIT
|
|
||||||
|
|
||||||
@property
|
|
||||||
def state(self):
|
|
||||||
"""Return the sensor state."""
|
|
||||||
return self._state
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_update_from_rest_api(self):
|
def async_update_from_rest_api(self):
|
||||||
"""Update the entity with the provided REST API data."""
|
"""Update the entity with the provided REST API data."""
|
||||||
self._state = self._sensor.temperature
|
self._attr_state = self._sensor.temperature
|
||||||
|
Loading…
x
Reference in New Issue
Block a user