mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 09:17:53 +00:00
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
@ -607,6 +607,14 @@ class SimpliSafeEntity(Entity):
|
||||
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
|
||||
def available(self):
|
||||
"""Return whether the entity is available."""
|
||||
@ -620,13 +628,7 @@ class SimpliSafeEntity(Entity):
|
||||
@property
|
||||
def device_info(self):
|
||||
"""Return device registry information for this entity."""
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self._system.system_id)},
|
||||
"manufacturer": "SimpliSafe",
|
||||
"model": self._system.version,
|
||||
"name": self._name,
|
||||
"via_device": (DOMAIN, self._system.serial),
|
||||
}
|
||||
return self._device_info
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
@ -730,4 +732,3 @@ class SimpliSafeEntity(Entity):
|
||||
@callback
|
||||
def async_update_from_websocket_event(self, 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."""
|
||||
simplisafe = hass.data[DOMAIN][DATA_CLIENT][entry.entry_id]
|
||||
|
||||
# Add sensor
|
||||
sensors = [
|
||||
SimpliSafeBinarySensor(simplisafe, system, sensor)
|
||||
for system in simplisafe.systems.values()
|
||||
for sensor in system.sensors.values()
|
||||
if sensor.type in SUPPORTED_SENSOR_TYPES
|
||||
]
|
||||
sensors = []
|
||||
for system in simplisafe.systems.values():
|
||||
for sensor in system.sensors.values():
|
||||
if sensor.type in SUPPORTED_SENSOR_TYPES:
|
||||
sensors.append(SimpliSafeBinarySensor(simplisafe, system, sensor))
|
||||
if sensor.type in SUPPORTED_BATTERY_SENSOR_TYPES:
|
||||
sensors.append(SimpliSafeSensorBattery(simplisafe, system, sensor))
|
||||
|
||||
# Add low battery status entity for every sensor
|
||||
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)
|
||||
async_add_entities(sensors)
|
||||
|
||||
|
||||
class SimpliSafeBinarySensor(SimpliSafeEntity, BinarySensorEntity):
|
||||
@ -108,10 +100,13 @@ class SimpliSafeSensorBattery(SimpliSafeEntity, BinarySensorEntity):
|
||||
def __init__(self, simplisafe, system, sensor):
|
||||
"""Initialize."""
|
||||
super().__init__(simplisafe, system, sensor.name, serial=sensor.serial)
|
||||
self._system = system
|
||||
self._sensor = sensor
|
||||
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
|
||||
def device_class(self):
|
||||
"""Return type of sensor."""
|
||||
@ -122,15 +117,6 @@ class SimpliSafeSensorBattery(SimpliSafeEntity, BinarySensorEntity):
|
||||
"""Return unique ID of sensor."""
|
||||
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
|
||||
def is_on(self):
|
||||
"""Return true if the battery is low."""
|
||||
|
@ -28,10 +28,13 @@ class SimplisafeFreezeSensor(SimpliSafeEntity):
|
||||
def __init__(self, simplisafe, system, sensor):
|
||||
"""Initialize."""
|
||||
super().__init__(simplisafe, system, sensor.name, serial=sensor.serial)
|
||||
self._system = system
|
||||
self._sensor = sensor
|
||||
self._state = None
|
||||
|
||||
self._device_info["identifiers"] = {(DOMAIN, sensor.serial)}
|
||||
self._device_info["model"] = "Freeze Sensor"
|
||||
self._device_info["name"] = sensor.name
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Return type of sensor."""
|
||||
@ -42,15 +45,6 @@ class SimplisafeFreezeSensor(SimpliSafeEntity):
|
||||
"""Return unique ID of sensor."""
|
||||
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
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user