diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index d6ca514e..f9a932d5 100644 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -1854,7 +1854,7 @@ class AdaptiveLightingManager: is_already_on = self.hass.states.is_state(entity_id, STATE_ON) is_manually_controlled = self.get_manual_control_attributes( entity_id, - ).has_any() + ).has_all() if ( not switch.is_on @@ -1871,6 +1871,9 @@ class AdaptiveLightingManager: entity_id, data[CONF_PARAMS], ) + # Skip adaptation only if all attributes are manually controlled, otherwise + # we have to assume that some attribute(s) need adaptation. + and self.get_manual_control_attributes(entity_id).has_all() ) ): _LOGGER.debug( @@ -2082,7 +2085,8 @@ class AdaptiveLightingManager: data: ServiceData, ): _LOGGER.debug( - "Intercepted TURN_ON call with data %s (%s)", + "%s: Intercepted TURN_ON call with data %s (%s)", + entity_ids, data, call.context.id, ) @@ -2117,6 +2121,7 @@ class AdaptiveLightingManager: # lack of a bijective mapping.) preprocess_turn_on_alternatives(self.hass, first_service_data) data[CONF_PARAMS].update(first_service_data) + switch.manager.last_service_data[entity_ids[0]] = first_service_data # Schedule additional service calls for the remaining adaptation data. # We cannot know here whether there is another call to follow (since the diff --git a/tests/test_switch.py b/tests/test_switch.py index c0891823..774b4dd3 100644 --- a/tests/test_switch.py +++ b/tests/test_switch.py @@ -20,6 +20,7 @@ from homeassistant.components.adaptive_lighting.adaptation_utils import ( AdaptationData, LightControlAttributes, _create_service_call_data_iterator, + has_color_attribute, ) from homeassistant.components.adaptive_lighting.color_and_brightness import ( lerp_color_hsv, @@ -2947,7 +2948,7 @@ async def test_adapt_only_on_bare_turn_on_respects_pause_changed_mode(hass, inte "With PAUSE_CHANGED mode, color should still be adapted since only brightness " "was marked as manually controlled." ) - assert ATTR_COLOR_TEMP_KELVIN in last_service_data, ( + assert has_color_attribute(last_service_data), ( f"Bug: Color was not adapted. last_service_data={last_service_data}. " f"With take_over_control_mode=PAUSE_CHANGED and only brightness marked " f"as manually controlled, color_temp should still be adapted."