mirror of
https://github.com/basnijholt/adaptive-lighting.git
synced 2026-09-11 22:34:04 +02:00
Compare commits
42 commits
main
...
reformat_a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
317ae3af13 | ||
|
|
96a28072f6 | ||
|
|
b9273d2d06 | ||
|
|
29eecc4698 |
||
|
|
b36b17ac03 | ||
|
|
11b268148b | ||
|
|
441cb1ff5c | ||
|
|
8afd13e8f4 |
||
|
|
331f485ef9 | ||
|
|
99473406ea |
||
|
|
8285564015 | ||
|
|
20854f1dc0 | ||
|
|
c3c0eaac2e | ||
|
|
5da2c85fea | ||
|
|
21f8beac8d | ||
|
|
9c8d322135 | ||
|
|
4b605706ef |
||
|
|
46d5563697 | ||
|
|
5524c75b42 | ||
|
|
4479761ad7 | ||
|
|
2f0bad82ff | ||
|
|
6b2fbf7c9b | ||
|
|
cebf31a203 | ||
|
|
6e9fb0cc0d | ||
|
|
f453968258 | ||
|
|
b221eed1a0 | ||
|
|
836595051d | ||
|
|
2a4acde1c0 | ||
|
|
3aa2f3242b | ||
|
|
732fc17c7f | ||
|
|
a6641d0daf | ||
|
|
9eb56463ec | ||
|
|
1571dfaeda | ||
|
|
120efff71e | ||
|
|
30c62bf759 | ||
|
|
8e847e71eb | ||
|
|
ad04e39d4e | ||
|
|
85eb85cab6 | ||
|
|
22bae9ed84 | ||
|
|
8b2fcf93be | ||
|
|
d7aecc9e7f |
||
|
|
52275bfee3 |
3 changed files with 52 additions and 42 deletions
0
custom_components/adaptive_lighting/services.yaml
Normal file → Executable file
0
custom_components/adaptive_lighting/services.yaml
Normal file → Executable file
|
|
@ -424,6 +424,7 @@ def _fire_manual_control_event(
|
|||
switch.entity_id,
|
||||
light,
|
||||
)
|
||||
switch.turn_on_off_listener.mark_as_manual_control(light)
|
||||
fire(
|
||||
f"{DOMAIN}.manual_control",
|
||||
{ATTR_ENTITY_ID: light, SWITCH_DOMAIN: switch.entity_id},
|
||||
|
|
@ -519,7 +520,6 @@ async def async_setup_entry(
|
|||
all_lights = _expand_light_groups(switch.hass, lights)
|
||||
if service_call.data[CONF_MANUAL_CONTROL]:
|
||||
for light in all_lights:
|
||||
switch.turn_on_off_listener.mark_as_manual_control(light)
|
||||
_fire_manual_control_event(switch, light, service_call.context)
|
||||
else:
|
||||
switch.turn_on_off_listener.reset(*all_lights)
|
||||
|
|
@ -1088,9 +1088,6 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
|
|||
if lock is not None and lock.locked():
|
||||
_LOGGER.debug("%s: '%s' is locked", self._name, light)
|
||||
return
|
||||
service_data = {ATTR_ENTITY_ID: light}
|
||||
features = _supported_features(self.hass, light)
|
||||
|
||||
if transition is None:
|
||||
transition = self._transition
|
||||
if adapt_brightness is None:
|
||||
|
|
@ -1100,15 +1097,18 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
|
|||
if prefer_rgb_color is None:
|
||||
prefer_rgb_color = self._prefer_rgb_color
|
||||
|
||||
# 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.
|
||||
self._settings = self._sun_light_settings.get_settings(
|
||||
self.sleep_mode_switch.is_on, transition
|
||||
)
|
||||
|
||||
# Build service data.
|
||||
service_data = {ATTR_ENTITY_ID: light}
|
||||
features = _supported_features(self.hass, light)
|
||||
|
||||
# Check transition == 0 to fix #378
|
||||
if "transition" in features and transition > 0:
|
||||
service_data[ATTR_TRANSITION] = transition
|
||||
if "brightness" in features and adapt_brightness:
|
||||
brightness = round(255 * self._settings["brightness_pct"] / 100)
|
||||
service_data[ATTR_BRIGHTNESS] = brightness
|
||||
|
|
@ -1135,19 +1135,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
|
|||
service_data[ATTR_RGB_COLOR] = self._settings["rgb_color"]
|
||||
|
||||
context = context or self.create_context("adapt_lights")
|
||||
if (
|
||||
self._take_over_control
|
||||
and self._detect_non_ha_changes
|
||||
and not force
|
||||
and await self.turn_on_off_listener.significant_change(
|
||||
self,
|
||||
light,
|
||||
adapt_brightness,
|
||||
adapt_color,
|
||||
context,
|
||||
)
|
||||
):
|
||||
return
|
||||
|
||||
# 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 not force and last_service_data.get(light) == service_data:
|
||||
|
|
@ -1236,9 +1224,11 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
|
|||
if not filtered_lights:
|
||||
return
|
||||
|
||||
await self._adapt_lights(filtered_lights, transition, force, context)
|
||||
await self._update_manual_control_and_maybe_adapt(
|
||||
filtered_lights, transition, force, context
|
||||
)
|
||||
|
||||
async def _adapt_lights(
|
||||
async def _update_manual_control_and_maybe_adapt(
|
||||
self,
|
||||
lights: list[str],
|
||||
transition: int | None,
|
||||
|
|
@ -1247,33 +1237,53 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
|
|||
) -> None:
|
||||
assert context is not None
|
||||
_LOGGER.debug(
|
||||
"%s: '_adapt_lights(%s, %s, force=%s, context.id=%s)' called",
|
||||
"%s: '_update_manual_control_and_maybe_adapt(%s, %s, force=%s, context.id=%s)' called",
|
||||
self.name,
|
||||
lights,
|
||||
transition,
|
||||
force,
|
||||
context.id,
|
||||
)
|
||||
|
||||
adapt_brightness = self.adapt_brightness_switch.is_on
|
||||
adapt_color = self.adapt_color_switch.is_on
|
||||
|
||||
for light in lights:
|
||||
if not is_on(self.hass, light):
|
||||
continue
|
||||
if (
|
||||
self._take_over_control
|
||||
and self.turn_on_off_listener.is_manually_controlled(
|
||||
|
||||
manually_controlled = self.turn_on_off_listener.is_manually_controlled(
|
||||
self,
|
||||
light,
|
||||
force,
|
||||
adapt_brightness,
|
||||
adapt_color,
|
||||
)
|
||||
|
||||
significant_change = (
|
||||
self._detect_non_ha_changes
|
||||
and not force
|
||||
and await self.turn_on_off_listener.significant_change(
|
||||
self,
|
||||
light,
|
||||
force,
|
||||
self.adapt_brightness_switch.is_on,
|
||||
self.adapt_color_switch.is_on,
|
||||
)
|
||||
):
|
||||
_LOGGER.debug(
|
||||
"%s: '%s' is being manually controlled, stop adapting, context.id=%s.",
|
||||
self._name,
|
||||
light,
|
||||
context.id,
|
||||
adapt_brightness,
|
||||
adapt_color,
|
||||
context,
|
||||
)
|
||||
)
|
||||
|
||||
if self._take_over_control and (manually_controlled or significant_change):
|
||||
if manually_controlled:
|
||||
_LOGGER.debug(
|
||||
"%s: '%s' is being manually controlled, stop adapting, context.id=%s.",
|
||||
self._name,
|
||||
light,
|
||||
context.id,
|
||||
)
|
||||
else:
|
||||
_fire_manual_control_event(self, light, context)
|
||||
continue
|
||||
|
||||
await self._adapt_light(light, transition, force=force, context=context)
|
||||
|
||||
async def _sleep_mode_switch_state_event(self, event: Event) -> None:
|
||||
|
|
@ -1900,7 +1910,7 @@ class TurnOnOffListener:
|
|||
):
|
||||
# Light was already on and 'light.turn_on' was not called by
|
||||
# the adaptive_lighting integration.
|
||||
manual_control = self.mark_as_manual_control(light)
|
||||
manual_control = True
|
||||
_fire_manual_control_event(switch, light, turn_on_event.context)
|
||||
_LOGGER.debug(
|
||||
"'%s' was already on and 'light.turn_on' was not called by the"
|
||||
|
|
@ -1968,8 +1978,6 @@ class TurnOnOffListener:
|
|||
light,
|
||||
context.id,
|
||||
)
|
||||
self.mark_as_manual_control(light)
|
||||
_fire_manual_control_event(switch, light, context, is_async=False)
|
||||
return True
|
||||
_LOGGER.debug(
|
||||
"%s: Light '%s' correctly matches our last adapt's service data, continuing..."
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ from homeassistant.components.adaptive_lighting.const import (
|
|||
CONF_SUNRISE_OFFSET,
|
||||
CONF_SUNRISE_TIME,
|
||||
CONF_SUNSET_TIME,
|
||||
CONF_TAKE_OVER_CONTROL,
|
||||
CONF_TRANSITION,
|
||||
CONF_TURN_ON_LIGHTS,
|
||||
CONF_USE_DEFAULTS,
|
||||
|
|
@ -212,7 +213,8 @@ async def setup_lights_and_switch(hass, extra_conf=None):
|
|||
CONF_SUNSET_TIME: datetime.time(SUNSET.hour),
|
||||
CONF_INITIAL_TRANSITION: 0,
|
||||
CONF_TRANSITION: 0,
|
||||
CONF_DETECT_NON_HA_CHANGES: True,
|
||||
CONF_DETECT_NON_HA_CHANGES: False,
|
||||
CONF_TAKE_OVER_CONTROL: True,
|
||||
CONF_PREFER_RGB_COLOR: False,
|
||||
CONF_MIN_COLOR_TEMP: 2500, # to not coincide with sleep_color_temp
|
||||
**(extra_conf or {}),
|
||||
|
|
@ -666,7 +668,7 @@ async def test_manual_control(hass):
|
|||
@pytest.mark.dependency(depends=[*GLOBAL_TEST_DEPENDENCIES, "test_manual_control"])
|
||||
async def test_auto_reset_manual_control(hass):
|
||||
switch, (light, *_) = await setup_lights_and_switch(
|
||||
hass, {CONF_AUTORESET_CONTROL: 0.1}
|
||||
hass, {CONF_AUTORESET_CONTROL: 0.2}
|
||||
)
|
||||
context = switch.create_context("test") # needs to be passed to update method
|
||||
manual_control = switch.turn_on_off_listener.manual_control
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue