mirror of
https://github.com/basnijholt/adaptive-lighting.git
synced 2026-09-15 08:14:04 +02:00
add separate_turn_on_commands option for MQTT lights
Closes https://github.com/basnijholt/adaptive-lighting/issues/29
This commit is contained in:
parent
c8620c3338
commit
8c39662318
6 changed files with 27 additions and 7 deletions
|
|
@ -24,6 +24,10 @@ CONF_MIN_BRIGHTNESS, DEFAULT_MIN_BRIGHTNESS = "min_brightness", 1
|
|||
CONF_MIN_COLOR_TEMP, DEFAULT_MIN_COLOR_TEMP = "min_color_temp", 2000
|
||||
CONF_ONLY_ONCE, DEFAULT_ONLY_ONCE = "only_once", False
|
||||
CONF_PREFER_RGB_COLOR, DEFAULT_PREFER_RGB_COLOR = "prefer_rgb_color", False
|
||||
CONF_SEPARATE_TURN_ON_COMMANDS, DEFAULT_SEPARATE_TURN_ON_COMMANDS = (
|
||||
"separate_turn_on_commands",
|
||||
False,
|
||||
)
|
||||
CONF_SLEEP_BRIGHTNESS, DEFAULT_SLEEP_BRIGHTNESS = "sleep_brightness", 1
|
||||
CONF_SLEEP_COLOR_TEMP, DEFAULT_SLEEP_COLOR_TEMP = "sleep_color_temp", 1000
|
||||
CONF_SUNRISE_OFFSET, DEFAULT_SUNRISE_OFFSET = "sunrise_offset", 0
|
||||
|
|
@ -74,6 +78,7 @@ VALIDATION_TUPLES = [
|
|||
(CONF_ONLY_ONCE, DEFAULT_ONLY_ONCE, bool),
|
||||
(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),
|
||||
]
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
"min_color_temp": "min_color_temp, in Kelvin",
|
||||
"only_once": "only_once, only adapt the lights when turning them on",
|
||||
"prefer_rgb_color": "prefer_rgb_color, use 'rgb_color' over 'color_temp' when possible",
|
||||
"separate_turn_on_commands": "separate_turn_on_commands, for each attribute (color, brightness, etc.) in 'light.turn_on', required for some lights.",
|
||||
"sleep_brightness": "sleep_brightness, in %",
|
||||
"sleep_color_temp": "sleep_color_temp, in Kelvin",
|
||||
"sunrise_offset": "sunrise_offset, in +/- seconds",
|
||||
|
|
|
|||
|
|
@ -100,6 +100,7 @@ from .const import (
|
|||
CONF_MIN_COLOR_TEMP,
|
||||
CONF_ONLY_ONCE,
|
||||
CONF_PREFER_RGB_COLOR,
|
||||
CONF_SEPARATE_TURN_ON_COMMANDS,
|
||||
CONF_SLEEP_BRIGHTNESS,
|
||||
CONF_SLEEP_COLOR_TEMP,
|
||||
CONF_SUNRISE_OFFSET,
|
||||
|
|
@ -206,7 +207,7 @@ async def handle_set_manual_control(switch: AdaptiveSwitch, service_call: Servic
|
|||
"""Set or unset lights as 'manually controlled'."""
|
||||
lights = service_call.data[CONF_LIGHTS]
|
||||
if not lights:
|
||||
all_lights = switch._lights
|
||||
all_lights = switch._lights # pylint: disable=protected-access
|
||||
else:
|
||||
all_lights = _expand_light_groups(switch.hass, lights)
|
||||
_LOGGER.debug(
|
||||
|
|
@ -492,6 +493,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
|
|||
self._interval = data[CONF_INTERVAL]
|
||||
self._only_once = data[CONF_ONLY_ONCE]
|
||||
self._prefer_rgb_color = data[CONF_PREFER_RGB_COLOR]
|
||||
self._separate_turn_on_commands = data[CONF_SEPARATE_TURN_ON_COMMANDS]
|
||||
self._take_over_control = data[CONF_TAKE_OVER_CONTROL]
|
||||
self._transition = min(
|
||||
data[CONF_TRANSITION], self._interval.total_seconds() // 2
|
||||
|
|
@ -747,12 +749,21 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
|
|||
context.id,
|
||||
)
|
||||
self.turn_on_off_listener.last_service_data[light] = service_data
|
||||
await self.hass.services.async_call(
|
||||
LIGHT_DOMAIN,
|
||||
SERVICE_TURN_ON,
|
||||
service_data,
|
||||
context=context,
|
||||
)
|
||||
if self._separate_turn_on_commands:
|
||||
service_datas = [
|
||||
{ATTR_ENTITY_ID: light, key: value}
|
||||
for key, value in service_data.items()
|
||||
if key != ATTR_ENTITY_ID
|
||||
]
|
||||
else:
|
||||
service_datas = [service_data]
|
||||
for service_data in service_datas:
|
||||
await self.hass.services.async_call(
|
||||
LIGHT_DOMAIN,
|
||||
SERVICE_TURN_ON,
|
||||
service_data,
|
||||
context=context,
|
||||
)
|
||||
|
||||
async def _update_attrs_and_maybe_adapt_lights(
|
||||
self,
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
"min_color_temp": "min_color_temp, minimale Farbtemperatur in Kelvin",
|
||||
"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, for each attribute (color, brightness, etc.) in 'light.turn_on', required for some lights.",
|
||||
"sleep_brightness": "sleep_brightness, Schlafhelligkeit in %",
|
||||
"sleep_color_temp": "sleep_color_temp, Schlaffarbtemperaturin Kelvin",
|
||||
"sunrise_offset": "sunrise_offset, Sonnenaufgang Verschiebung in +/- seconds",
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
"min_color_temp": "min_color_temp, in Kelvin",
|
||||
"only_once": "only_once, only adapt the lights when turning them on",
|
||||
"prefer_rgb_color": "prefer_rgb_color, use 'rgb_color' over 'color_temp' when possible",
|
||||
"separate_turn_on_commands": "separate_turn_on_commands, for each attribute (color, brightness, etc.) in 'light.turn_on', required for some lights.",
|
||||
"sleep_brightness": "sleep_brightness, in %",
|
||||
"sleep_color_temp": "sleep_color_temp, in Kelvin",
|
||||
"sunrise_offset": "sunrise_offset, in +/- seconds",
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
"min_color_temp": "min_color_temp, i Kelvin",
|
||||
"only_once": "only_once, Adaptivt justera endast ljuskällorna när de sätts från 'av' till 'på'",
|
||||
"prefer_rgb_color": "prefer_rgb_color, Använd 'rgb_color' över 'color_temp' om möjligt",
|
||||
"separate_turn_on_commands": "separate_turn_on_commands, for each attribute (color, brightness, etc.) in 'light.turn_on', required for some lights.",
|
||||
"sleep_brightness": "sleep_brightness, i %",
|
||||
"sleep_color_temp": "sleep_color_temp, i Kelvin",
|
||||
"sunrise_offset": "sunrise_offset, i +/- sekunder",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue