Clean up SimpliSafe device info and sensor creation (#41920)
* Clean up SimpliSafe device info and sensor creation * Code review
This commit is contained in:
parent
1c3ec69166
commit
bbef87d3f3
3 changed files with 25 additions and 44 deletions
|
@ -607,6 +607,14 @@ class SimpliSafeEntity(Entity):
|
||||||
ATTR_SYSTEM_ID: system.system_id,
|
ATTR_SYSTEM_ID: system.system_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self._device_info = {
|
||||||
|
"identifiers": {(DOMAIN, system.system_id)},
|
||||||
|
"manufacturer": "SimpliSafe",
|
||||||
|
"model": system.version,
|
||||||
|
"name": name,
|
||||||
|
"via_device": (DOMAIN, system.serial),
|
||||||
|
}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def available(self):
|
def available(self):
|
||||||
"""Return whether the entity is available."""
|
"""Return whether the entity is available."""
|
||||||
|
@ -620,13 +628,7 @@ class SimpliSafeEntity(Entity):
|
||||||
@property
|
@property
|
||||||
def device_info(self):
|
def device_info(self):
|
||||||
"""Return device registry information for this entity."""
|
"""Return device registry information for this entity."""
|
||||||
return {
|
return self._device_info
|
||||||
"identifiers": {(DOMAIN, self._system.system_id)},
|
|
||||||
"manufacturer": "SimpliSafe",
|
|
||||||
"model": self._system.version,
|
|
||||||
"name": self._name,
|
|
||||||
"via_device": (DOMAIN, self._system.serial),
|
|
||||||
}
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
|
@ -730,4 +732,3 @@ class SimpliSafeEntity(Entity):
|
||||||
@callback
|
@callback
|
||||||
def async_update_from_websocket_event(self, event):
|
def async_update_from_websocket_event(self, event):
|
||||||
"""Update the entity with the provided websocket event."""
|
"""Update the entity with the provided websocket event."""
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
|
@ -48,23 +48,15 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
||||||
"""Set up SimpliSafe binary sensors based on a config entry."""
|
"""Set up SimpliSafe binary sensors based on a config entry."""
|
||||||
simplisafe = hass.data[DOMAIN][DATA_CLIENT][entry.entry_id]
|
simplisafe = hass.data[DOMAIN][DATA_CLIENT][entry.entry_id]
|
||||||
|
|
||||||
# Add sensor
|
sensors = []
|
||||||
sensors = [
|
for system in simplisafe.systems.values():
|
||||||
SimpliSafeBinarySensor(simplisafe, system, sensor)
|
for sensor in system.sensors.values():
|
||||||
for system in simplisafe.systems.values()
|
if sensor.type in SUPPORTED_SENSOR_TYPES:
|
||||||
for sensor in system.sensors.values()
|
sensors.append(SimpliSafeBinarySensor(simplisafe, system, sensor))
|
||||||
if sensor.type in SUPPORTED_SENSOR_TYPES
|
if sensor.type in SUPPORTED_BATTERY_SENSOR_TYPES:
|
||||||
]
|
sensors.append(SimpliSafeSensorBattery(simplisafe, system, sensor))
|
||||||
|
|
||||||
# Add low battery status entity for every sensor
|
async_add_entities(sensors)
|
||||||
battery_sensors = [
|
|
||||||
SimpliSafeSensorBattery(simplisafe, system, sensor)
|
|
||||||
for system in simplisafe.systems.values()
|
|
||||||
for sensor in system.sensors.values()
|
|
||||||
if sensor.type in SUPPORTED_BATTERY_SENSOR_TYPES
|
|
||||||
]
|
|
||||||
|
|
||||||
async_add_entities(sensors + battery_sensors)
|
|
||||||
|
|
||||||
|
|
||||||
class SimpliSafeBinarySensor(SimpliSafeEntity, BinarySensorEntity):
|
class SimpliSafeBinarySensor(SimpliSafeEntity, BinarySensorEntity):
|
||||||
|
@ -108,10 +100,13 @@ class SimpliSafeSensorBattery(SimpliSafeEntity, BinarySensorEntity):
|
||||||
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._system = system
|
|
||||||
self._sensor = sensor
|
self._sensor = sensor
|
||||||
self._is_low = False
|
self._is_low = False
|
||||||
|
|
||||||
|
self._device_info["identifiers"] = {(DOMAIN, sensor.serial)}
|
||||||
|
self._device_info["model"] = SENSOR_MODELS[sensor.type]
|
||||||
|
self._device_info["name"] = sensor.name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_class(self):
|
def device_class(self):
|
||||||
"""Return type of sensor."""
|
"""Return type of sensor."""
|
||||||
|
@ -122,15 +117,6 @@ class SimpliSafeSensorBattery(SimpliSafeEntity, BinarySensorEntity):
|
||||||
"""Return unique ID of sensor."""
|
"""Return unique ID of sensor."""
|
||||||
return f"{self._sensor.serial}-battery"
|
return f"{self._sensor.serial}-battery"
|
||||||
|
|
||||||
@property
|
|
||||||
def device_info(self):
|
|
||||||
"""Return device registry information for this entity."""
|
|
||||||
info = super().device_info
|
|
||||||
info["identifiers"] = {(DOMAIN, self._sensor.serial)}
|
|
||||||
info["model"] = SENSOR_MODELS[self._sensor.type]
|
|
||||||
info["name"] = self._sensor.name
|
|
||||||
return info
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return true if the battery is low."""
|
"""Return true if the battery is low."""
|
||||||
|
|
|
@ -28,10 +28,13 @@ class SimplisafeFreezeSensor(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._system = system
|
|
||||||
self._sensor = sensor
|
self._sensor = sensor
|
||||||
self._state = None
|
self._state = None
|
||||||
|
|
||||||
|
self._device_info["identifiers"] = {(DOMAIN, sensor.serial)}
|
||||||
|
self._device_info["model"] = "Freeze Sensor"
|
||||||
|
self._device_info["name"] = sensor.name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_class(self):
|
def device_class(self):
|
||||||
"""Return type of sensor."""
|
"""Return type of sensor."""
|
||||||
|
@ -42,15 +45,6 @@ class SimplisafeFreezeSensor(SimpliSafeEntity):
|
||||||
"""Return unique ID of sensor."""
|
"""Return unique ID of sensor."""
|
||||||
return self._sensor.serial
|
return self._sensor.serial
|
||||||
|
|
||||||
@property
|
|
||||||
def device_info(self):
|
|
||||||
"""Return device registry information for this entity."""
|
|
||||||
info = super().device_info
|
|
||||||
info["identifiers"] = {(DOMAIN, self._sensor.serial)}
|
|
||||||
info["model"] = "Freeze Sensor"
|
|
||||||
info["name"] = self._sensor.name
|
|
||||||
return info
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Return the unit of measurement."""
|
"""Return the unit of measurement."""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue