mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Handle preset change errors in ViCare integration (#103992)
This commit is contained in:
parent
706add4a57
commit
a5934e9acc
@ -34,6 +34,7 @@ from homeassistant.const import (
|
|||||||
UnitOfTemperature,
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.exceptions import ServiceValidationError
|
||||||
from homeassistant.helpers import entity_platform
|
from homeassistant.helpers import entity_platform
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
@ -292,22 +293,45 @@ class ViCareClimate(ViCareEntity, ClimateEntity):
|
|||||||
|
|
||||||
def set_preset_mode(self, preset_mode: str) -> None:
|
def set_preset_mode(self, preset_mode: str) -> None:
|
||||||
"""Set new preset mode and deactivate any existing programs."""
|
"""Set new preset mode and deactivate any existing programs."""
|
||||||
vicare_program = HA_TO_VICARE_PRESET_HEATING.get(preset_mode)
|
target_program = HA_TO_VICARE_PRESET_HEATING.get(preset_mode)
|
||||||
if vicare_program is None:
|
if target_program is None:
|
||||||
raise ValueError(
|
raise ServiceValidationError(
|
||||||
f"Cannot set invalid vicare program: {preset_mode}/{vicare_program}"
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="program_unknown",
|
||||||
|
translation_placeholders={
|
||||||
|
"preset": preset_mode,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
_LOGGER.debug("Setting preset to %s / %s", preset_mode, vicare_program)
|
_LOGGER.debug("Current preset %s", self._current_program)
|
||||||
if self._current_program != VICARE_PROGRAM_NORMAL:
|
if self._current_program and self._current_program != VICARE_PROGRAM_NORMAL:
|
||||||
# We can't deactivate "normal"
|
# We can't deactivate "normal"
|
||||||
|
_LOGGER.debug("deactivating %s", self._current_program)
|
||||||
try:
|
try:
|
||||||
self._circuit.deactivateProgram(self._current_program)
|
self._circuit.deactivateProgram(self._current_program)
|
||||||
except PyViCareCommandError:
|
except PyViCareCommandError as err:
|
||||||
_LOGGER.debug("Unable to deactivate program %s", self._current_program)
|
raise ServiceValidationError(
|
||||||
if vicare_program != VICARE_PROGRAM_NORMAL:
|
translation_domain=DOMAIN,
|
||||||
# And we can't explicitly activate normal, either
|
translation_key="program_not_deactivated",
|
||||||
self._circuit.activateProgram(vicare_program)
|
translation_placeholders={
|
||||||
|
"program": self._current_program,
|
||||||
|
},
|
||||||
|
) from err
|
||||||
|
|
||||||
|
_LOGGER.debug("Setting preset to %s / %s", preset_mode, target_program)
|
||||||
|
if target_program != VICARE_PROGRAM_NORMAL:
|
||||||
|
# And we can't explicitly activate "normal", either
|
||||||
|
_LOGGER.debug("activating %s", target_program)
|
||||||
|
try:
|
||||||
|
self._circuit.activateProgram(target_program)
|
||||||
|
except PyViCareCommandError as err:
|
||||||
|
raise ServiceValidationError(
|
||||||
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="program_not_activated",
|
||||||
|
translation_placeholders={
|
||||||
|
"program": target_program,
|
||||||
|
},
|
||||||
|
) from err
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self):
|
||||||
|
@ -288,6 +288,17 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"exceptions": {
|
||||||
|
"program_unknown": {
|
||||||
|
"message": "Cannot translate preset {preset} into a valid ViCare program"
|
||||||
|
},
|
||||||
|
"program_not_activated": {
|
||||||
|
"message": "Unable to activate ViCare program {program}"
|
||||||
|
},
|
||||||
|
"program_not_deactivated": {
|
||||||
|
"message": "Unable to deactivate ViCare program {program}"
|
||||||
|
}
|
||||||
|
},
|
||||||
"services": {
|
"services": {
|
||||||
"set_vicare_mode": {
|
"set_vicare_mode": {
|
||||||
"name": "Set ViCare mode",
|
"name": "Set ViCare mode",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user