Files

111 lines
3.4 KiB
Python

"""Support for Vallox ventilation unit numbers."""
from dataclasses import dataclass
from typing import override
from homeassistant.components.number import (
NumberDeviceClass,
NumberEntity,
NumberEntityDescription,
)
from homeassistant.const import CONF_NAME, EntityCategory, UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from .coordinator import ValloxConfigEntry, ValloxDataUpdateCoordinator
from .entity import ValloxEntity
class ValloxNumberEntity(ValloxEntity, NumberEntity):
"""Representation of a Vallox number entity."""
entity_description: ValloxNumberEntityDescription
_attr_entity_category = EntityCategory.CONFIG
def __init__(
self,
name: str,
coordinator: ValloxDataUpdateCoordinator,
description: ValloxNumberEntityDescription,
) -> None:
"""Initialize the Vallox number entity."""
super().__init__(name, coordinator)
self.entity_description = description
self._attr_unique_id = f"{self._device_uuid}-{description.key}"
@property
@override
def native_value(self) -> float | None:
"""Return the value reported by the sensor."""
if (
value := self.coordinator.data.get(self.entity_description.metric_key)
) is None:
return None
return float(value)
@override
async def async_set_native_value(self, value: float) -> None:
"""Update the current value."""
await self.coordinator.client.set_values(
{self.entity_description.metric_key: float(value)}
)
await self.coordinator.async_request_refresh()
@dataclass(frozen=True, kw_only=True)
class ValloxNumberEntityDescription(NumberEntityDescription):
"""Describes Vallox number entity."""
metric_key: str
NUMBER_ENTITIES: tuple[ValloxNumberEntityDescription, ...] = (
ValloxNumberEntityDescription(
key="supply_air_target_home",
translation_key="supply_air_target_home",
metric_key="A_CYC_HOME_AIR_TEMP_TARGET",
device_class=NumberDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
native_min_value=5.0,
native_max_value=25.0,
native_step=1.0,
),
ValloxNumberEntityDescription(
key="supply_air_target_away",
translation_key="supply_air_target_away",
metric_key="A_CYC_AWAY_AIR_TEMP_TARGET",
device_class=NumberDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
native_min_value=5.0,
native_max_value=25.0,
native_step=1.0,
),
ValloxNumberEntityDescription(
key="supply_air_target_boost",
translation_key="supply_air_target_boost",
metric_key="A_CYC_BOOST_AIR_TEMP_TARGET",
device_class=NumberDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
native_min_value=5.0,
native_max_value=25.0,
native_step=1.0,
),
)
async def async_setup_entry(
hass: HomeAssistant,
entry: ValloxConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up the sensors."""
coordinator = entry.runtime_data
async_add_entities(
ValloxNumberEntity(entry.data[CONF_NAME], coordinator, description)
for description in NUMBER_ENTITIES
)