mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Add number entities to change heat pump program temperatures in ViCare integration (#109315)
* add HeatingProgram type * use HeatingProgram type * add heatpump number sensors * use HeatingProgram type * Update strings.json * rename HeatingProgram to Program * remove commented code * rename heating program type * simplify * Apply suggestions from code review * Update strings.json * Update const.py * fix * add heating program type * correct imports * Revert "fix" This reverts commit 857dda59da188cdcf2d8d47073910ec042b4b523. * Apply suggestions from code review * Update strings.json
This commit is contained in:
parent
c1b4a21821
commit
88e9870f1c
@ -42,7 +42,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||||||
|
|
||||||
from .const import DEVICE_LIST, DOMAIN
|
from .const import DEVICE_LIST, DOMAIN
|
||||||
from .entity import ViCareEntity
|
from .entity import ViCareEntity
|
||||||
from .types import ViCareDevice
|
from .types import HeatingProgram, ViCareDevice
|
||||||
from .utils import get_burners, get_circuits, get_compressors
|
from .utils import get_burners, get_circuits, get_compressors
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -58,15 +58,6 @@ VICARE_MODE_FORCEDREDUCED = "forcedReduced"
|
|||||||
VICARE_MODE_FORCEDNORMAL = "forcedNormal"
|
VICARE_MODE_FORCEDNORMAL = "forcedNormal"
|
||||||
VICARE_MODE_OFF = "standby"
|
VICARE_MODE_OFF = "standby"
|
||||||
|
|
||||||
VICARE_PROGRAM_ACTIVE = "active"
|
|
||||||
VICARE_PROGRAM_COMFORT = "comfort"
|
|
||||||
VICARE_PROGRAM_ECO = "eco"
|
|
||||||
VICARE_PROGRAM_EXTERNAL = "external"
|
|
||||||
VICARE_PROGRAM_HOLIDAY = "holiday"
|
|
||||||
VICARE_PROGRAM_NORMAL = "normal"
|
|
||||||
VICARE_PROGRAM_REDUCED = "reduced"
|
|
||||||
VICARE_PROGRAM_STANDBY = "standby"
|
|
||||||
|
|
||||||
VICARE_HOLD_MODE_AWAY = "away"
|
VICARE_HOLD_MODE_AWAY = "away"
|
||||||
VICARE_HOLD_MODE_HOME = "home"
|
VICARE_HOLD_MODE_HOME = "home"
|
||||||
VICARE_HOLD_MODE_OFF = "off"
|
VICARE_HOLD_MODE_OFF = "off"
|
||||||
@ -85,18 +76,13 @@ VICARE_TO_HA_HVAC_HEATING: dict[str, HVACMode] = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
VICARE_TO_HA_PRESET_HEATING = {
|
VICARE_TO_HA_PRESET_HEATING = {
|
||||||
VICARE_PROGRAM_COMFORT: PRESET_COMFORT,
|
HeatingProgram.COMFORT: PRESET_COMFORT,
|
||||||
VICARE_PROGRAM_ECO: PRESET_ECO,
|
HeatingProgram.ECO: PRESET_ECO,
|
||||||
VICARE_PROGRAM_NORMAL: PRESET_HOME,
|
HeatingProgram.NORMAL: PRESET_HOME,
|
||||||
VICARE_PROGRAM_REDUCED: PRESET_SLEEP,
|
HeatingProgram.REDUCED: PRESET_SLEEP,
|
||||||
}
|
}
|
||||||
|
|
||||||
HA_TO_VICARE_PRESET_HEATING = {
|
HA_TO_VICARE_PRESET_HEATING = {v: k for k, v in VICARE_TO_HA_PRESET_HEATING.items()}
|
||||||
PRESET_COMFORT: VICARE_PROGRAM_COMFORT,
|
|
||||||
PRESET_ECO: VICARE_PROGRAM_ECO,
|
|
||||||
PRESET_HOME: VICARE_PROGRAM_NORMAL,
|
|
||||||
PRESET_SLEEP: VICARE_PROGRAM_REDUCED,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def _build_entities(
|
def _build_entities(
|
||||||
@ -319,9 +305,9 @@ class ViCareClimate(ViCareEntity, ClimateEntity):
|
|||||||
|
|
||||||
_LOGGER.debug("Current preset %s", self._current_program)
|
_LOGGER.debug("Current preset %s", self._current_program)
|
||||||
if self._current_program and self._current_program not in [
|
if self._current_program and self._current_program not in [
|
||||||
VICARE_PROGRAM_NORMAL,
|
HeatingProgram.NORMAL,
|
||||||
VICARE_PROGRAM_REDUCED,
|
HeatingProgram.REDUCED,
|
||||||
VICARE_PROGRAM_STANDBY,
|
HeatingProgram.STANDBY,
|
||||||
]:
|
]:
|
||||||
# We can't deactivate "normal", "reduced" or "standby"
|
# We can't deactivate "normal", "reduced" or "standby"
|
||||||
_LOGGER.debug("deactivating %s", self._current_program)
|
_LOGGER.debug("deactivating %s", self._current_program)
|
||||||
@ -338,9 +324,9 @@ class ViCareClimate(ViCareEntity, ClimateEntity):
|
|||||||
|
|
||||||
_LOGGER.debug("Setting preset to %s / %s", preset_mode, target_program)
|
_LOGGER.debug("Setting preset to %s / %s", preset_mode, target_program)
|
||||||
if target_program not in [
|
if target_program not in [
|
||||||
VICARE_PROGRAM_NORMAL,
|
HeatingProgram.NORMAL,
|
||||||
VICARE_PROGRAM_REDUCED,
|
HeatingProgram.REDUCED,
|
||||||
VICARE_PROGRAM_STANDBY,
|
HeatingProgram.STANDBY,
|
||||||
]:
|
]:
|
||||||
# And we can't explicitly activate "normal", "reduced" or "standby", either
|
# And we can't explicitly activate "normal", "reduced" or "standby", either
|
||||||
_LOGGER.debug("activating %s", target_program)
|
_LOGGER.debug("activating %s", target_program)
|
||||||
|
@ -31,7 +31,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||||||
|
|
||||||
from .const import DEVICE_LIST, DOMAIN
|
from .const import DEVICE_LIST, DOMAIN
|
||||||
from .entity import ViCareEntity
|
from .entity import ViCareEntity
|
||||||
from .types import ViCareDevice, ViCareRequiredKeysMixin
|
from .types import HeatingProgram, ViCareDevice, ViCareRequiredKeysMixin
|
||||||
from .utils import get_circuits, is_supported
|
from .utils import get_circuits, is_supported
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -89,11 +89,19 @@ CIRCUIT_ENTITY_DESCRIPTIONS: tuple[ViCareNumberEntityDescription, ...] = (
|
|||||||
entity_category=EntityCategory.CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
device_class=NumberDeviceClass.TEMPERATURE,
|
device_class=NumberDeviceClass.TEMPERATURE,
|
||||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
value_getter=lambda api: api.getDesiredTemperatureForProgram("normal"),
|
value_getter=lambda api: api.getDesiredTemperatureForProgram(
|
||||||
value_setter=lambda api, value: api.setProgramTemperature("normal", value),
|
HeatingProgram.NORMAL
|
||||||
min_value_getter=lambda api: api.getProgramMinTemperature("normal"),
|
),
|
||||||
max_value_getter=lambda api: api.getProgramMaxTemperature("normal"),
|
value_setter=lambda api, value: api.setProgramTemperature(
|
||||||
stepping_getter=lambda api: api.getProgramStepping("normal"),
|
HeatingProgram.NORMAL, value
|
||||||
|
),
|
||||||
|
min_value_getter=lambda api: api.getProgramMinTemperature(
|
||||||
|
HeatingProgram.NORMAL
|
||||||
|
),
|
||||||
|
max_value_getter=lambda api: api.getProgramMaxTemperature(
|
||||||
|
HeatingProgram.NORMAL
|
||||||
|
),
|
||||||
|
stepping_getter=lambda api: api.getProgramStepping(HeatingProgram.NORMAL),
|
||||||
),
|
),
|
||||||
ViCareNumberEntityDescription(
|
ViCareNumberEntityDescription(
|
||||||
key="reduced_temperature",
|
key="reduced_temperature",
|
||||||
@ -101,11 +109,19 @@ CIRCUIT_ENTITY_DESCRIPTIONS: tuple[ViCareNumberEntityDescription, ...] = (
|
|||||||
entity_category=EntityCategory.CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
device_class=NumberDeviceClass.TEMPERATURE,
|
device_class=NumberDeviceClass.TEMPERATURE,
|
||||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
value_getter=lambda api: api.getDesiredTemperatureForProgram("reduced"),
|
value_getter=lambda api: api.getDesiredTemperatureForProgram(
|
||||||
value_setter=lambda api, value: api.setProgramTemperature("reduced", value),
|
HeatingProgram.REDUCED
|
||||||
min_value_getter=lambda api: api.getProgramMinTemperature("reduced"),
|
),
|
||||||
max_value_getter=lambda api: api.getProgramMaxTemperature("reduced"),
|
value_setter=lambda api, value: api.setProgramTemperature(
|
||||||
stepping_getter=lambda api: api.getProgramStepping("reduced"),
|
HeatingProgram.REDUCED, value
|
||||||
|
),
|
||||||
|
min_value_getter=lambda api: api.getProgramMinTemperature(
|
||||||
|
HeatingProgram.REDUCED
|
||||||
|
),
|
||||||
|
max_value_getter=lambda api: api.getProgramMaxTemperature(
|
||||||
|
HeatingProgram.REDUCED
|
||||||
|
),
|
||||||
|
stepping_getter=lambda api: api.getProgramStepping(HeatingProgram.REDUCED),
|
||||||
),
|
),
|
||||||
ViCareNumberEntityDescription(
|
ViCareNumberEntityDescription(
|
||||||
key="comfort_temperature",
|
key="comfort_temperature",
|
||||||
@ -113,11 +129,85 @@ CIRCUIT_ENTITY_DESCRIPTIONS: tuple[ViCareNumberEntityDescription, ...] = (
|
|||||||
entity_category=EntityCategory.CONFIG,
|
entity_category=EntityCategory.CONFIG,
|
||||||
device_class=NumberDeviceClass.TEMPERATURE,
|
device_class=NumberDeviceClass.TEMPERATURE,
|
||||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
value_getter=lambda api: api.getDesiredTemperatureForProgram("comfort"),
|
value_getter=lambda api: api.getDesiredTemperatureForProgram(
|
||||||
value_setter=lambda api, value: api.setProgramTemperature("comfort", value),
|
HeatingProgram.COMFORT
|
||||||
min_value_getter=lambda api: api.getProgramMinTemperature("comfort"),
|
),
|
||||||
max_value_getter=lambda api: api.getProgramMaxTemperature("comfort"),
|
value_setter=lambda api, value: api.setProgramTemperature(
|
||||||
stepping_getter=lambda api: api.getProgramStepping("comfort"),
|
HeatingProgram.COMFORT, value
|
||||||
|
),
|
||||||
|
min_value_getter=lambda api: api.getProgramMinTemperature(
|
||||||
|
HeatingProgram.COMFORT
|
||||||
|
),
|
||||||
|
max_value_getter=lambda api: api.getProgramMaxTemperature(
|
||||||
|
HeatingProgram.COMFORT
|
||||||
|
),
|
||||||
|
stepping_getter=lambda api: api.getProgramStepping(HeatingProgram.COMFORT),
|
||||||
|
),
|
||||||
|
ViCareNumberEntityDescription(
|
||||||
|
key="normal_heating_temperature",
|
||||||
|
translation_key="normal_heating_temperature",
|
||||||
|
entity_category=EntityCategory.CONFIG,
|
||||||
|
device_class=NumberDeviceClass.TEMPERATURE,
|
||||||
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
|
value_getter=lambda api: api.getDesiredTemperatureForProgram(
|
||||||
|
HeatingProgram.NORMAL_HEATING
|
||||||
|
),
|
||||||
|
value_setter=lambda api, value: api.setProgramTemperature(
|
||||||
|
HeatingProgram.NORMAL_HEATING, value
|
||||||
|
),
|
||||||
|
min_value_getter=lambda api: api.getProgramMinTemperature(
|
||||||
|
HeatingProgram.NORMAL_HEATING
|
||||||
|
),
|
||||||
|
max_value_getter=lambda api: api.getProgramMaxTemperature(
|
||||||
|
HeatingProgram.NORMAL_HEATING
|
||||||
|
),
|
||||||
|
stepping_getter=lambda api: api.getProgramStepping(
|
||||||
|
HeatingProgram.NORMAL_HEATING
|
||||||
|
),
|
||||||
|
),
|
||||||
|
ViCareNumberEntityDescription(
|
||||||
|
key="reduced_heating_temperature",
|
||||||
|
translation_key="reduced_heating_temperature",
|
||||||
|
entity_category=EntityCategory.CONFIG,
|
||||||
|
device_class=NumberDeviceClass.TEMPERATURE,
|
||||||
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
|
value_getter=lambda api: api.getDesiredTemperatureForProgram(
|
||||||
|
HeatingProgram.REDUCED_HEATING
|
||||||
|
),
|
||||||
|
value_setter=lambda api, value: api.setProgramTemperature(
|
||||||
|
HeatingProgram.REDUCED_HEATING, value
|
||||||
|
),
|
||||||
|
min_value_getter=lambda api: api.getProgramMinTemperature(
|
||||||
|
HeatingProgram.REDUCED_HEATING
|
||||||
|
),
|
||||||
|
max_value_getter=lambda api: api.getProgramMaxTemperature(
|
||||||
|
HeatingProgram.REDUCED_HEATING
|
||||||
|
),
|
||||||
|
stepping_getter=lambda api: api.getProgramStepping(
|
||||||
|
HeatingProgram.REDUCED_HEATING
|
||||||
|
),
|
||||||
|
),
|
||||||
|
ViCareNumberEntityDescription(
|
||||||
|
key="comfort_heating_temperature",
|
||||||
|
translation_key="comfort_heating_temperature",
|
||||||
|
entity_category=EntityCategory.CONFIG,
|
||||||
|
device_class=NumberDeviceClass.TEMPERATURE,
|
||||||
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
|
value_getter=lambda api: api.getDesiredTemperatureForProgram(
|
||||||
|
HeatingProgram.COMFORT_HEATING
|
||||||
|
),
|
||||||
|
value_setter=lambda api, value: api.setProgramTemperature(
|
||||||
|
HeatingProgram.COMFORT_HEATING, value
|
||||||
|
),
|
||||||
|
min_value_getter=lambda api: api.getProgramMinTemperature(
|
||||||
|
HeatingProgram.COMFORT_HEATING
|
||||||
|
),
|
||||||
|
max_value_getter=lambda api: api.getProgramMaxTemperature(
|
||||||
|
HeatingProgram.COMFORT_HEATING
|
||||||
|
),
|
||||||
|
stepping_getter=lambda api: api.getProgramStepping(
|
||||||
|
HeatingProgram.COMFORT_HEATING
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -80,6 +80,15 @@
|
|||||||
},
|
},
|
||||||
"comfort_temperature": {
|
"comfort_temperature": {
|
||||||
"name": "Comfort temperature"
|
"name": "Comfort temperature"
|
||||||
|
},
|
||||||
|
"normal_heating_temperature": {
|
||||||
|
"name": "[%key:component::vicare::entity::number::normal_temperature::name%]"
|
||||||
|
},
|
||||||
|
"reduced_heating_temperature": {
|
||||||
|
"name": "[%key:component::vicare::entity::number::reduced_temperature::name%]"
|
||||||
|
},
|
||||||
|
"comfort_heating_temperature": {
|
||||||
|
"name": "[%key:component::vicare::entity::number::comfort_temperature::name%]"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sensor": {
|
"sensor": {
|
||||||
|
@ -1,12 +1,29 @@
|
|||||||
"""Types for the ViCare integration."""
|
"""Types for the ViCare integration."""
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
import enum
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from PyViCare.PyViCareDevice import Device as PyViCareDevice
|
from PyViCare.PyViCareDevice import Device as PyViCareDevice
|
||||||
from PyViCare.PyViCareDeviceConfig import PyViCareDeviceConfig
|
from PyViCare.PyViCareDeviceConfig import PyViCareDeviceConfig
|
||||||
|
|
||||||
|
|
||||||
|
class HeatingProgram(enum.StrEnum):
|
||||||
|
"""ViCare preset heating programs.
|
||||||
|
|
||||||
|
As listed in https://github.com/somm15/PyViCare/blob/63f9f7fea505fdf9a26c77c6cd0bff889abcdb05/PyViCare/PyViCareHeatingDevice.py#L606
|
||||||
|
"""
|
||||||
|
|
||||||
|
COMFORT = "comfort"
|
||||||
|
COMFORT_HEATING = "comfortHeating"
|
||||||
|
ECO = "eco"
|
||||||
|
NORMAL = "normal"
|
||||||
|
NORMAL_HEATING = "normalHeating"
|
||||||
|
REDUCED = "reduced"
|
||||||
|
REDUCED_HEATING = "reducedHeating"
|
||||||
|
STANDBY = "standby"
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class ViCareDevice:
|
class ViCareDevice:
|
||||||
"""Dataclass holding the device api and config."""
|
"""Dataclass holding the device api and config."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user