core/homeassistant/components/fritzbox/sensor.py

39 lines
1.3 KiB
Python
Raw Normal View History

"""Support for AVM FRITZ!SmartHome temperature sensor only devices."""
from __future__ import annotations
from homeassistant.components.fritzbox.model import FritzSensorEntityDescription
from homeassistant.components.sensor import SensorEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import FritzBoxEntity
from .const import CONF_COORDINATOR, DOMAIN as FRITZBOX_DOMAIN, SENSOR_TYPES
async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None:
"""Set up the FRITZ!SmartHome sensor from ConfigEntry."""
coordinator = hass.data[FRITZBOX_DOMAIN][entry.entry_id][CONF_COORDINATOR]
async_add_entities(
[
FritzBoxSensor(coordinator, ain, description)
for ain, device in coordinator.data.items()
for description in SENSOR_TYPES
if description.suitable(device)
]
)
class FritzBoxSensor(FritzBoxEntity, SensorEntity):
"""The entity class for FRITZ!SmartHome sensors."""
entity_description: FritzSensorEntityDescription
@property
def native_value(self) -> float | int | None:
"""Return the state of the sensor."""
return self.entity_description.native_value(self.device)