From b1529bac16308e187559ec1195efaf6b292d80d6 Mon Sep 17 00:00:00 2001 From: MapoDan <42698485+MapoDan@users.noreply.github.com> Date: Thu, 28 Jan 2021 19:04:15 +0100 Subject: [PATCH] Update config_schema.py --- .../programmable_thermostat/config_schema.py | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/custom_components/programmable_thermostat/config_schema.py b/custom_components/programmable_thermostat/config_schema.py index c3eea2f..f9cb384 100755 --- a/custom_components/programmable_thermostat/config_schema.py +++ b/custom_components/programmable_thermostat/config_schema.py @@ -2,7 +2,8 @@ import logging import homeassistant.helpers.config_validation as cv from homeassistant.components.climate.const import ( - SUPPORT_TARGET_TEMPERATURE) + SUPPORT_TARGET_TEMPERATURE +) from homeassistant.const import CONF_NAME, CONF_ENTITIES from .const import ( DOMAIN, @@ -15,7 +16,10 @@ DEFAULT_MIN_CYCLE_DURATION, MAX_HVAC_OPTIONS, AUTO_MODE_OPTIONS, - INITIAL_HVAC_MODE_OPTIONS) + INITIAL_HVAC_MODE_OPTIONS, + INITIAL_HVAC_MODE_OPTIONS_OPTFLOW +) +from .helpers import dict_to_string _LOGGER = logging.getLogger(__name__) @@ -74,19 +78,38 @@ def get_config_flow_schema(config: dict = {}, config_flow_step: int = 0) -> dict vol.Required(CONF_SENSOR, default=config.get(CONF_SENSOR)): str, vol.Required(CONF_TARGET, default=config.get(CONF_TARGET)): str } + elif config_flow_step==4: + #identical to step 1 but without NAME (better to not change it since it will break configuration) + #this is used for options flow only + return { + vol.Optional(CONF_HEATER, default=config.get(CONF_HEATER)): str, + vol.Optional(CONF_COOLER, default=config.get(CONF_COOLER)): str, + vol.Required(CONF_SENSOR, default=config.get(CONF_SENSOR)): str, + vol.Required(CONF_TARGET, default=config.get(CONF_TARGET)): str + } elif config_flow_step==2: return { - vol.Optional(CONF_MAX_TEMP, default=config.get(CONF_MAX_TEMP)): int, - vol.Optional(CONF_MIN_TEMP, default=config.get(CONF_MIN_TEMP)): int, - vol.Optional(CONF_TOLERANCE, default=config.get(CONF_TOLERANCE)): float + vol.Required(CONF_MAX_TEMP, default=config.get(CONF_MAX_TEMP)): int, + vol.Required(CONF_MIN_TEMP, default=config.get(CONF_MIN_TEMP)): int, + vol.Required(CONF_TOLERANCE, default=config.get(CONF_TOLERANCE)): float } elif config_flow_step==3: return { vol.Optional(CONF_RELATED_CLIMATE, default=config.get(CONF_RELATED_CLIMATE)): str, - vol.Optional(CONF_HVAC_OPTIONS, default=config.get(CONF_HVAC_OPTIONS)): vol.In(range(MAX_HVAC_OPTIONS)), - vol.Optional(CONF_AUTO_MODE, default=config.get(CONF_AUTO_MODE)): vol.In(AUTO_MODE_OPTIONS), + vol.Required(CONF_HVAC_OPTIONS, default=config.get(CONF_HVAC_OPTIONS)): vol.In(range(MAX_HVAC_OPTIONS)), + vol.Required(CONF_AUTO_MODE, default=config.get(CONF_AUTO_MODE)): vol.In(AUTO_MODE_OPTIONS), vol.Optional(CONF_INITIAL_HVAC_MODE, default=config.get(CONF_INITIAL_HVAC_MODE)): vol.In(INITIAL_HVAC_MODE_OPTIONS), vol.Optional(CONF_MIN_CYCLE_DURATION, default=config.get(CONF_MIN_CYCLE_DURATION)): str } + elif config_flow_step==5: + #identical to 3 but with CONF_MIN_CYCLE_DURATION converted in string from dict (necessary since it is always set as null if not used) + #this is used for options flow only + return { + vol.Optional(CONF_RELATED_CLIMATE, default=config.get(CONF_RELATED_CLIMATE)): str, + vol.Required(CONF_HVAC_OPTIONS, default=config.get(CONF_HVAC_OPTIONS)): vol.In(range(MAX_HVAC_OPTIONS)), + vol.Required(CONF_AUTO_MODE, default=config.get(CONF_AUTO_MODE)): vol.In(AUTO_MODE_OPTIONS), + vol.Optional(CONF_INITIAL_HVAC_MODE, default=config.get(CONF_INITIAL_HVAC_MODE)): vol.In(INITIAL_HVAC_MODE_OPTIONS_OPTFLOW), + vol.Optional(CONF_MIN_CYCLE_DURATION, default=dict_to_string(config.get(CONF_MIN_CYCLE_DURATION))): str + } return {}