diff --git a/homeassistant/components/simplisafe/binary_sensor.py b/homeassistant/components/simplisafe/binary_sensor.py index 263bbf51b13..67a4af4752d 100644 --- a/homeassistant/components/simplisafe/binary_sensor.py +++ b/homeassistant/components/simplisafe/binary_sensor.py @@ -23,25 +23,25 @@ SUPPORTED_BATTERY_SENSOR_TYPES = [ EntityTypes.temperature, ] -SUPPORTED_SENSOR_TYPES = [ - EntityTypes.entry, +SUPPORTED_TRIGGERED_SENSOR_TYPES = [ EntityTypes.carbon_monoxide, - EntityTypes.smoke, + EntityTypes.entry, EntityTypes.leak, + EntityTypes.smoke, ] -HA_SENSOR_TYPES = { - EntityTypes.entry: DEVICE_CLASS_DOOR, +DEVICE_CLASSES = { EntityTypes.carbon_monoxide: DEVICE_CLASS_GAS, - EntityTypes.smoke: DEVICE_CLASS_SMOKE, + EntityTypes.entry: DEVICE_CLASS_DOOR, EntityTypes.leak: DEVICE_CLASS_MOISTURE, + EntityTypes.smoke: DEVICE_CLASS_SMOKE, } SENSOR_MODELS = { - EntityTypes.entry: "Entry Sensor", EntityTypes.carbon_monoxide: "Carbon Monoxide Detector", - EntityTypes.smoke: "Smoke Detector", + EntityTypes.entry: "Entry Sensor", EntityTypes.leak: "Water Sensor", + EntityTypes.smoke: "Smoke Detector", } @@ -56,10 +56,10 @@ async def async_setup_entry(hass, entry, async_add_entities): continue for sensor in system.sensors.values(): - if sensor.type in SUPPORTED_SENSOR_TYPES: - sensors.append(SimpliSafeBinarySensor(simplisafe, system, sensor)) + if sensor.type in SUPPORTED_TRIGGERED_SENSOR_TYPES: + sensors.append(TriggeredBinarySensor(simplisafe, system, sensor)) if sensor.type in SUPPORTED_BATTERY_SENSOR_TYPES: - sensors.append(SimpliSafeSensorBattery(simplisafe, system, sensor)) + sensors.append(BatteryBinarySensor(simplisafe, system, sensor)) async_add_entities(sensors) @@ -70,6 +70,17 @@ class SimpliSafeBinarySensor(SimpliSafeEntity, BinarySensorEntity): 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.""" + + def __init__(self, simplisafe, system, sensor): + """Initialize.""" + super().__init__(simplisafe, system, sensor) self._system = system self._sensor = sensor self._is_on = False @@ -77,16 +88,7 @@ class SimpliSafeBinarySensor(SimpliSafeEntity, BinarySensorEntity): @property def device_class(self): """Return type of sensor.""" - return HA_SENSOR_TYPES[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 + return DEVICE_CLASSES[self._sensor.type] @property def is_on(self): @@ -99,19 +101,15 @@ class SimpliSafeBinarySensor(SimpliSafeEntity, BinarySensorEntity): self._is_on = self._sensor.triggered -class SimpliSafeSensorBattery(SimpliSafeEntity, BinarySensorEntity): +class BatteryBinarySensor(SimpliSafeEntity, BinarySensorEntity): """Define a SimpliSafe battery binary sensor entity.""" def __init__(self, simplisafe, system, sensor): """Initialize.""" - super().__init__(simplisafe, system, sensor.name, serial=sensor.serial) + super().__init__(simplisafe, system, sensor) 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."""