Skip to content

Commit

Permalink
Merge pull request #384 from Mark-Niemeyer/send_split_delay
Browse files Browse the repository at this point in the history
add a delay between sending commands using separate_turn_on_commands
  • Loading branch information
basnijholt authored Nov 27, 2022
2 parents e33ddc8 + 97bb2cf commit 2029319
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ adaptive_lighting:
| `take_over_control` | If another source calls `light.turn_on` while the lights are on and being adapted, disable Adaptive Lighting. | False | True | boolean |
| `detect_non_ha_changes` | Whether to detect state changes and stop adapting lights, even not from `light.turn_on`. Needs `take_over_control` to be enabled. Note that by enabling this option, it calls 'homeassistant.update_entity' every 'interval'! | False | False | boolean |
| `separate_turn_on_commands` | Whether to use separate `light.turn_on` calls for color and brightness, needed for some types of lights | False | False | boolean |
| `send_split_delay` | Wait between commands (milliseconds), when separate_turn_on_commands is used. May ensure that both commands are handled by the bulb correctly. | False | 0 | integer |
| `adapt_delay` | Wait time in seconds between light turn on, and Adaptive Lights applying changes to the light state. May avoid flickering. | False | 0 | integer |

Full example:
Expand Down
2 changes: 2 additions & 0 deletions custom_components/adaptive_lighting/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@

CONF_ADAPT_DELAY, DEFAULT_ADAPT_DELAY = "adapt_delay", 0
TURNING_OFF_DELAY = 5
CONF_SEND_SPLIT_DELAY, DEFAULT_SEND_SPLIT_DELAY = "send_split_delay", 0


def int_between(min_int, max_int):
Expand Down Expand Up @@ -108,6 +109,7 @@ def int_between(min_int, max_int):
(CONF_TAKE_OVER_CONTROL, DEFAULT_TAKE_OVER_CONTROL, bool),
(CONF_DETECT_NON_HA_CHANGES, DEFAULT_DETECT_NON_HA_CHANGES, 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_ADAPT_DELAY, DEFAULT_ADAPT_DELAY, int_between(0, 10000)),
]

Expand Down
1 change: 1 addition & 0 deletions custom_components/adaptive_lighting/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"only_once": "only_once: Only adapt the lights when turning them on.",
"prefer_rgb_color": "prefer_rgb_color: Use 'rgb_color' rather than 'color_temp' when possible.",
"separate_turn_on_commands": "separate_turn_on_commands: Separate the commands for each attribute (color, brightness, etc.) in 'light.turn_on' (required for some lights).",
"send_split_delay": "send_split_delay: wait between commands (milliseconds), when separate_turn_on_commands is used. May ensure that both commands are handled by the bulb correctly.",
"sleep_brightness": "sleep_brightness, Brightness setting for Sleep Mode. (%)",
"sleep_rgb_or_color_temp": "sleep_rgb_or_color_temp, use 'rgb_color' or 'color_temp'",
"sleep_rgb_color": "sleep_rgb_color, in RGB",
Expand Down
3 changes: 3 additions & 0 deletions custom_components/adaptive_lighting/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
CONF_MIN_SUNSET_TIME,
CONF_ONLY_ONCE,
CONF_PREFER_RGB_COLOR,
CONF_SEND_SPLIT_DELAY,
CONF_SEPARATE_TURN_ON_COMMANDS,
CONF_SLEEP_BRIGHTNESS,
CONF_SLEEP_COLOR_TEMP,
Expand Down Expand Up @@ -574,6 +575,7 @@ def __init__(
self._take_over_control = data[CONF_TAKE_OVER_CONTROL]
self._transition = data[CONF_TRANSITION]
self._adapt_delay = data[CONF_ADAPT_DELAY]
self._send_split_delay = data[CONF_SEND_SPLIT_DELAY]
_loc = get_astral_location(self.hass)
if isinstance(_loc, tuple):
# Astral v2.2
Expand Down Expand Up @@ -873,6 +875,7 @@ async def turn_on(service_data):
transition = service_datas[0].get(ATTR_TRANSITION)
if transition is not None:
await asyncio.sleep(transition)
await asyncio.sleep(self._send_split_delay / 1000.0)
await turn_on(service_datas[1])

async def _update_attrs_and_maybe_adapt_lights(
Expand Down
1 change: 1 addition & 0 deletions custom_components/adaptive_lighting/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"only_once": "only_once, passe die Lichter nur beim Einschalten an",
"prefer_rgb_color": "prefer_rgb_color, nutze 'rgb_color' vor 'color_temp', wenn möglich",
"separate_turn_on_commands": "separate_turn_on_commands, für jedes Attribut (Farbe, Helligkeit usw.) in 'light.turn_on' werden separate Befehle gesendet. Wird für manche Leuchtmittel benötigt.",
"send_split_delay": "send_split_delay: Wartezeit zwischen dem Senden der Befehle (Millisekunden), wenn separate_turn_on_commands genutzt wird. Kann helfen, wenn die Leuchtmittel die separaten Befehle nicht korrekt umsetzen.",
"sleep_brightness": "sleep_brightness, Schlafhelligkeit in %",
"sleep_rgb_or_color_temp": "sleep_rgb_or_color_temp, nutze 'rgb_color' oder 'color_temp'",
"sleep_rgb_color": "sleep_rgb_color, in RGB",
Expand Down
1 change: 1 addition & 0 deletions custom_components/adaptive_lighting/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"only_once": "only_once: Only adapt the lights when turning them on.",
"prefer_rgb_color": "prefer_rgb_color: Use 'rgb_color' rather than 'color_temp' when possible.",
"separate_turn_on_commands": "separate_turn_on_commands: Separate the commands for each attribute (color, brightness, etc.) in 'light.turn_on' (required for some lights).",
"send_split_delay": "send_split_delay: wait between commands (milliseconds), when separate_turn_on_commands is used. May ensure that both commands are handled by the bulb correctly.",
"sleep_brightness": "sleep_brightness, Brightness setting for Sleep Mode. (%)",
"sleep_rgb_or_color_temp": "sleep_rgb_or_color_temp, use 'rgb_color' or 'color_temp'",
"sleep_rgb_color": "sleep_rgb_color, in RGB",
Expand Down

0 comments on commit 2029319

Please sign in to comment.