From dce2a35147e3f9c0cba7f47ca4d5c1bfd85f20c2 Mon Sep 17 00:00:00 2001 From: Kyle Bjordahl <3489222+kylebjordahl@users.noreply.github.com> Date: Sun, 19 Nov 2023 17:21:05 -0800 Subject: [PATCH] Protect for None attributes after HA core change (#846) --- custom_components/adaptive_lighting/switch.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 7e910525..9aec8ba1 100644 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -710,6 +710,10 @@ def _attributes_have_changed( adapt_color: bool, context: Context, ) -> bool: + # 2023-11-19: HA core no longer removes light domain attributes when off + # so we must protect for `None` here + # see https://github.com/home-assistant/core/pull/101946 + if adapt_color: old_attributes, new_attributes = _add_missing_attributes( old_attributes, @@ -718,8 +722,8 @@ def _attributes_have_changed( if ( adapt_brightness - and ATTR_BRIGHTNESS in old_attributes - and ATTR_BRIGHTNESS in new_attributes + and old_attributes.get(ATTR_BRIGHTNESS) + and new_attributes.get(ATTR_BRIGHTNESS) ): last_brightness = old_attributes[ATTR_BRIGHTNESS] current_brightness = new_attributes[ATTR_BRIGHTNESS] @@ -736,8 +740,8 @@ def _attributes_have_changed( if ( adapt_color - and ATTR_COLOR_TEMP_KELVIN in old_attributes - and ATTR_COLOR_TEMP_KELVIN in new_attributes + and old_attributes.get(ATTR_COLOR_TEMP_KELVIN) + and new_attributes.get(ATTR_COLOR_TEMP_KELVIN) ): last_color_temp = old_attributes[ATTR_COLOR_TEMP_KELVIN] current_color_temp = new_attributes[ATTR_COLOR_TEMP_KELVIN] @@ -754,8 +758,8 @@ def _attributes_have_changed( if ( adapt_color - and ATTR_RGB_COLOR in old_attributes - and ATTR_RGB_COLOR in new_attributes + and old_attributes.get(ATTR_RGB_COLOR) + and new_attributes.get(ATTR_RGB_COLOR) ): last_rgb_color = old_attributes[ATTR_RGB_COLOR] current_rgb_color = new_attributes[ATTR_RGB_COLOR]