2020-10-12 17:31:55 +00:00
|
|
|
"""Support for SimpliSafe freeze sensor."""
|
2021-10-21 10:54:50 +00:00
|
|
|
from __future__ import annotations
|
2021-10-19 20:09:48 +00:00
|
|
|
|
|
|
|
from simplipy.device import DeviceTypes
|
|
|
|
from simplipy.device.sensor.v3 import SensorV3
|
2021-10-21 10:54:50 +00:00
|
|
|
from simplipy.system.v3 import SystemV3
|
2020-10-12 17:31:55 +00:00
|
|
|
|
2021-08-30 17:04:21 +00:00
|
|
|
from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorEntity
|
2021-07-27 20:11:54 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2020-10-12 17:31:55 +00:00
|
|
|
from homeassistant.const import DEVICE_CLASS_TEMPERATURE, TEMP_FAHRENHEIT
|
2021-07-27 20:11:54 +00:00
|
|
|
from homeassistant.core import HomeAssistant, callback
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2020-10-12 17:31:55 +00:00
|
|
|
|
2021-10-21 10:54:50 +00:00
|
|
|
from . import SimpliSafe, SimpliSafeEntity
|
2020-10-22 16:01:10 +00:00
|
|
|
from .const import DATA_CLIENT, DOMAIN, LOGGER
|
2020-10-12 17:31:55 +00:00
|
|
|
|
|
|
|
|
2021-07-27 20:11:54 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
|
|
|
) -> None:
|
2020-10-12 17:31:55 +00:00
|
|
|
"""Set up SimpliSafe freeze sensors based on a config entry."""
|
2021-10-19 20:09:48 +00:00
|
|
|
simplisafe = hass.data[DOMAIN][entry.entry_id][DATA_CLIENT]
|
2020-10-22 16:01:10 +00:00
|
|
|
sensors = []
|
2020-10-12 17:31:55 +00:00
|
|
|
|
2020-10-22 16:01:10 +00:00
|
|
|
for system in simplisafe.systems.values():
|
|
|
|
if system.version == 2:
|
|
|
|
LOGGER.info("Skipping sensor setup for V2 system: %s", system.system_id)
|
|
|
|
continue
|
|
|
|
|
|
|
|
for sensor in system.sensors.values():
|
2021-10-19 20:09:48 +00:00
|
|
|
if sensor.type == DeviceTypes.temperature:
|
2020-10-22 16:01:10 +00:00
|
|
|
sensors.append(SimplisafeFreezeSensor(simplisafe, system, sensor))
|
|
|
|
|
|
|
|
async_add_entities(sensors)
|
2020-10-12 17:31:55 +00:00
|
|
|
|
|
|
|
|
2021-10-21 10:54:50 +00:00
|
|
|
class SimplisafeFreezeSensor(SimpliSafeEntity, SensorEntity):
|
2020-10-12 17:31:55 +00:00
|
|
|
"""Define a SimpliSafe freeze sensor entity."""
|
|
|
|
|
2021-07-03 16:16:55 +00:00
|
|
|
_attr_device_class = DEVICE_CLASS_TEMPERATURE
|
2021-08-12 15:40:55 +00:00
|
|
|
_attr_native_unit_of_measurement = TEMP_FAHRENHEIT
|
2021-08-30 17:04:21 +00:00
|
|
|
_attr_state_class = STATE_CLASS_MEASUREMENT
|
2020-10-12 17:31:55 +00:00
|
|
|
|
2021-10-21 10:54:50 +00:00
|
|
|
def __init__(
|
|
|
|
self, simplisafe: SimpliSafe, system: SystemV3, sensor: SensorV3
|
|
|
|
) -> None:
|
|
|
|
"""Initialize."""
|
|
|
|
super().__init__(simplisafe, system, device=sensor)
|
|
|
|
|
|
|
|
self._device: SensorV3
|
|
|
|
|
2020-10-12 17:31:55 +00:00
|
|
|
@callback
|
2021-07-27 20:11:54 +00:00
|
|
|
def async_update_from_rest_api(self) -> None:
|
2020-10-12 17:31:55 +00:00
|
|
|
"""Update the entity with the provided REST API data."""
|
2021-10-21 10:54:50 +00:00
|
|
|
self._attr_native_value = self._device.temperature
|