fix apply service, closes #24

This commit is contained in:
Bas Nijholt 2020-10-25 09:35:54 +01:00
commit 3352fa3b9c
3 changed files with 54 additions and 49 deletions

View file

@ -13,12 +13,12 @@ apply:
adapt_brightness:
description: "Adapt the 'brightness', default: true"
example: true
adapt_color_temp:
description: "Adapt the 'color_temp', default: true"
example: true
adapt_rgb_color:
description: "Adapt the 'rgb_color', default: true"
adapt_color:
description: "Adapt the color_temp/color_rgb, default: true"
example: true
prefer_rgb_color:
description: "Prefer to use color_rgb over color_temp if possible, default: false"
example: false
turn_on_lights:
description: "Turn on the lights that are off, default: false"
example: false

View file

@ -194,6 +194,7 @@ async def handle_apply(switch: AdaptiveSwitch, service_call: ServiceCall):
data[CONF_TRANSITION],
data[ATTR_ADAPT_BRIGHTNESS],
data[ATTR_ADAPT_COLOR],
data[CONF_PREFER_RGB_COLOR],
force=True,
)
@ -274,6 +275,7 @@ async def async_setup_entry(
): VALID_TRANSITION,
vol.Optional(ATTR_ADAPT_BRIGHTNESS, default=True): cv.boolean,
vol.Optional(ATTR_ADAPT_COLOR, default=True): cv.boolean,
vol.Optional(CONF_PREFER_RGB_COLOR, default=False): cv.boolean,
vol.Optional(CONF_TURN_ON_LIGHTS, default=False): cv.boolean,
},
handle_apply,
@ -655,6 +657,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
transition: Optional[int] = None,
adapt_brightness: Optional[bool] = None,
adapt_color: Optional[bool] = None,
prefer_rgb_color: Optional[bool] = None,
force: bool = False,
context: Optional[Context] = None,
) -> None:
@ -671,6 +674,8 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
adapt_brightness = self.adapt_brightness_switch.is_on
if adapt_color is None:
adapt_color = self.adapt_color_switch.is_on
if prefer_rgb_color is None:
prefer_rgb_color = self._prefer_rgb_color
if "transition" in features:
service_data[ATTR_TRANSITION] = transition
@ -682,7 +687,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
if (
"color_temp" in features
and adapt_color
and not (self._prefer_rgb_color and "color" in features)
and not (prefer_rgb_color and "color" in features)
):
attributes = self.hass.states.get(light).attributes
min_mireds, max_mireds = attributes["min_mireds"], attributes["max_mireds"]

View file

@ -1,48 +1,48 @@
{
"config": {
"abort": {
"already_configured": "Device is already configured"
},
"step": {
"user": {
"data": {
"name": "Name"
},
"description": "Every instance can contain multiple lights!",
"title": "Choose a name for the Adaptive Lighting"
}
"title": "Adaptive Lighting",
"config": {
"step": {
"user": {
"title": "Choose a name for the Adaptive Lighting",
"description": "Every instance can contain multiple lights!",
"data": {
"name": "Name"
}
}
},
"options": {
"error": {
"option_error": "Invalid option"
},
"step": {
"init": {
"data": {
"detect_non_ha_changes": "detect_non_ha_changes, detects all >5% changes made to the lights (also outside of HA), requires 'take_over_control' to be enabled (calls 'homeassistant.update_entity' every 'interval'!)",
"initial_transition": "initial_transition, when lights go 'off' to 'on' or when 'sleep_state' changes",
"interval": "interval, time between switch updates in seconds",
"lights": "lights",
"max_brightness": "max_brightness, in %",
"max_color_temp": "max_color_temp, in Kelvin",
"min_brightness": "min_brightness, in %",
"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",
"sleep_brightness": "sleep_brightness, in %",
"sleep_color_temp": "sleep_color_temp, in Kelvin",
"sunrise_offset": "sunrise_offset, in +/- seconds",
"sunrise_time": "sunrise_time, in 'HH:MM:SS' format (if 'None', it uses the actual sunrise time at your location)",
"sunset_offset": "sunset_offset, in +/- seconds",
"sunset_time": "sunset_time, in 'HH:MM:SS' format (if 'None', it uses the actual sunset time at your location)",
"take_over_control": "take_over_control, if anything but Adaptive Lighting calls 'light.turn_on' when a light is already on, stop adapting that light until it (or the switch) toggles off -> on.",
"transition": "transition, in seconds"
},
"description": "All settings for a Adaptive Lighting component. The option names correspond with the YAML settings. No options are shown if you have this entry defined in YAML.",
"title": "Adaptive Lighting options"
}
"abort": {
"already_configured": "Device is already configured"
}
},
"options": {
"step": {
"init": {
"title": "Adaptive Lighting options",
"description": "All settings for a Adaptive Lighting component. The option names correspond with the YAML settings. No options are shown if you have this entry defined in YAML.",
"data": {
"lights": "lights",
"initial_transition": "initial_transition, when lights go 'off' to 'on' or when 'sleep_state' changes",
"interval": "interval, time between switch updates in seconds",
"max_brightness": "max_brightness, in %",
"max_color_temp": "max_color_temp, in Kelvin",
"min_brightness": "min_brightness, in %",
"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",
"sleep_brightness": "sleep_brightness, in %",
"sleep_color_temp": "sleep_color_temp, in Kelvin",
"sunrise_offset": "sunrise_offset, in +/- seconds",
"sunrise_time": "sunrise_time, in 'HH:MM:SS' format (if 'None', it uses the actual sunrise time at your location)",
"sunset_offset": "sunset_offset, in +/- seconds",
"sunset_time": "sunset_time, in 'HH:MM:SS' format (if 'None', it uses the actual sunset time at your location)",
"take_over_control": "take_over_control, if anything but Adaptive Lighting calls 'light.turn_on' when a light is already on, stop adapting that light until it (or the switch) toggles off -> on.",
"detect_non_ha_changes": "detect_non_ha_changes, detects all >10% changes made to the lights (also outside of HA), requires 'take_over_control' to be enabled (calls 'homeassistant.update_entity' every 'interval'!)",
"transition": "transition, in seconds"
}
}
},
"title": "Adaptive Lighting"
}
"error": {
"option_error": "Invalid option"
}
}
}