core/homeassistant/components/vicare/number.py

222 lines
8.4 KiB
Python
Raw Normal View History

"""Number for ViCare."""
from __future__ import annotations
from collections.abc import Callable
from contextlib import suppress
from dataclasses import dataclass
import logging
from typing import Any
from PyViCare.PyViCareDevice import Device as PyViCareDevice
from PyViCare.PyViCareDeviceConfig import PyViCareDeviceConfig
from PyViCare.PyViCareHeatingDevice import (
HeatingDeviceWithComponent as PyViCareHeatingDeviceComponent,
)
from PyViCare.PyViCareUtils import (
PyViCareInvalidDataError,
PyViCareNotSupportedFeatureError,
PyViCareRateLimitError,
)
from requests.exceptions import ConnectionError as RequestConnectionError
from homeassistant.components.number import (
NumberDeviceClass,
NumberEntity,
NumberEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import EntityCategory, UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
Add support for multiple devices linked to a Viessmann account (#96044) * care about all devices * use first device for diagnostics * update constants * handle multiple devices * handle multiple devices * handle multiple devices * handle multiple devices * handle multiple devices * code style * code style * code style * code style * code style * remove unused import * remove unused import * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * remove unused constant * Update const.py * Update binary_sensor.py * change format * change format * fix line duplication * fix line duplication * change format * fix typo * use serial in device name if multiple devices are found * add common base class * use base class * Update __init__.py * Update __init__.py * Update __init__.py * Update sensor.py * Update binary_sensor.py * correct import * use base class * fix cdestyle findings * fix pylint findings * fix mypy findings * fix codestyle finidings * move has_entity_name to base class * Revert "fix mypy findings" This reverts commit 2d78801a69ec13670e0ef47354daf54b383eb595. * fix type issue * move multiple device handling * fix import * remove special handling for device name * extract api getter * Update __init__.py * Update __init__.py * Update entity.py * Update button.py * Update binary_sensor.py * Update climate.py * Update sensor.py * Update water_heater.py * Apply suggestions from code review Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update __init__.py * fix mypy & black * move get_device to utils * rename const * Apply suggestions from code review Co-authored-by: Robert Resch <robert@resch.dev> * store device in config entry * extract types * fix diagnostics * handle new platform * handle api rate limit * add types * add types * rename * add types * ignore gateways for now * Update .coveragerc * adjust types * fix merge issues * rename * Update types.py * fix type * add test method * simplify * ignore unused devices * Apply suggestions from code review Co-authored-by: Robert Resch <robert@resch.dev> * fix findings * handle unsupported devices * Apply suggestions from code review Co-authored-by: Robert Resch <robert@resch.dev> * Update types.py * fix format * adjust variable naming * Update conftest.py * Update conftest.py * remove kw_only * Apply suggestions from code review * Update __init__.py * Update binary_sensor.py * Update button.py * Update climate.py * Update const.py * Update diagnostics.py * Update number.py * Update sensor.py * Update types.py * Update water_heater.py * fix comment * Apply suggestions from code review Co-authored-by: Erik Montnemery <erik@montnemery.com> --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> Co-authored-by: Robert Resch <robert@resch.dev> Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-02-15 12:58:00 +00:00
from .const import DEVICE_LIST, DOMAIN
from .entity import ViCareEntity
Add support for multiple devices linked to a Viessmann account (#96044) * care about all devices * use first device for diagnostics * update constants * handle multiple devices * handle multiple devices * handle multiple devices * handle multiple devices * handle multiple devices * code style * code style * code style * code style * code style * remove unused import * remove unused import * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * remove unused constant * Update const.py * Update binary_sensor.py * change format * change format * fix line duplication * fix line duplication * change format * fix typo * use serial in device name if multiple devices are found * add common base class * use base class * Update __init__.py * Update __init__.py * Update __init__.py * Update sensor.py * Update binary_sensor.py * correct import * use base class * fix cdestyle findings * fix pylint findings * fix mypy findings * fix codestyle finidings * move has_entity_name to base class * Revert "fix mypy findings" This reverts commit 2d78801a69ec13670e0ef47354daf54b383eb595. * fix type issue * move multiple device handling * fix import * remove special handling for device name * extract api getter * Update __init__.py * Update __init__.py * Update entity.py * Update button.py * Update binary_sensor.py * Update climate.py * Update sensor.py * Update water_heater.py * Apply suggestions from code review Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update __init__.py * fix mypy & black * move get_device to utils * rename const * Apply suggestions from code review Co-authored-by: Robert Resch <robert@resch.dev> * store device in config entry * extract types * fix diagnostics * handle new platform * handle api rate limit * add types * add types * rename * add types * ignore gateways for now * Update .coveragerc * adjust types * fix merge issues * rename * Update types.py * fix type * add test method * simplify * ignore unused devices * Apply suggestions from code review Co-authored-by: Robert Resch <robert@resch.dev> * fix findings * handle unsupported devices * Apply suggestions from code review Co-authored-by: Robert Resch <robert@resch.dev> * Update types.py * fix format * adjust variable naming * Update conftest.py * Update conftest.py * remove kw_only * Apply suggestions from code review * Update __init__.py * Update binary_sensor.py * Update button.py * Update climate.py * Update const.py * Update diagnostics.py * Update number.py * Update sensor.py * Update types.py * Update water_heater.py * fix comment * Apply suggestions from code review Co-authored-by: Erik Montnemery <erik@montnemery.com> --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> Co-authored-by: Robert Resch <robert@resch.dev> Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-02-15 12:58:00 +00:00
from .types import ViCareDevice, ViCareRequiredKeysMixin
from .utils import get_circuits, is_supported
_LOGGER = logging.getLogger(__name__)
@dataclass(frozen=True)
class ViCareNumberEntityDescription(NumberEntityDescription, ViCareRequiredKeysMixin):
"""Describes ViCare number entity."""
value_getter: Callable[[PyViCareDevice], float]
value_setter: Callable[[PyViCareDevice, float], Any] | None = None
min_value_getter: Callable[[PyViCareDevice], float | None] | None = None
max_value_getter: Callable[[PyViCareDevice], float | None] | None = None
stepping_getter: Callable[[PyViCareDevice], float | None] | None = None
CIRCUIT_ENTITY_DESCRIPTIONS: tuple[ViCareNumberEntityDescription, ...] = (
ViCareNumberEntityDescription(
key="heating curve shift",
translation_key="heating_curve_shift",
icon="mdi:plus-minus-variant",
entity_category=EntityCategory.CONFIG,
device_class=NumberDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
value_getter=lambda api: api.getHeatingCurveShift(),
value_setter=lambda api, shift: (
api.setHeatingCurve(shift, api.getHeatingCurveSlope())
),
min_value_getter=lambda api: api.getHeatingCurveShiftMin(),
max_value_getter=lambda api: api.getHeatingCurveShiftMax(),
stepping_getter=lambda api: api.getHeatingCurveShiftStepping(),
native_min_value=-13,
native_max_value=40,
native_step=1,
),
ViCareNumberEntityDescription(
key="heating curve slope",
translation_key="heating_curve_slope",
icon="mdi:slope-uphill",
entity_category=EntityCategory.CONFIG,
value_getter=lambda api: api.getHeatingCurveSlope(),
value_setter=lambda api, slope: (
api.setHeatingCurve(api.getHeatingCurveShift(), slope)
),
min_value_getter=lambda api: api.getHeatingCurveSlopeMin(),
max_value_getter=lambda api: api.getHeatingCurveSlopeMax(),
stepping_getter=lambda api: api.getHeatingCurveSlopeStepping(),
native_min_value=0.2,
native_max_value=3.5,
native_step=0.1,
),
ViCareNumberEntityDescription(
key="normal_temperature",
translation_key="normal_temperature",
entity_category=EntityCategory.CONFIG,
device_class=NumberDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
value_getter=lambda api: api.getDesiredTemperatureForProgram("normal"),
value_setter=lambda api, value: api.setProgramTemperature("normal", value),
min_value_getter=lambda api: api.getProgramMinTemperature("normal"),
max_value_getter=lambda api: api.getProgramMaxTemperature("normal"),
stepping_getter=lambda api: api.getProgramStepping("normal"),
),
ViCareNumberEntityDescription(
key="reduced_temperature",
translation_key="reduced_temperature",
entity_category=EntityCategory.CONFIG,
device_class=NumberDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
value_getter=lambda api: api.getDesiredTemperatureForProgram("reduced"),
value_setter=lambda api, value: api.setProgramTemperature("reduced", value),
min_value_getter=lambda api: api.getProgramMinTemperature("reduced"),
max_value_getter=lambda api: api.getProgramMaxTemperature("reduced"),
stepping_getter=lambda api: api.getProgramStepping("reduced"),
),
ViCareNumberEntityDescription(
key="comfort_temperature",
translation_key="comfort_temperature",
entity_category=EntityCategory.CONFIG,
device_class=NumberDeviceClass.TEMPERATURE,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
value_getter=lambda api: api.getDesiredTemperatureForProgram("comfort"),
value_setter=lambda api, value: api.setProgramTemperature("comfort", value),
min_value_getter=lambda api: api.getProgramMinTemperature("comfort"),
max_value_getter=lambda api: api.getProgramMaxTemperature("comfort"),
stepping_getter=lambda api: api.getProgramStepping("comfort"),
),
)
def _build_entities(
Add support for multiple devices linked to a Viessmann account (#96044) * care about all devices * use first device for diagnostics * update constants * handle multiple devices * handle multiple devices * handle multiple devices * handle multiple devices * handle multiple devices * code style * code style * code style * code style * code style * remove unused import * remove unused import * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * remove unused constant * Update const.py * Update binary_sensor.py * change format * change format * fix line duplication * fix line duplication * change format * fix typo * use serial in device name if multiple devices are found * add common base class * use base class * Update __init__.py * Update __init__.py * Update __init__.py * Update sensor.py * Update binary_sensor.py * correct import * use base class * fix cdestyle findings * fix pylint findings * fix mypy findings * fix codestyle finidings * move has_entity_name to base class * Revert "fix mypy findings" This reverts commit 2d78801a69ec13670e0ef47354daf54b383eb595. * fix type issue * move multiple device handling * fix import * remove special handling for device name * extract api getter * Update __init__.py * Update __init__.py * Update entity.py * Update button.py * Update binary_sensor.py * Update climate.py * Update sensor.py * Update water_heater.py * Apply suggestions from code review Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update __init__.py * fix mypy & black * move get_device to utils * rename const * Apply suggestions from code review Co-authored-by: Robert Resch <robert@resch.dev> * store device in config entry * extract types * fix diagnostics * handle new platform * handle api rate limit * add types * add types * rename * add types * ignore gateways for now * Update .coveragerc * adjust types * fix merge issues * rename * Update types.py * fix type * add test method * simplify * ignore unused devices * Apply suggestions from code review Co-authored-by: Robert Resch <robert@resch.dev> * fix findings * handle unsupported devices * Apply suggestions from code review Co-authored-by: Robert Resch <robert@resch.dev> * Update types.py * fix format * adjust variable naming * Update conftest.py * Update conftest.py * remove kw_only * Apply suggestions from code review * Update __init__.py * Update binary_sensor.py * Update button.py * Update climate.py * Update const.py * Update diagnostics.py * Update number.py * Update sensor.py * Update types.py * Update water_heater.py * fix comment * Apply suggestions from code review Co-authored-by: Erik Montnemery <erik@montnemery.com> --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> Co-authored-by: Robert Resch <robert@resch.dev> Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-02-15 12:58:00 +00:00
device_list: list[ViCareDevice],
) -> list[ViCareNumber]:
Add support for multiple devices linked to a Viessmann account (#96044) * care about all devices * use first device for diagnostics * update constants * handle multiple devices * handle multiple devices * handle multiple devices * handle multiple devices * handle multiple devices * code style * code style * code style * code style * code style * remove unused import * remove unused import * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * remove unused constant * Update const.py * Update binary_sensor.py * change format * change format * fix line duplication * fix line duplication * change format * fix typo * use serial in device name if multiple devices are found * add common base class * use base class * Update __init__.py * Update __init__.py * Update __init__.py * Update sensor.py * Update binary_sensor.py * correct import * use base class * fix cdestyle findings * fix pylint findings * fix mypy findings * fix codestyle finidings * move has_entity_name to base class * Revert "fix mypy findings" This reverts commit 2d78801a69ec13670e0ef47354daf54b383eb595. * fix type issue * move multiple device handling * fix import * remove special handling for device name * extract api getter * Update __init__.py * Update __init__.py * Update entity.py * Update button.py * Update binary_sensor.py * Update climate.py * Update sensor.py * Update water_heater.py * Apply suggestions from code review Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update __init__.py * fix mypy & black * move get_device to utils * rename const * Apply suggestions from code review Co-authored-by: Robert Resch <robert@resch.dev> * store device in config entry * extract types * fix diagnostics * handle new platform * handle api rate limit * add types * add types * rename * add types * ignore gateways for now * Update .coveragerc * adjust types * fix merge issues * rename * Update types.py * fix type * add test method * simplify * ignore unused devices * Apply suggestions from code review Co-authored-by: Robert Resch <robert@resch.dev> * fix findings * handle unsupported devices * Apply suggestions from code review Co-authored-by: Robert Resch <robert@resch.dev> * Update types.py * fix format * adjust variable naming * Update conftest.py * Update conftest.py * remove kw_only * Apply suggestions from code review * Update __init__.py * Update binary_sensor.py * Update button.py * Update climate.py * Update const.py * Update diagnostics.py * Update number.py * Update sensor.py * Update types.py * Update water_heater.py * fix comment * Apply suggestions from code review Co-authored-by: Erik Montnemery <erik@montnemery.com> --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> Co-authored-by: Robert Resch <robert@resch.dev> Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-02-15 12:58:00 +00:00
"""Create ViCare number entities for a device."""
return [
ViCareNumber(
circuit,
Add support for multiple devices linked to a Viessmann account (#96044) * care about all devices * use first device for diagnostics * update constants * handle multiple devices * handle multiple devices * handle multiple devices * handle multiple devices * handle multiple devices * code style * code style * code style * code style * code style * remove unused import * remove unused import * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * remove unused constant * Update const.py * Update binary_sensor.py * change format * change format * fix line duplication * fix line duplication * change format * fix typo * use serial in device name if multiple devices are found * add common base class * use base class * Update __init__.py * Update __init__.py * Update __init__.py * Update sensor.py * Update binary_sensor.py * correct import * use base class * fix cdestyle findings * fix pylint findings * fix mypy findings * fix codestyle finidings * move has_entity_name to base class * Revert "fix mypy findings" This reverts commit 2d78801a69ec13670e0ef47354daf54b383eb595. * fix type issue * move multiple device handling * fix import * remove special handling for device name * extract api getter * Update __init__.py * Update __init__.py * Update entity.py * Update button.py * Update binary_sensor.py * Update climate.py * Update sensor.py * Update water_heater.py * Apply suggestions from code review Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update __init__.py * fix mypy & black * move get_device to utils * rename const * Apply suggestions from code review Co-authored-by: Robert Resch <robert@resch.dev> * store device in config entry * extract types * fix diagnostics * handle new platform * handle api rate limit * add types * add types * rename * add types * ignore gateways for now * Update .coveragerc * adjust types * fix merge issues * rename * Update types.py * fix type * add test method * simplify * ignore unused devices * Apply suggestions from code review Co-authored-by: Robert Resch <robert@resch.dev> * fix findings * handle unsupported devices * Apply suggestions from code review Co-authored-by: Robert Resch <robert@resch.dev> * Update types.py * fix format * adjust variable naming * Update conftest.py * Update conftest.py * remove kw_only * Apply suggestions from code review * Update __init__.py * Update binary_sensor.py * Update button.py * Update climate.py * Update const.py * Update diagnostics.py * Update number.py * Update sensor.py * Update types.py * Update water_heater.py * fix comment * Apply suggestions from code review Co-authored-by: Erik Montnemery <erik@montnemery.com> --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> Co-authored-by: Robert Resch <robert@resch.dev> Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-02-15 12:58:00 +00:00
device.config,
description,
)
Add support for multiple devices linked to a Viessmann account (#96044) * care about all devices * use first device for diagnostics * update constants * handle multiple devices * handle multiple devices * handle multiple devices * handle multiple devices * handle multiple devices * code style * code style * code style * code style * code style * remove unused import * remove unused import * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * remove unused constant * Update const.py * Update binary_sensor.py * change format * change format * fix line duplication * fix line duplication * change format * fix typo * use serial in device name if multiple devices are found * add common base class * use base class * Update __init__.py * Update __init__.py * Update __init__.py * Update sensor.py * Update binary_sensor.py * correct import * use base class * fix cdestyle findings * fix pylint findings * fix mypy findings * fix codestyle finidings * move has_entity_name to base class * Revert "fix mypy findings" This reverts commit 2d78801a69ec13670e0ef47354daf54b383eb595. * fix type issue * move multiple device handling * fix import * remove special handling for device name * extract api getter * Update __init__.py * Update __init__.py * Update entity.py * Update button.py * Update binary_sensor.py * Update climate.py * Update sensor.py * Update water_heater.py * Apply suggestions from code review Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update __init__.py * fix mypy & black * move get_device to utils * rename const * Apply suggestions from code review Co-authored-by: Robert Resch <robert@resch.dev> * store device in config entry * extract types * fix diagnostics * handle new platform * handle api rate limit * add types * add types * rename * add types * ignore gateways for now * Update .coveragerc * adjust types * fix merge issues * rename * Update types.py * fix type * add test method * simplify * ignore unused devices * Apply suggestions from code review Co-authored-by: Robert Resch <robert@resch.dev> * fix findings * handle unsupported devices * Apply suggestions from code review Co-authored-by: Robert Resch <robert@resch.dev> * Update types.py * fix format * adjust variable naming * Update conftest.py * Update conftest.py * remove kw_only * Apply suggestions from code review * Update __init__.py * Update binary_sensor.py * Update button.py * Update climate.py * Update const.py * Update diagnostics.py * Update number.py * Update sensor.py * Update types.py * Update water_heater.py * fix comment * Apply suggestions from code review Co-authored-by: Erik Montnemery <erik@montnemery.com> --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> Co-authored-by: Robert Resch <robert@resch.dev> Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-02-15 12:58:00 +00:00
for device in device_list
for circuit in get_circuits(device.api)
for description in CIRCUIT_ENTITY_DESCRIPTIONS
if is_supported(description.key, description, circuit)
]
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Create the ViCare number devices."""
Add support for multiple devices linked to a Viessmann account (#96044) * care about all devices * use first device for diagnostics * update constants * handle multiple devices * handle multiple devices * handle multiple devices * handle multiple devices * handle multiple devices * code style * code style * code style * code style * code style * remove unused import * remove unused import * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * remove unused constant * Update const.py * Update binary_sensor.py * change format * change format * fix line duplication * fix line duplication * change format * fix typo * use serial in device name if multiple devices are found * add common base class * use base class * Update __init__.py * Update __init__.py * Update __init__.py * Update sensor.py * Update binary_sensor.py * correct import * use base class * fix cdestyle findings * fix pylint findings * fix mypy findings * fix codestyle finidings * move has_entity_name to base class * Revert "fix mypy findings" This reverts commit 2d78801a69ec13670e0ef47354daf54b383eb595. * fix type issue * move multiple device handling * fix import * remove special handling for device name * extract api getter * Update __init__.py * Update __init__.py * Update entity.py * Update button.py * Update binary_sensor.py * Update climate.py * Update sensor.py * Update water_heater.py * Apply suggestions from code review Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update __init__.py * fix mypy & black * move get_device to utils * rename const * Apply suggestions from code review Co-authored-by: Robert Resch <robert@resch.dev> * store device in config entry * extract types * fix diagnostics * handle new platform * handle api rate limit * add types * add types * rename * add types * ignore gateways for now * Update .coveragerc * adjust types * fix merge issues * rename * Update types.py * fix type * add test method * simplify * ignore unused devices * Apply suggestions from code review Co-authored-by: Robert Resch <robert@resch.dev> * fix findings * handle unsupported devices * Apply suggestions from code review Co-authored-by: Robert Resch <robert@resch.dev> * Update types.py * fix format * adjust variable naming * Update conftest.py * Update conftest.py * remove kw_only * Apply suggestions from code review * Update __init__.py * Update binary_sensor.py * Update button.py * Update climate.py * Update const.py * Update diagnostics.py * Update number.py * Update sensor.py * Update types.py * Update water_heater.py * fix comment * Apply suggestions from code review Co-authored-by: Erik Montnemery <erik@montnemery.com> --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> Co-authored-by: Robert Resch <robert@resch.dev> Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-02-15 12:58:00 +00:00
device_list = hass.data[DOMAIN][config_entry.entry_id][DEVICE_LIST]
async_add_entities(
await hass.async_add_executor_job(
_build_entities,
Add support for multiple devices linked to a Viessmann account (#96044) * care about all devices * use first device for diagnostics * update constants * handle multiple devices * handle multiple devices * handle multiple devices * handle multiple devices * handle multiple devices * code style * code style * code style * code style * code style * remove unused import * remove unused import * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * use has_entity_name and add serial to device name * remove unused constant * Update const.py * Update binary_sensor.py * change format * change format * fix line duplication * fix line duplication * change format * fix typo * use serial in device name if multiple devices are found * add common base class * use base class * Update __init__.py * Update __init__.py * Update __init__.py * Update sensor.py * Update binary_sensor.py * correct import * use base class * fix cdestyle findings * fix pylint findings * fix mypy findings * fix codestyle finidings * move has_entity_name to base class * Revert "fix mypy findings" This reverts commit 2d78801a69ec13670e0ef47354daf54b383eb595. * fix type issue * move multiple device handling * fix import * remove special handling for device name * extract api getter * Update __init__.py * Update __init__.py * Update entity.py * Update button.py * Update binary_sensor.py * Update climate.py * Update sensor.py * Update water_heater.py * Apply suggestions from code review Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update __init__.py * fix mypy & black * move get_device to utils * rename const * Apply suggestions from code review Co-authored-by: Robert Resch <robert@resch.dev> * store device in config entry * extract types * fix diagnostics * handle new platform * handle api rate limit * add types * add types * rename * add types * ignore gateways for now * Update .coveragerc * adjust types * fix merge issues * rename * Update types.py * fix type * add test method * simplify * ignore unused devices * Apply suggestions from code review Co-authored-by: Robert Resch <robert@resch.dev> * fix findings * handle unsupported devices * Apply suggestions from code review Co-authored-by: Robert Resch <robert@resch.dev> * Update types.py * fix format * adjust variable naming * Update conftest.py * Update conftest.py * remove kw_only * Apply suggestions from code review * Update __init__.py * Update binary_sensor.py * Update button.py * Update climate.py * Update const.py * Update diagnostics.py * Update number.py * Update sensor.py * Update types.py * Update water_heater.py * fix comment * Apply suggestions from code review Co-authored-by: Erik Montnemery <erik@montnemery.com> --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> Co-authored-by: Robert Resch <robert@resch.dev> Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-02-15 12:58:00 +00:00
device_list,
)
)
class ViCareNumber(ViCareEntity, NumberEntity):
"""Representation of a ViCare number."""
entity_description: ViCareNumberEntityDescription
def __init__(
self,
api: PyViCareHeatingDeviceComponent,
device_config: PyViCareDeviceConfig,
description: ViCareNumberEntityDescription,
) -> None:
"""Initialize the number."""
super().__init__(device_config, api, description.key)
self.entity_description = description
@property
def available(self) -> bool:
"""Return True if entity is available."""
return self._attr_native_value is not None
def set_native_value(self, value: float) -> None:
"""Set new value."""
if self.entity_description.value_setter:
self.entity_description.value_setter(self._api, value)
self.schedule_update_ha_state()
def update(self) -> None:
"""Update state of number."""
try:
with suppress(PyViCareNotSupportedFeatureError):
self._attr_native_value = self.entity_description.value_getter(
self._api
)
if min_value := _get_value(
self.entity_description.min_value_getter, self._api
):
self._attr_native_min_value = min_value
if max_value := _get_value(
self.entity_description.max_value_getter, self._api
):
self._attr_native_max_value = max_value
if stepping_value := _get_value(
self.entity_description.stepping_getter, self._api
):
self._attr_native_step = stepping_value
except RequestConnectionError:
_LOGGER.error("Unable to retrieve data from ViCare server")
except ValueError:
_LOGGER.error("Unable to decode data from ViCare server")
except PyViCareRateLimitError as limit_exception:
_LOGGER.error("Vicare API rate limit exceeded: %s", limit_exception)
except PyViCareInvalidDataError as invalid_data_exception:
_LOGGER.error("Invalid data from Vicare server: %s", invalid_data_exception)
def _get_value(
fn: Callable[[PyViCareDevice], float | None] | None,
api: PyViCareHeatingDeviceComponent,
) -> float | None:
return None if fn is None else fn(api)