Files
core/homeassistant/components/fritzbox/sensor.py
Michael e2dac31471 Use EntityDescription - fritzbox (#55104)
* Use sensor entity description

* check if not none instead if callable

* List comprehension in switch and climate

* change state to native_value in description

* merge FritzBoxSensorEntity into FritzBoxEntity

* rename SENSOR_DESCRIPTIONS to SENSOR_TYPES

* use mixins for descriptions

* use comprehension in async_setup_entry()

* improve extra_state_attributes
2021-08-27 17:09:34 +02:00

39 lines
1.3 KiB
Python

"""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)