From ec558e5616dd659ed30915643f4f55ea3896fe87 Mon Sep 17 00:00:00 2001 From: Benjamin Auquite Date: Sat, 1 Apr 2023 18:35:01 -0500 Subject: [PATCH] Move `include_config_in_attributes` --- custom_components/adaptive_lighting/switch.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index ef8b42aa..c94ab32a 100644 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -771,16 +771,6 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): # Set in self._update_attrs_and_maybe_adapt_lights self._settings: dict[str, Any] = {} - self._config: dict[str, Any] = {} - if self._include_config_in_attributes: - attrdata = deepcopy(data) - for k, v in attrdata.items(): - if isinstance(v, (datetime.date, datetime.datetime)): - attrdata[k] = v.isoformat() - if isinstance(v, (datetime.timedelta)): - attrdata[k] = v.total_seconds() - self._config.update(attrdata) - # Set and unset tracker in async_turn_on and async_turn_off self.remove_listeners = [] _LOGGER.debug( @@ -811,6 +801,16 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): self._detect_non_ha_changes = data[CONF_DETECT_NON_HA_CHANGES] self._include_config_in_attributes = data[CONF_INCLUDE_CONFIG_IN_ATTRIBUTES] + self._config: dict[str, Any] = {} + if self._include_config_in_attributes: + attrdata = deepcopy(data) + for k, v in attrdata.items(): + if isinstance(v, (datetime.date, datetime.datetime)): + attrdata[k] = v.isoformat() + if isinstance(v, (datetime.timedelta)): + attrdata[k] = v.total_seconds() + self._config.update(attrdata) + self._initial_transition = data[CONF_INITIAL_TRANSITION] self._sleep_transition = data[CONF_SLEEP_TRANSITION] self._only_once = data[CONF_ONLY_ONCE]