2021-05-03 10:52:22 +00:00
|
|
|
"""Support for AVM FRITZ!SmartHome temperature sensor only devices."""
|
2021-05-15 05:54:11 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2021-08-27 15:09:34 +00:00
|
|
|
from homeassistant.components.fritzbox.model import FritzSensorEntityDescription
|
|
|
|
from homeassistant.components.sensor import SensorEntity
|
2021-04-25 00:40:12 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant
|
2021-04-30 18:38:59 +00:00
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2021-04-25 00:40:12 +00:00
|
|
|
from . import FritzBoxEntity
|
2021-08-27 15:09:34 +00:00
|
|
|
from .const import CONF_COORDINATOR, DOMAIN as FRITZBOX_DOMAIN, SENSOR_TYPES
|
2019-01-30 17:44:36 +00:00
|
|
|
|
|
|
|
|
2021-04-25 00:40:12 +00:00
|
|
|
async def async_setup_entry(
|
2021-04-30 18:38:59 +00:00
|
|
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
2021-04-25 00:40:12 +00:00
|
|
|
) -> None:
|
2021-05-03 10:52:22 +00:00
|
|
|
"""Set up the FRITZ!SmartHome sensor from ConfigEntry."""
|
2021-04-25 00:40:12 +00:00
|
|
|
coordinator = hass.data[FRITZBOX_DOMAIN][entry.entry_id][CONF_COORDINATOR]
|
2019-01-30 17:44:36 +00:00
|
|
|
|
2021-08-27 15:09:34 +00:00
|
|
|
async_add_entities(
|
|
|
|
[
|
|
|
|
FritzBoxSensor(coordinator, ain, description)
|
|
|
|
for ain, device in coordinator.data.items()
|
|
|
|
for description in SENSOR_TYPES
|
|
|
|
if description.suitable(device)
|
|
|
|
]
|
|
|
|
)
|
2019-01-30 17:44:36 +00:00
|
|
|
|
|
|
|
|
2021-08-12 12:23:56 +00:00
|
|
|
class FritzBoxSensor(FritzBoxEntity, SensorEntity):
|
|
|
|
"""The entity class for FRITZ!SmartHome sensors."""
|
|
|
|
|
2021-08-27 15:09:34 +00:00
|
|
|
entity_description: FritzSensorEntityDescription
|
2021-04-18 22:30:58 +00:00
|
|
|
|
|
|
|
@property
|
2021-08-27 15:09:34 +00:00
|
|
|
def native_value(self) -> float | int | None:
|
2021-04-18 22:30:58 +00:00
|
|
|
"""Return the state of the sensor."""
|
2021-08-27 15:09:34 +00:00
|
|
|
return self.entity_description.native_value(self.device)
|