mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Clean up SimpliSafe binary sensor implementation (#42841)
* Clean up SimpliSafe binary sensor implementation * Cleanup * Constant name
This commit is contained in:
parent
ceb8172b7c
commit
9bb1c6f188
@ -23,25 +23,25 @@ SUPPORTED_BATTERY_SENSOR_TYPES = [
|
|||||||
EntityTypes.temperature,
|
EntityTypes.temperature,
|
||||||
]
|
]
|
||||||
|
|
||||||
SUPPORTED_SENSOR_TYPES = [
|
SUPPORTED_TRIGGERED_SENSOR_TYPES = [
|
||||||
EntityTypes.entry,
|
|
||||||
EntityTypes.carbon_monoxide,
|
EntityTypes.carbon_monoxide,
|
||||||
EntityTypes.smoke,
|
EntityTypes.entry,
|
||||||
EntityTypes.leak,
|
EntityTypes.leak,
|
||||||
|
EntityTypes.smoke,
|
||||||
]
|
]
|
||||||
|
|
||||||
HA_SENSOR_TYPES = {
|
DEVICE_CLASSES = {
|
||||||
EntityTypes.entry: DEVICE_CLASS_DOOR,
|
|
||||||
EntityTypes.carbon_monoxide: DEVICE_CLASS_GAS,
|
EntityTypes.carbon_monoxide: DEVICE_CLASS_GAS,
|
||||||
EntityTypes.smoke: DEVICE_CLASS_SMOKE,
|
EntityTypes.entry: DEVICE_CLASS_DOOR,
|
||||||
EntityTypes.leak: DEVICE_CLASS_MOISTURE,
|
EntityTypes.leak: DEVICE_CLASS_MOISTURE,
|
||||||
|
EntityTypes.smoke: DEVICE_CLASS_SMOKE,
|
||||||
}
|
}
|
||||||
|
|
||||||
SENSOR_MODELS = {
|
SENSOR_MODELS = {
|
||||||
EntityTypes.entry: "Entry Sensor",
|
|
||||||
EntityTypes.carbon_monoxide: "Carbon Monoxide Detector",
|
EntityTypes.carbon_monoxide: "Carbon Monoxide Detector",
|
||||||
EntityTypes.smoke: "Smoke Detector",
|
EntityTypes.entry: "Entry Sensor",
|
||||||
EntityTypes.leak: "Water Sensor",
|
EntityTypes.leak: "Water Sensor",
|
||||||
|
EntityTypes.smoke: "Smoke Detector",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -56,10 +56,10 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
for sensor in system.sensors.values():
|
for sensor in system.sensors.values():
|
||||||
if sensor.type in SUPPORTED_SENSOR_TYPES:
|
if sensor.type in SUPPORTED_TRIGGERED_SENSOR_TYPES:
|
||||||
sensors.append(SimpliSafeBinarySensor(simplisafe, system, sensor))
|
sensors.append(TriggeredBinarySensor(simplisafe, system, sensor))
|
||||||
if sensor.type in SUPPORTED_BATTERY_SENSOR_TYPES:
|
if sensor.type in SUPPORTED_BATTERY_SENSOR_TYPES:
|
||||||
sensors.append(SimpliSafeSensorBattery(simplisafe, system, sensor))
|
sensors.append(BatteryBinarySensor(simplisafe, system, sensor))
|
||||||
|
|
||||||
async_add_entities(sensors)
|
async_add_entities(sensors)
|
||||||
|
|
||||||
@ -70,6 +70,17 @@ class SimpliSafeBinarySensor(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._device_info["identifiers"] = {(DOMAIN, sensor.serial)}
|
||||||
|
self._device_info["model"] = SENSOR_MODELS[sensor.type]
|
||||||
|
self._device_info["name"] = sensor.name
|
||||||
|
|
||||||
|
|
||||||
|
class TriggeredBinarySensor(SimpliSafeBinarySensor):
|
||||||
|
"""Define a binary sensor related to whether an entity has been triggered."""
|
||||||
|
|
||||||
|
def __init__(self, simplisafe, system, sensor):
|
||||||
|
"""Initialize."""
|
||||||
|
super().__init__(simplisafe, system, sensor)
|
||||||
self._system = system
|
self._system = system
|
||||||
self._sensor = sensor
|
self._sensor = sensor
|
||||||
self._is_on = False
|
self._is_on = False
|
||||||
@ -77,16 +88,7 @@ class SimpliSafeBinarySensor(SimpliSafeEntity, BinarySensorEntity):
|
|||||||
@property
|
@property
|
||||||
def device_class(self):
|
def device_class(self):
|
||||||
"""Return type of sensor."""
|
"""Return type of sensor."""
|
||||||
return HA_SENSOR_TYPES[self._sensor.type]
|
return DEVICE_CLASSES[self._sensor.type]
|
||||||
|
|
||||||
@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):
|
||||||
@ -99,19 +101,15 @@ class SimpliSafeBinarySensor(SimpliSafeEntity, BinarySensorEntity):
|
|||||||
self._is_on = self._sensor.triggered
|
self._is_on = self._sensor.triggered
|
||||||
|
|
||||||
|
|
||||||
class SimpliSafeSensorBattery(SimpliSafeEntity, BinarySensorEntity):
|
class BatteryBinarySensor(SimpliSafeEntity, BinarySensorEntity):
|
||||||
"""Define a SimpliSafe battery binary sensor entity."""
|
"""Define a SimpliSafe battery binary sensor entity."""
|
||||||
|
|
||||||
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)
|
||||||
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."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user