From 45faa3fcc5bf41a913b142ff7f5606efbf5b9cec Mon Sep 17 00:00:00 2001 From: rgc99 Date: Sat, 21 Oct 2023 22:14:06 +0000 Subject: [PATCH] Consolidate and fix switch config load --- .../irrigation_unlimited.py | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/custom_components/irrigation_unlimited/irrigation_unlimited.py b/custom_components/irrigation_unlimited/irrigation_unlimited.py index 987d802..8874d2d 100644 --- a/custom_components/irrigation_unlimited/irrigation_unlimited.py +++ b/custom_components/irrigation_unlimited/irrigation_unlimited.py @@ -1400,25 +1400,25 @@ def clear(self) -> None: def load(self, config: OrderedDict, all_zones: OrderedDict) -> "IUSwitch": """Load switch data from the configuration""" + + def load_params(config: OrderedDict) -> None: + if config is None: + return + self._check_back_states = config.get(CONF_STATES, self._check_back_states) + self._check_back_retries = config.get( + CONF_RETRIES, self._check_back_retries + ) + self._check_back_resync = config.get(CONF_RESYNC, self._check_back_resync) + self._state_on = config.get(CONF_STATE_ON, self._state_on) + self._state_off = config.get(CONF_STATE_OFF, self._state_off) + delay = config.get(CONF_DELAY, self._check_back_delay.total_seconds()) + self._check_back_delay = wash_td(timedelta(seconds=delay)) + self.clear() - delay = self._check_back_delay.total_seconds() - if all_zones is not None and CONF_CHECK_BACK in all_zones: - cfg: dict = all_zones[CONF_CHECK_BACK] - self._check_back_states = cfg.get(CONF_STATES, self._check_back_states) - self._check_back_retries = cfg.get(CONF_RETRIES, self._check_back_retries) - self._check_back_resync = cfg.get(CONF_RESYNC, self._check_back_resync) - self._state_on = cfg.get(CONF_STATE_ON, self._state_on) - self._state_off = cfg.get(CONF_STATE_OFF, self._state_off) - delay = cfg.get(CONF_DELAY, delay) self._switch_entity_id = config.get(CONF_ENTITY_ID) - self._check_back_states = config.get(CONF_STATES, self._check_back_states) - self._check_back_retries = config.get(CONF_RETRIES, self._check_back_retries) - self._check_back_resync = config.get(CONF_RESYNC, self._check_back_resync) - self._state_on = config.get(CONF_STATE_ON, self._state_on) - self._state_off = config.get(CONF_STATE_OFF, self._state_off) - - delay = config.get(CONF_DELAY, delay) - self._check_back_delay = wash_td(timedelta(seconds=delay)) + if all_zones is not None: + load_params(all_zones.get(CONF_CHECK_BACK)) + load_params(config.get(CONF_CHECK_BACK)) return self def muster(self, stime: datetime) -> int: