mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
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 commit 360e33315987c086d923992a4ced888886636627. * remove eco entity * Update strings.json * add eco sensor entity * Revert "add eco sensor entity" This reverts commit d64b38c548d0cdc56571b7c75fa026b1bb755f42. * Update strings.json --------- Co-authored-by: G Johansson <goran.johansson@shiftit.se>
This commit is contained in:
parent
c9306049b3
commit
7480945465
@ -41,7 +41,7 @@ _TOKEN_FILENAME = "vicare_token.save"
|
|||||||
class ViCareRequiredKeysMixin:
|
class ViCareRequiredKeysMixin:
|
||||||
"""Mixin for required keys."""
|
"""Mixin for required keys."""
|
||||||
|
|
||||||
value_getter: Callable[[Device], bool]
|
value_getter: Callable[[Device], Any]
|
||||||
|
|
||||||
|
|
||||||
@dataclass()
|
@dataclass()
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""Viessmann ViCare sensor device."""
|
"""Viessmann ViCare sensor device."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Callable
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
import logging
|
import logging
|
||||||
@ -40,6 +41,8 @@ class ViCareBinarySensorEntityDescription(
|
|||||||
):
|
):
|
||||||
"""Describes ViCare binary sensor entity."""
|
"""Describes ViCare binary sensor entity."""
|
||||||
|
|
||||||
|
value_getter: Callable[[PyViCareDevice], bool]
|
||||||
|
|
||||||
|
|
||||||
CIRCUIT_SENSORS: tuple[ViCareBinarySensorEntityDescription, ...] = (
|
CIRCUIT_SENSORS: tuple[ViCareBinarySensorEntityDescription, ...] = (
|
||||||
ViCareBinarySensorEntityDescription(
|
ViCareBinarySensorEntityDescription(
|
||||||
|
@ -19,7 +19,11 @@ from PyViCare.PyViCareUtils import (
|
|||||||
)
|
)
|
||||||
from requests.exceptions import ConnectionError as RequestConnectionError
|
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.config_entries import ConfigEntry
|
||||||
from homeassistant.const import EntityCategory, UnitOfTemperature
|
from homeassistant.const import EntityCategory, UnitOfTemperature
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -37,6 +41,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
class ViCareNumberEntityDescription(NumberEntityDescription, ViCareRequiredKeysMixin):
|
class ViCareNumberEntityDescription(NumberEntityDescription, ViCareRequiredKeysMixin):
|
||||||
"""Describes ViCare number entity."""
|
"""Describes ViCare number entity."""
|
||||||
|
|
||||||
|
value_getter: Callable[[PyViCareDevice], float]
|
||||||
value_setter: Callable[[PyViCareDevice, float], Any] | None = None
|
value_setter: Callable[[PyViCareDevice, float], Any] | None = None
|
||||||
min_value_getter: Callable[[PyViCareDevice], float | None] | None = None
|
min_value_getter: Callable[[PyViCareDevice], float | None] | None = None
|
||||||
max_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",
|
translation_key="heating_curve_shift",
|
||||||
icon="mdi:plus-minus-variant",
|
icon="mdi:plus-minus-variant",
|
||||||
entity_category=EntityCategory.CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
|
device_class=NumberDeviceClass.TEMPERATURE,
|
||||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
value_getter=lambda api: api.getHeatingCurveShift(),
|
value_getter=lambda api: api.getHeatingCurveShift(),
|
||||||
value_setter=lambda api, shift: (
|
value_setter=lambda api, shift: (
|
||||||
@ -77,6 +83,42 @@ CIRCUIT_ENTITY_DESCRIPTIONS: tuple[ViCareNumberEntityDescription, ...] = (
|
|||||||
native_max_value=3.5,
|
native_max_value=3.5,
|
||||||
native_step=0.1,
|
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._attr_native_value = self.entity_description.value_getter(
|
||||||
self._api
|
self._api
|
||||||
)
|
)
|
||||||
|
|
||||||
if min_value := _get_value(
|
if min_value := _get_value(
|
||||||
self.entity_description.min_value_getter, self._api
|
self.entity_description.min_value_getter, self._api
|
||||||
):
|
):
|
||||||
|
@ -80,9 +80,6 @@
|
|||||||
},
|
},
|
||||||
"comfort_temperature": {
|
"comfort_temperature": {
|
||||||
"name": "Comfort temperature"
|
"name": "Comfort temperature"
|
||||||
},
|
|
||||||
"eco_temperature": {
|
|
||||||
"name": "Eco temperature"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sensor": {
|
"sensor": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user