Increase setMode flexibility (#58491)

This commit is contained in:
Hans Oischinger 2021-10-27 14:22:16 +02:00 committed by GitHub
parent 8e8ccb7ce4
commit e656974e8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -24,6 +24,7 @@ from homeassistant.components.climate.const import (
)
from homeassistant.const import ATTR_TEMPERATURE, PRECISION_WHOLE, TEMP_CELSIUS
from homeassistant.helpers import entity_platform
import homeassistant.helpers.config_validation as cv
from .const import (
CONF_HEATING_TYPE,
@ -129,11 +130,7 @@ async def async_setup_platform(
platform.async_register_entity_service(
SERVICE_SET_VICARE_MODE,
{
vol.Required(SERVICE_SET_VICARE_MODE_ATTR_MODE): vol.In(
VICARE_TO_HA_HVAC_HEATING
)
},
{vol.Required(SERVICE_SET_VICARE_MODE_ATTR_MODE): cv.string},
"set_vicare_mode",
)
@ -215,6 +212,8 @@ class ViCareClimate(ClimateEntity):
"heating_curve_shift"
] = self._circuit.getHeatingCurveShift()
self._attributes["vicare_modes"] = self._circuit.getModes()
self._current_action = False
# Update the specific device attributes
with suppress(PyViCareNotSupportedFeatureError):
@ -339,7 +338,7 @@ class ViCareClimate(ClimateEntity):
def set_vicare_mode(self, vicare_mode):
"""Service function to set vicare modes directly."""
if vicare_mode not in VICARE_TO_HA_HVAC_HEATING:
raise ValueError(f"Cannot set invalid vicare mode: {vicare_mode}")
if vicare_mode not in self._attributes["vicare_modes"]:
raise ValueError(f"Cannot set invalid vicare mode: {vicare_mode}.")
self._circuit.setMode(vicare_mode)