2020-10-12 17:31:55 +00:00
|
|
|
"""Support for SimpliSafe freeze sensor."""
|
|
|
|
from simplipy.entity import EntityTypes
|
|
|
|
|
2021-03-22 18:54:14 +00:00
|
|
|
from homeassistant.components.sensor import 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
|
|
|
|
2020-11-04 19:34:14 +00:00
|
|
|
from . import SimpliSafeBaseSensor
|
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."""
|
|
|
|
simplisafe = hass.data[DOMAIN][DATA_CLIENT][entry.entry_id]
|
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():
|
|
|
|
if sensor.type == EntityTypes.temperature:
|
|
|
|
sensors.append(SimplisafeFreezeSensor(simplisafe, system, sensor))
|
|
|
|
|
|
|
|
async_add_entities(sensors)
|
2020-10-12 17:31:55 +00:00
|
|
|
|
|
|
|
|
2021-03-22 18:54:14 +00:00
|
|
|
class SimplisafeFreezeSensor(SimpliSafeBaseSensor, 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
|
|
|
|
_attr_unit_of_measurement = TEMP_FAHRENHEIT
|
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-07-03 16:16:55 +00:00
|
|
|
self._attr_state = self._sensor.temperature
|