mirror of
https://github.com/basnijholt/adaptive-lighting.git
synced 2026-09-14 07:44:04 +02:00
squash merge alt_detect_method again
This commit is contained in:
parent
3c5ea73341
commit
784eed09b3
2 changed files with 96 additions and 49 deletions
|
|
@ -33,6 +33,12 @@ DOCS[CONF_DETECT_NON_HA_CHANGES] = (
|
||||||
"Requires `take_over_control`. 🕵️"
|
"Requires `take_over_control`. 🕵️"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
CONF_ALT_DETECT_METHOD, DEFAULT_ALT_DETECT_METHOD = "alt_detect_method", False
|
||||||
|
DOCS[CONF_ALT_DETECT_METHOD] = (
|
||||||
|
"alt_detect_method: When true, will check for any significant changes in the opposite direction"
|
||||||
|
" of where adaptive-lighting tried to adapt last."
|
||||||
|
" This is an alternative to 'detect_non_ha_changes' (default: false)"
|
||||||
|
)
|
||||||
CONF_INCLUDE_CONFIG_IN_ATTRIBUTES, DEFAULT_INCLUDE_CONFIG_IN_ATTRIBUTES = (
|
CONF_INCLUDE_CONFIG_IN_ATTRIBUTES, DEFAULT_INCLUDE_CONFIG_IN_ATTRIBUTES = (
|
||||||
"include_config_in_attributes",
|
"include_config_in_attributes",
|
||||||
False,
|
False,
|
||||||
|
|
@ -271,6 +277,7 @@ VALIDATION_TUPLES = [
|
||||||
(CONF_SUNSET_OFFSET, DEFAULT_SUNSET_OFFSET, int),
|
(CONF_SUNSET_OFFSET, DEFAULT_SUNSET_OFFSET, int),
|
||||||
(CONF_ONLY_ONCE, DEFAULT_ONLY_ONCE, bool),
|
(CONF_ONLY_ONCE, DEFAULT_ONLY_ONCE, bool),
|
||||||
(CONF_TAKE_OVER_CONTROL, DEFAULT_TAKE_OVER_CONTROL, bool),
|
(CONF_TAKE_OVER_CONTROL, DEFAULT_TAKE_OVER_CONTROL, bool),
|
||||||
|
(CONF_ALT_DETECT_METHOD, DEFAULT_ALT_DETECT_METHOD, bool),
|
||||||
(CONF_DETECT_NON_HA_CHANGES, DEFAULT_DETECT_NON_HA_CHANGES, bool),
|
(CONF_DETECT_NON_HA_CHANGES, DEFAULT_DETECT_NON_HA_CHANGES, bool),
|
||||||
(CONF_SEPARATE_TURN_ON_COMMANDS, DEFAULT_SEPARATE_TURN_ON_COMMANDS, bool),
|
(CONF_SEPARATE_TURN_ON_COMMANDS, DEFAULT_SEPARATE_TURN_ON_COMMANDS, bool),
|
||||||
(CONF_SEND_SPLIT_DELAY, DEFAULT_SEND_SPLIT_DELAY, int_between(0, 10000)),
|
(CONF_SEND_SPLIT_DELAY, DEFAULT_SEND_SPLIT_DELAY, int_between(0, 10000)),
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ from homeassistant.components.adaptive_lighting.const import (
|
||||||
ADAPT_BRIGHTNESS_SWITCH,
|
ADAPT_BRIGHTNESS_SWITCH,
|
||||||
ADAPT_COLOR_SWITCH,
|
ADAPT_COLOR_SWITCH,
|
||||||
ATTR_TURN_ON_OFF_LISTENER,
|
ATTR_TURN_ON_OFF_LISTENER,
|
||||||
|
CONF_ALT_DETECT_METHOD,
|
||||||
CONF_AUTORESET_CONTROL,
|
CONF_AUTORESET_CONTROL,
|
||||||
CONF_DETECT_NON_HA_CHANGES,
|
CONF_DETECT_NON_HA_CHANGES,
|
||||||
CONF_INITIAL_TRANSITION,
|
CONF_INITIAL_TRANSITION,
|
||||||
|
|
@ -22,6 +23,7 @@ from homeassistant.components.adaptive_lighting.const import (
|
||||||
CONF_SUNRISE_OFFSET,
|
CONF_SUNRISE_OFFSET,
|
||||||
CONF_SUNRISE_TIME,
|
CONF_SUNRISE_TIME,
|
||||||
CONF_SUNSET_TIME,
|
CONF_SUNSET_TIME,
|
||||||
|
CONF_TAKE_OVER_CONTROL,
|
||||||
CONF_TRANSITION,
|
CONF_TRANSITION,
|
||||||
CONF_TURN_ON_LIGHTS,
|
CONF_TURN_ON_LIGHTS,
|
||||||
CONF_USE_DEFAULTS,
|
CONF_USE_DEFAULTS,
|
||||||
|
|
@ -212,7 +214,9 @@ async def setup_lights_and_switch(hass, extra_conf=None):
|
||||||
CONF_SUNSET_TIME: datetime.time(SUNSET.hour),
|
CONF_SUNSET_TIME: datetime.time(SUNSET.hour),
|
||||||
CONF_INITIAL_TRANSITION: 0,
|
CONF_INITIAL_TRANSITION: 0,
|
||||||
CONF_TRANSITION: 0,
|
CONF_TRANSITION: 0,
|
||||||
CONF_DETECT_NON_HA_CHANGES: True,
|
CONF_ALT_DETECT_METHOD: False,
|
||||||
|
CONF_DETECT_NON_HA_CHANGES: False,
|
||||||
|
CONF_TAKE_OVER_CONTROL: True,
|
||||||
CONF_PREFER_RGB_COLOR: False,
|
CONF_PREFER_RGB_COLOR: False,
|
||||||
CONF_MIN_COLOR_TEMP: 2500, # to not coincide with sleep_color_temp
|
CONF_MIN_COLOR_TEMP: 2500, # to not coincide with sleep_color_temp
|
||||||
**(extra_conf or {}),
|
**(extra_conf or {}),
|
||||||
|
|
@ -666,7 +670,7 @@ async def test_manual_control(hass):
|
||||||
@pytest.mark.dependency(depends=[*GLOBAL_TEST_DEPENDENCIES, "test_manual_control"])
|
@pytest.mark.dependency(depends=[*GLOBAL_TEST_DEPENDENCIES, "test_manual_control"])
|
||||||
async def test_auto_reset_manual_control(hass):
|
async def test_auto_reset_manual_control(hass):
|
||||||
switch, (light, *_) = await setup_lights_and_switch(
|
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
|
context = switch.create_context("test") # needs to be passed to update method
|
||||||
manual_control = switch.turn_on_off_listener.manual_control
|
manual_control = switch.turn_on_off_listener.manual_control
|
||||||
|
|
@ -1032,11 +1036,24 @@ async def test_state_change_handlers(hass):
|
||||||
assert listener.transition_timers.get(ENTITY_LIGHT)
|
assert listener.transition_timers.get(ENTITY_LIGHT)
|
||||||
|
|
||||||
# 5. Execute some checks during a transition
|
# 5. Execute some checks during a transition
|
||||||
_LOGGER.debug("Test detect_non_ha_changes:")
|
|
||||||
|
for i in range(2):
|
||||||
|
if i == 0:
|
||||||
|
_LOGGER.debug("Test detect_non_ha_changes before a transition:")
|
||||||
switch._take_over_control = True
|
switch._take_over_control = True
|
||||||
assert switch._take_over_control
|
assert switch._take_over_control
|
||||||
switch._detect_non_ha_changes = True
|
switch._detect_non_ha_changes = True
|
||||||
assert switch._detect_non_ha_changes
|
assert switch._detect_non_ha_changes
|
||||||
|
switch._alt_detect_method = False
|
||||||
|
assert not switch._alt_detect_method
|
||||||
|
elif i == 1:
|
||||||
|
_LOGGER.debug("Test alt_detect_method before a transition:")
|
||||||
|
switch._take_over_control = True
|
||||||
|
assert switch._take_over_control
|
||||||
|
switch._detect_non_ha_changes = False
|
||||||
|
assert not switch._detect_non_ha_changes
|
||||||
|
switch._alt_detect_method = True
|
||||||
|
assert switch._alt_detect_method
|
||||||
await asyncio.sleep(transition_used / 3)
|
await asyncio.sleep(transition_used / 3)
|
||||||
# Ensure the timer still exists
|
# Ensure the timer still exists
|
||||||
timer = listener.transition_timers.get(ENTITY_LIGHT)
|
timer = listener.transition_timers.get(ENTITY_LIGHT)
|
||||||
|
|
@ -1053,6 +1070,25 @@ async def test_state_change_handlers(hass):
|
||||||
|
|
||||||
# 6. Assert everything after the transition finishes.
|
# 6. Assert everything after the transition finishes.
|
||||||
await asyncio.sleep(transition_used)
|
await asyncio.sleep(transition_used)
|
||||||
|
|
||||||
|
for i in range(2):
|
||||||
|
if i == 0:
|
||||||
|
_LOGGER.debug("Test detect_non_ha_changes after a transition:")
|
||||||
|
switch._take_over_control = True
|
||||||
|
assert switch._take_over_control
|
||||||
|
switch._detect_non_ha_changes = True
|
||||||
|
assert switch._detect_non_ha_changes
|
||||||
|
switch._alt_detect_method = False
|
||||||
|
assert not switch._alt_detect_method
|
||||||
|
elif i == 1:
|
||||||
|
_LOGGER.debug("Test alt_detect_method after a transition:")
|
||||||
|
switch._take_over_control = True
|
||||||
|
assert switch._take_over_control
|
||||||
|
switch._detect_non_ha_changes = False
|
||||||
|
assert not switch._detect_non_ha_changes
|
||||||
|
switch._alt_detect_method = True
|
||||||
|
assert switch._alt_detect_method
|
||||||
|
|
||||||
assert listener.last_state_change.get(ENTITY_LIGHT)
|
assert listener.last_state_change.get(ENTITY_LIGHT)
|
||||||
assert len(listener.last_state_change[ENTITY_LIGHT]) == total_events
|
assert len(listener.last_state_change[ENTITY_LIGHT]) == total_events
|
||||||
# Timer should be done and reset now.
|
# Timer should be done and reset now.
|
||||||
|
|
@ -1081,8 +1117,12 @@ async def test_state_change_handlers(hass):
|
||||||
|
|
||||||
# On next update ENTITY_LIGHT should be marked as manually controlled
|
# On next update ENTITY_LIGHT should be marked as manually controlled
|
||||||
await update(force=False)
|
await update(force=False)
|
||||||
assert switch.turn_on_off_listener.last_service_data.get(ENTITY_LIGHT) is not None
|
assert (
|
||||||
assert switch.turn_on_off_listener.last_state_change.get(ENTITY_LIGHT) is not None
|
switch.turn_on_off_listener.last_service_data.get(ENTITY_LIGHT) is not None
|
||||||
|
)
|
||||||
|
assert (
|
||||||
|
switch.turn_on_off_listener.last_state_change.get(ENTITY_LIGHT) is not None
|
||||||
|
)
|
||||||
assert switch.turn_on_off_listener.manual_control[ENTITY_LIGHT]
|
assert switch.turn_on_off_listener.manual_control[ENTITY_LIGHT]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue