Add number entities for program temperature in ViCare integration (#103960)
* add number platform * Update .coveragerc * reset default value * fix default value * cast Any value to float * Apply suggestions from code review * Update strings.json * add translation keys * remove obsolete unique id handling * add eco program * reset type * remove name from entity * Update strings.json * Update strings.json * rename * Apply suggestions from code review Co-authored-by: G Johansson <goran.johansson@shiftit.se> * retype getter * adjust interface * use device classes * check setter * Revert "check setter" This reverts commitpull/104924/head360e333159
. * remove eco entity * Update strings.json * add eco sensor entity * Revert "add eco sensor entity" This reverts commitd64b38c548
. * Update strings.json --------- Co-authored-by: G Johansson <goran.johansson@shiftit.se>
parent
c9306049b3
commit
7480945465
|
@ -41,7 +41,7 @@ _TOKEN_FILENAME = "vicare_token.save"
|
|||
class ViCareRequiredKeysMixin:
|
||||
"""Mixin for required keys."""
|
||||
|
||||
value_getter: Callable[[Device], bool]
|
||||
value_getter: Callable[[Device], Any]
|
||||
|
||||
|
||||
@dataclass()
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""Viessmann ViCare sensor device."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from contextlib import suppress
|
||||
from dataclasses import dataclass
|
||||
import logging
|
||||
|
@ -40,6 +41,8 @@ class ViCareBinarySensorEntityDescription(
|
|||
):
|
||||
"""Describes ViCare binary sensor entity."""
|
||||
|
||||
value_getter: Callable[[PyViCareDevice], bool]
|
||||
|
||||
|
||||
CIRCUIT_SENSORS: tuple[ViCareBinarySensorEntityDescription, ...] = (
|
||||
ViCareBinarySensorEntityDescription(
|
||||
|
|
|
@ -19,7 +19,11 @@ from PyViCare.PyViCareUtils import (
|
|||
)
|
||||
from requests.exceptions import ConnectionError as RequestConnectionError
|
||||
|
||||
from homeassistant.components.number import NumberEntity, NumberEntityDescription
|
||||
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
|
||||
|
@ -37,6 +41,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||
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
|
||||
|
@ -49,6 +54,7 @@ CIRCUIT_ENTITY_DESCRIPTIONS: tuple[ViCareNumberEntityDescription, ...] = (
|
|||
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: (
|
||||
|
@ -77,6 +83,42 @@ CIRCUIT_ENTITY_DESCRIPTIONS: tuple[ViCareNumberEntityDescription, ...] = (
|
|||
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"),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
@ -149,6 +191,7 @@ class ViCareNumber(ViCareEntity, NumberEntity):
|
|||
self._attr_native_value = self.entity_description.value_getter(
|
||||
self._api
|
||||
)
|
||||
|
||||
if min_value := _get_value(
|
||||
self.entity_description.min_value_getter, self._api
|
||||
):
|
||||
|
|
|
@ -80,9 +80,6 @@
|
|||
},
|
||||
"comfort_temperature": {
|
||||
"name": "Comfort temperature"
|
||||
},
|
||||
"eco_temperature": {
|
||||
"name": "Eco temperature"
|
||||
}
|
||||
},
|
||||
"sensor": {
|
||||
|
|
Loading…
Reference in New Issue