"""Support for sensors.""" from __future__ import annotations from homeassistant.components.number import NumberEntity from homeassistant.config_entries import ConfigEntry from homeassistant.const import TIME_MINUTES from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import DeviceInfo, Entity, EntityCategory from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.update_coordinator import CoordinatorEntity from . import Coordinator, async_setup_entry_platform async def async_setup_entry( hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: AddEntitiesCallback, ) -> None: """Set up number entities dynamically through discovery.""" def _constructor(coordinator: Coordinator) -> list[Entity]: return [ PeriodicVentingTime(coordinator, coordinator.device_info), ] async_setup_entry_platform(hass, config_entry, async_add_entities, _constructor) class PeriodicVentingTime(CoordinatorEntity[Coordinator], NumberEntity): """Periodic Venting.""" _attr_has_entity_name = True _attr_native_max_value: float = 59 _attr_native_min_value: float = 0 _attr_native_step: float = 1 _attr_entity_category = EntityCategory.CONFIG _attr_native_unit_of_measurement = TIME_MINUTES def __init__( self, coordinator: Coordinator, device_info: DeviceInfo, ) -> None: """Init number entities.""" super().__init__(coordinator) self._attr_unique_id = f"{coordinator.device.address}-periodic-venting" self._attr_device_info = device_info self._attr_name = "Periodic venting" @property def native_value(self) -> float | None: """Return the entity value to represent the entity state.""" if data := self.coordinator.data: return data.periodic_venting return None async def async_set_native_value(self, value: float) -> None: """Set new value.""" async with self.coordinator.async_connect_and_update() as device: await device.send_periodic_venting(int(value))