mirror of
https://github.com/basnijholt/adaptive-lighting.git
synced 2026-09-12 06:44:04 +02:00
Basic community fixes PR (#460)
* Fixes #423 #423 * Do not adapt lights turned on with custom payloads. * Update switch.py * Issue fixes #423, #378, #403, #449 * quickly test #274 * Revert feature requests, this branch only has fixes. Reverted FR 274 * pre-commit fix * Create automerge.yaml * test * Delete automerge.yaml My bad. * Fix #460 and #408 * see @basnijholt 's comment in #450. * @basnijholt requested changes. --------- Co-authored-by: Bas Nijholt <bas@nijho.lt>
This commit is contained in:
parent
87391e6d24
commit
c6a6cd323f
3 changed files with 27 additions and 9 deletions
4
custom_components/adaptive_lighting/services.yaml
Executable file → Normal file
4
custom_components/adaptive_lighting/services.yaml
Executable file → Normal file
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue