diff --git a/custom_components/adaptive_lighting/services.yaml b/custom_components/adaptive_lighting/services.yaml old mode 100755 new mode 100644 index 89c112e3..351fe5b5 --- a/custom_components/adaptive_lighting/services.yaml +++ b/custom_components/adaptive_lighting/services.yaml @@ -3,7 +3,6 @@ apply: fields: entity_id: description: "Entity ID of the switch. \U0001F4DD" - example: switch.adaptive_lighting_default selector: entity: integration: adaptive_lighting @@ -11,7 +10,6 @@ apply: multiple: false lights: description: "List of light entities to be controlled by Adaptive Lighting (may be empty). \U0001F31F" - example: light.bedroom_ceiling selector: entity: domain: light @@ -46,7 +44,6 @@ set_manual_control: fields: entity_id: description: "Entity ID of the switch. \U0001F4DD" - example: switch.adaptive_lighting_default selector: entity: integration: adaptive_lighting @@ -54,7 +51,6 @@ set_manual_control: multiple: false lights: description: "List of light entities to be controlled by Adaptive Lighting (may be empty). \U0001F31F" - example: light.bedroom_ceiling selector: entity: domain: light diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 3e1c86db..4b9e1856 100644 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -582,7 +582,7 @@ def _expand_light_groups(hass: HomeAssistant, lights: list[str]) -> list[str]: def _supported_features(hass: HomeAssistant, light: str): state = hass.states.get(light) - supported_features = state.attributes[ATTR_SUPPORTED_FEATURES] + supported_features = state.attributes.get(ATTR_SUPPORTED_FEATURES, 0) supported = { key for key, value in _SUPPORT_OPTS.items() if supported_features & value } @@ -1017,7 +1017,8 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): if prefer_rgb_color is None: prefer_rgb_color = self._prefer_rgb_color - if "transition" in features: + # Check transition == 0 to fix #378 + if "transition" in features and transition > 0: service_data[ATTR_TRANSITION] = transition # The switch might be off and not have _settings set. @@ -1064,7 +1065,18 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): ) ): return - self.turn_on_off_listener.last_service_data[light] = service_data + # See #80. Doesn't check if transitions differ but it does the job. + last_service_data = self.turn_on_off_listener.last_service_data + if light in last_service_data and last_service_data[light] == service_data: + _LOGGER.debug( + "%s: Cancelling adapt to light %s, there's no new values to set (context.id='%s')", + self._name, + light, + context.id, + ) + return + else: + self.turn_on_off_listener.last_service_data[light] = service_data async def turn_on(service_data): _LOGGER.debug( @@ -1489,11 +1501,14 @@ class SunLightSettings: rgb_color: tuple[float, float, float] = color_temperature_to_rgb( color_temp_kelvin ) + # backwards compatibility for versions < 1.3.1 - see #403 + color_temp_mired: float = math.floor(1000000 / color_temp_kelvin) xy_color: tuple[float, float] = color_RGB_to_xy(*rgb_color) hs_color: tuple[float, float] = color_xy_to_hs(*xy_color) return { "brightness_pct": brightness_pct, "color_temp_kelvin": color_temp_kelvin, + "color_temp_mired": color_temp_mired, "rgb_color": rgb_color, "xy_color": xy_color, "hs_color": hs_color, diff --git a/tests/test_switch.py b/tests/test_switch.py index 5b74c94c..212cea82 100644 --- a/tests/test_switch.py +++ b/tests/test_switch.py @@ -527,11 +527,18 @@ async def test_manual_control(hass): await turn_switch(True, entity_id) assert not manual_control[ENTITY_LIGHT] + # Check that manual control is still enabled if set while bulb is off. + # Test issue #37 + await turn_light(False) + await change_manual_control(True) + await turn_light(True) + assert manual_control[ENTITY_LIGHT] + # Check that when 'adapt_brightness' is off, changing the brightness # doesn't mark it as manually controlled but changing color_temp # does - await turn_light(False) # reset manually controlled status - await turn_light(True) + await turn_light(False) + await turn_light(True) # reset manually controlled status assert not manual_control[ENTITY_LIGHT] await switch.adapt_brightness_switch.async_turn_off() await turn_light(True, brightness=increased_brightness())