From cc90c512555977dcd204d4c1a06d5e5ee1304b25 Mon Sep 17 00:00:00 2001 From: Simon Gurcke Date: Sat, 13 Nov 2021 23:49:03 +1000 Subject: [PATCH] Fix default lights for adaptive_lighting.apply service --- custom_components/adaptive_lighting/switch.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 6c9cd7d6..c07f8b5c 100755 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -222,9 +222,15 @@ async def handle_apply(switch: AdaptiveSwitch, service_call: ServiceCall): """Handle the entity service apply.""" hass = switch.hass data = service_call.data - all_lights = _expand_light_groups(hass, data[CONF_LIGHTS]) + all_lights = data[CONF_LIGHTS] + if not all_lights: + all_lights = switch._lights + all_lights = _expand_light_groups(hass, all_lights) switch.turn_on_off_listener.lights.update(all_lights) - + _LOGGER.debug( + "Called 'adaptive_lighting.apply' service with '%s'", + data, + ) for light in all_lights: if data[CONF_TURN_ON_LIGHTS] or is_on(hass, light): await switch._adapt_light( # pylint: disable=protected-access @@ -322,7 +328,7 @@ async def async_setup_entry( platform.async_register_entity_service( SERVICE_APPLY, { - vol.Optional(CONF_LIGHTS, default=switch._lights): cv.entity_ids, # pylint: disable=protected-access + vol.Optional(CONF_LIGHTS, default=[]): cv.entity_ids, # pylint: disable=protected-access vol.Optional( CONF_TRANSITION, default=switch._initial_transition, # pylint: disable=protected-access