From ad946cf9d260029ce5bd056c684c618a99fcd51c Mon Sep 17 00:00:00 2001 From: north3221 Date: Thu, 7 Apr 2022 23:23:07 +0100 Subject: [PATCH] Fix tado default overlay for when set pre new overlay feature (#69584) --- homeassistant/components/tado/__init__.py | 16 ++++++++++++++-- homeassistant/components/tado/config_flow.py | 13 +++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/tado/__init__.py b/homeassistant/components/tado/__init__.py index 9a5e1eb9c1e..0029dbf8c89 100644 --- a/homeassistant/components/tado/__init__.py +++ b/homeassistant/components/tado/__init__.py @@ -18,7 +18,10 @@ from homeassistant.util import Throttle from .const import ( CONF_FALLBACK, + CONST_OVERLAY_MANUAL, + CONST_OVERLAY_TADO_DEFAULT, CONST_OVERLAY_TADO_MODE, + CONST_OVERLAY_TADO_OPTIONS, DATA, DOMAIN, INSIDE_TEMPERATURE_MEASUREMENT, @@ -51,7 +54,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: username = entry.data[CONF_USERNAME] password = entry.data[CONF_PASSWORD] - fallback = entry.options.get(CONF_FALLBACK, CONST_OVERLAY_TADO_MODE) + fallback = entry.options.get(CONF_FALLBACK, CONST_OVERLAY_TADO_DEFAULT) tadoconnector = TadoConnector(hass, username, password, fallback) @@ -99,7 +102,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: def _async_import_options_from_data_if_missing(hass: HomeAssistant, entry: ConfigEntry): options = dict(entry.options) if CONF_FALLBACK not in options: - options[CONF_FALLBACK] = entry.data.get(CONF_FALLBACK, CONST_OVERLAY_TADO_MODE) + options[CONF_FALLBACK] = entry.data.get( + CONF_FALLBACK, CONST_OVERLAY_TADO_DEFAULT + ) + hass.config_entries.async_update_entry(entry, options=options) + + if options[CONF_FALLBACK] not in CONST_OVERLAY_TADO_OPTIONS: + if options[CONF_FALLBACK]: + options[CONF_FALLBACK] = CONST_OVERLAY_TADO_MODE + else: + options[CONF_FALLBACK] = CONST_OVERLAY_MANUAL hass.config_entries.async_update_entry(entry, options=options) diff --git a/homeassistant/components/tado/config_flow.py b/homeassistant/components/tado/config_flow.py index 95b415c5acc..a03b370d0a3 100644 --- a/homeassistant/components/tado/config_flow.py +++ b/homeassistant/components/tado/config_flow.py @@ -11,7 +11,13 @@ from homeassistant.const import CONF_PASSWORD, CONF_USERNAME from homeassistant.core import callback from homeassistant.data_entry_flow import FlowResult -from .const import CONF_FALLBACK, CONST_OVERLAY_TADO_OPTIONS, DOMAIN, UNIQUE_ID +from .const import ( + CONF_FALLBACK, + CONST_OVERLAY_TADO_DEFAULT, + CONST_OVERLAY_TADO_OPTIONS, + DOMAIN, + UNIQUE_ID, +) _LOGGER = logging.getLogger(__name__) @@ -126,7 +132,10 @@ class OptionsFlowHandler(config_entries.OptionsFlow): data_schema = vol.Schema( { vol.Optional( - CONF_FALLBACK, default=self.config_entry.options.get(CONF_FALLBACK) + CONF_FALLBACK, + default=self.config_entry.options.get( + CONF_FALLBACK, CONST_OVERLAY_TADO_DEFAULT + ), ): vol.In(CONST_OVERLAY_TADO_OPTIONS), } )