Fix missing sensor exceptions in SimpliSafe (#42845)
* Fix missing sensor exceptions in SimpliSafe * Entity types * Don't overdo it
This commit is contained in:
parent
b0a6ac7e91
commit
5b754c29e0
3 changed files with 31 additions and 44 deletions
|
@ -728,3 +728,15 @@ class SimpliSafeEntity(CoordinatorEntity):
|
||||||
@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."""
|
||||||
|
|
||||||
|
|
||||||
|
class SimpliSafeBaseSensor(SimpliSafeEntity):
|
||||||
|
"""Define a SimpliSafe base (binary) sensor."""
|
||||||
|
|
||||||
|
def __init__(self, simplisafe, system, sensor):
|
||||||
|
"""Initialize."""
|
||||||
|
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
|
||||||
|
|
|
@ -11,7 +11,7 @@ from homeassistant.components.binary_sensor import (
|
||||||
)
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
|
|
||||||
from . import SimpliSafeEntity
|
from . import SimpliSafeBaseSensor
|
||||||
from .const import DATA_CLIENT, DOMAIN, LOGGER
|
from .const import DATA_CLIENT, DOMAIN, LOGGER
|
||||||
|
|
||||||
SUPPORTED_BATTERY_SENSOR_TYPES = [
|
SUPPORTED_BATTERY_SENSOR_TYPES = [
|
||||||
|
@ -23,27 +23,13 @@ SUPPORTED_BATTERY_SENSOR_TYPES = [
|
||||||
EntityTypes.temperature,
|
EntityTypes.temperature,
|
||||||
]
|
]
|
||||||
|
|
||||||
SUPPORTED_TRIGGERED_SENSOR_TYPES = [
|
TRIGGERED_SENSOR_TYPES = {
|
||||||
EntityTypes.carbon_monoxide,
|
|
||||||
EntityTypes.entry,
|
|
||||||
EntityTypes.leak,
|
|
||||||
EntityTypes.smoke,
|
|
||||||
]
|
|
||||||
|
|
||||||
DEVICE_CLASSES = {
|
|
||||||
EntityTypes.carbon_monoxide: DEVICE_CLASS_GAS,
|
EntityTypes.carbon_monoxide: DEVICE_CLASS_GAS,
|
||||||
EntityTypes.entry: DEVICE_CLASS_DOOR,
|
EntityTypes.entry: DEVICE_CLASS_DOOR,
|
||||||
EntityTypes.leak: DEVICE_CLASS_MOISTURE,
|
EntityTypes.leak: DEVICE_CLASS_MOISTURE,
|
||||||
EntityTypes.smoke: DEVICE_CLASS_SMOKE,
|
EntityTypes.smoke: DEVICE_CLASS_SMOKE,
|
||||||
}
|
}
|
||||||
|
|
||||||
SENSOR_MODELS = {
|
|
||||||
EntityTypes.carbon_monoxide: "Carbon Monoxide Detector",
|
|
||||||
EntityTypes.entry: "Entry Sensor",
|
|
||||||
EntityTypes.leak: "Water Sensor",
|
|
||||||
EntityTypes.smoke: "Smoke Detector",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass, entry, async_add_entities):
|
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."""
|
||||||
|
@ -56,39 +42,34 @@ 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_TRIGGERED_SENSOR_TYPES:
|
if sensor.type in TRIGGERED_SENSOR_TYPES:
|
||||||
sensors.append(TriggeredBinarySensor(simplisafe, system, sensor))
|
sensors.append(
|
||||||
|
TriggeredBinarySensor(
|
||||||
|
simplisafe,
|
||||||
|
system,
|
||||||
|
sensor,
|
||||||
|
TRIGGERED_SENSOR_TYPES[sensor.type],
|
||||||
|
)
|
||||||
|
)
|
||||||
if sensor.type in SUPPORTED_BATTERY_SENSOR_TYPES:
|
if sensor.type in SUPPORTED_BATTERY_SENSOR_TYPES:
|
||||||
sensors.append(BatteryBinarySensor(simplisafe, system, sensor))
|
sensors.append(BatteryBinarySensor(simplisafe, system, sensor))
|
||||||
|
|
||||||
async_add_entities(sensors)
|
async_add_entities(sensors)
|
||||||
|
|
||||||
|
|
||||||
class SimpliSafeBinarySensor(SimpliSafeEntity, BinarySensorEntity):
|
class TriggeredBinarySensor(SimpliSafeBaseSensor, BinarySensorEntity):
|
||||||
"""Define a SimpliSafe binary sensor entity."""
|
|
||||||
|
|
||||||
def __init__(self, simplisafe, system, sensor):
|
|
||||||
"""Initialize."""
|
|
||||||
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."""
|
"""Define a binary sensor related to whether an entity has been triggered."""
|
||||||
|
|
||||||
def __init__(self, simplisafe, system, sensor):
|
def __init__(self, simplisafe, system, sensor, device_class):
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
super().__init__(simplisafe, system, sensor)
|
super().__init__(simplisafe, system, sensor)
|
||||||
self._system = system
|
self._device_class = device_class
|
||||||
self._sensor = sensor
|
|
||||||
self._is_on = False
|
self._is_on = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_class(self):
|
def device_class(self):
|
||||||
"""Return type of sensor."""
|
"""Return type of sensor."""
|
||||||
return DEVICE_CLASSES[self._sensor.type]
|
return self._device_class
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
|
@ -101,13 +82,12 @@ class TriggeredBinarySensor(SimpliSafeBinarySensor):
|
||||||
self._is_on = self._sensor.triggered
|
self._is_on = self._sensor.triggered
|
||||||
|
|
||||||
|
|
||||||
class BatteryBinarySensor(SimpliSafeEntity, BinarySensorEntity):
|
class BatteryBinarySensor(SimpliSafeBaseSensor, 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)
|
super().__init__(simplisafe, system, sensor)
|
||||||
self._sensor = sensor
|
|
||||||
self._is_low = False
|
self._is_low = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -4,7 +4,7 @@ from simplipy.entity import EntityTypes
|
||||||
from homeassistant.const import DEVICE_CLASS_TEMPERATURE, TEMP_FAHRENHEIT
|
from homeassistant.const import DEVICE_CLASS_TEMPERATURE, TEMP_FAHRENHEIT
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
|
|
||||||
from . import SimpliSafeEntity
|
from . import SimpliSafeBaseSensor
|
||||||
from .const import DATA_CLIENT, DOMAIN, LOGGER
|
from .const import DATA_CLIENT, DOMAIN, LOGGER
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,19 +25,14 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
||||||
async_add_entities(sensors)
|
async_add_entities(sensors)
|
||||||
|
|
||||||
|
|
||||||
class SimplisafeFreezeSensor(SimpliSafeEntity):
|
class SimplisafeFreezeSensor(SimpliSafeBaseSensor):
|
||||||
"""Define a SimpliSafe freeze sensor entity."""
|
"""Define a SimpliSafe freeze 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._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."""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue