Issue #281 - cannot use central config at first integration installation

This commit is contained in:
Jean-Marc Collin
2023-12-18 20:54:39 +00:00
parent efb8ce257d
commit 30c3418f1b
2 changed files with 14 additions and 11 deletions

View File

@@ -86,7 +86,10 @@ class VersatileThermostatBaseConfigFlow(FlowHandler):
# VTherm API should have been initialized before arriving here # VTherm API should have been initialized before arriving here
vtherm_api = VersatileThermostatAPI.get_vtherm_api() vtherm_api = VersatileThermostatAPI.get_vtherm_api()
if vtherm_api is not None:
self._central_config = vtherm_api.find_central_configuration() self._central_config = vtherm_api.find_central_configuration()
else:
self._central_config = None
self._init_feature_flags(infos) self._init_feature_flags(infos)
self._init_central_config_flags(infos) self._init_central_config_flags(infos)

View File

@@ -19,26 +19,27 @@ _LOGGER = logging.getLogger(__name__)
class VersatileThermostatAPI(dict): class VersatileThermostatAPI(dict):
"""The VersatileThermostatAPI""" """The VersatileThermostatAPI"""
_hass: HomeAssistant _hass: HomeAssistant = None
# _entries: Dict(str, ConfigEntry) # _entries: Dict(str, ConfigEntry)
@classmethod @classmethod
def get_vtherm_api(cls, hass=None): def get_vtherm_api(cls, hass=None):
"""Get the eventual VTherm API class instance""" """Get the eventual VTherm API class instance or
instantiate it if it doesn't exists"""
if hass is not None: if hass is not None:
VersatileThermostatAPI._hass = hass VersatileThermostatAPI._hass = hass
else:
if VersatileThermostatAPI._hass is None: if VersatileThermostatAPI._hass is None:
return None return None
domain = VersatileThermostatAPI._hass.data.get(DOMAIN) domain = VersatileThermostatAPI._hass.data.get(DOMAIN)
if not domain: if not domain:
hass.data.setdefault(DOMAIN, {}) VersatileThermostatAPI._hass.data.setdefault(DOMAIN, {})
ret = VersatileThermostatAPI._hass.data.get(DOMAIN).get(VTHERM_API_NAME) ret = VersatileThermostatAPI._hass.data.get(DOMAIN).get(VTHERM_API_NAME)
if ret is None: if ret is None:
ret = VersatileThermostatAPI() ret = VersatileThermostatAPI()
hass.data[DOMAIN][VTHERM_API_NAME] = ret VersatileThermostatAPI._hass.data[DOMAIN][VTHERM_API_NAME] = ret
return ret return ret
def __init__(self) -> None: def __init__(self) -> None:
@@ -46,7 +47,6 @@ class VersatileThermostatAPI(dict):
super().__init__() super().__init__()
self._expert_params = None self._expert_params = None
self._short_ema_params = None self._short_ema_params = None
self._central_config = None
def find_central_configuration(self): def find_central_configuration(self):
"""Search for a central configuration""" """Search for a central configuration"""
@@ -57,8 +57,8 @@ class VersatileThermostatAPI(dict):
config_entry.data.get(CONF_THERMOSTAT_TYPE) config_entry.data.get(CONF_THERMOSTAT_TYPE)
== CONF_THERMOSTAT_CENTRAL_CONFIG == CONF_THERMOSTAT_CENTRAL_CONFIG
): ):
self._central_config = config_entry central_config = config_entry
return self._central_config return central_config
return None return None
def add_entry(self, entry: ConfigEntry): def add_entry(self, entry: ConfigEntry):