Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions homeassistant/components/light/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
SUPPORT_TRANSITION = 32
SUPPORT_XY_COLOR = 64
SUPPORT_WHITE_VALUE = 128
SUPPORT_OFF_STATE = 256

# Integer that represents transition time in seconds to make change.
ATTR_TRANSITION = "transition"
Expand Down Expand Up @@ -77,6 +78,8 @@

LIGHT_PROFILES_FILE = "light_profiles.csv"

ATTR_POWER_ON = "power_on"

PROP_TO_ATTR = {
'brightness': ATTR_BRIGHTNESS,
'color_temp': ATTR_COLOR_TEMP,
Expand Down Expand Up @@ -107,6 +110,7 @@
ATTR_WHITE_VALUE: vol.All(vol.Coerce(int), vol.Range(min=0, max=255)),
ATTR_FLASH: vol.In([FLASH_SHORT, FLASH_LONG]),
ATTR_EFFECT: cv.string,
vol.Optional(ATTR_POWER_ON, default=True): cv.boolean,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this just doesn't make much sense… turn on with power off? 😛 I wonder if we should extend the turn_off schema instead?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, this idea came up before and I have shot it down because of proposed implementations (things like a set_state command etc).

As far as I know LIFX is the only light that allows changing settings while it's off. So I suggest you add it as a LIFX only service. If we ever have more lights than we can maybe generalize it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think I touched on both points in the "Alternatives" section. The idea comes up repeatedly because it's really useful and we miss it when converting from IFTTT 😄

I'm cool with starting out with a LIFX only service (though that will not fix the Flux+motion sensor race). So that will indeed be something like lifx_set_state – or maybe lifx_set_color. I will look into that.

If I am creating a new service call, will it be acceptable to use the units that are well-known from the LIFX smartphone app? This is Kelvin for temperature and percentage for brightness.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a lifx only service so I don't really care. But I feel like it would make sense to keep them in sync with the rest of Hass. So rather not use the app units.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, and I must admit that I did not read the whole PR intro…

})

LIGHT_TURN_OFF_SCHEMA = vol.Schema({
Expand Down Expand Up @@ -143,19 +147,20 @@ def is_on(hass, entity_id=None):

def turn_on(hass, entity_id=None, transition=None, brightness=None,
rgb_color=None, xy_color=None, color_temp=None, white_value=None,
profile=None, flash=None, effect=None, color_name=None):
profile=None, flash=None, effect=None, color_name=None,
power_on=None):
"""Turn all or specified light on."""
hass.add_job(
async_turn_on, hass, entity_id, transition, brightness,
rgb_color, xy_color, color_temp, white_value,
profile, flash, effect, color_name)
profile, flash, effect, color_name, power_on)


@callback
def async_turn_on(hass, entity_id=None, transition=None, brightness=None,
rgb_color=None, xy_color=None, color_temp=None,
white_value=None, profile=None, flash=None, effect=None,
color_name=None):
color_name=None, power_on=None):
"""Turn all or specified light on."""
data = {
key: value for key, value in [
Expand All @@ -170,6 +175,7 @@ def async_turn_on(hass, entity_id=None, transition=None, brightness=None,
(ATTR_FLASH, flash),
(ATTR_EFFECT, effect),
(ATTR_COLOR_NAME, color_name),
(ATTR_POWER_ON, power_on),
] if value is not None
}

Expand Down
14 changes: 9 additions & 5 deletions homeassistant/components/light/lifx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
from homeassistant.components.light import (
Light, PLATFORM_SCHEMA, ATTR_BRIGHTNESS, ATTR_COLOR_NAME, ATTR_RGB_COLOR,
ATTR_XY_COLOR, ATTR_COLOR_TEMP, ATTR_TRANSITION, ATTR_EFFECT,
SUPPORT_BRIGHTNESS, SUPPORT_COLOR_TEMP, SUPPORT_RGB_COLOR,
SUPPORT_XY_COLOR, SUPPORT_TRANSITION, SUPPORT_EFFECT)
ATTR_POWER_ON, SUPPORT_BRIGHTNESS, SUPPORT_COLOR_TEMP, SUPPORT_RGB_COLOR,
SUPPORT_XY_COLOR, SUPPORT_TRANSITION, SUPPORT_EFFECT, SUPPORT_OFF_STATE)
from homeassistant.util.color import (
color_temperature_mired_to_kelvin, color_temperature_kelvin_to_mired)
from homeassistant import util
Expand Down Expand Up @@ -47,7 +47,8 @@
SHORT_MAX = 65535

SUPPORT_LIFX = (SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_RGB_COLOR |
SUPPORT_XY_COLOR | SUPPORT_TRANSITION | SUPPORT_EFFECT)
SUPPORT_XY_COLOR | SUPPORT_TRANSITION | SUPPORT_EFFECT |
SUPPORT_OFF_STATE)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_SERVER, default='0.0.0.0'): cv.string,
Expand Down Expand Up @@ -316,9 +317,12 @@ def async_turn_on(self, **kwargs):
if self._power == 0:
if changed_color:
self.device.set_color(hsbk, None, 0)
self.device.set_power(True, None, fade)
if kwargs[ATTR_POWER_ON]:
self.device.set_power(True, None, fade)
else:
self.device.set_power(True, None, 0) # racing for power status
if kwargs[ATTR_POWER_ON]:
# racing for power status, our state could be obsolete
self.device.set_power(True, None, 0)
if changed_color:
self.device.set_color(hsbk, None, fade)

Expand Down
38 changes: 24 additions & 14 deletions homeassistant/components/switch/flux.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@
import logging
import voluptuous as vol

from homeassistant.components.light import is_on, turn_on
from homeassistant.components.light import is_on, turn_on, SUPPORT_OFF_STATE
from homeassistant.components.sun import next_setting, next_rising
from homeassistant.components.switch import DOMAIN, SwitchDevice
from homeassistant.const import CONF_NAME, CONF_PLATFORM
from homeassistant.const import (
CONF_NAME, CONF_PLATFORM, ATTR_SUPPORTED_FEATURES)
from homeassistant.helpers.event import track_time_change
from homeassistant.util.color import (
color_temperature_to_rgb, color_RGB_to_xy,
color_temperature_kelvin_to_mired)
from homeassistant.util.dt import now as dt_now
from homeassistant.loader import get_component
import homeassistant.helpers.config_validation as cv

DEPENDENCIES = ['sun', 'light']
Expand Down Expand Up @@ -59,24 +61,32 @@
})


def set_lights(hass, lights, **kwargs):
"""Set color of array of lights."""
entity_ids = get_component('group').expand_entity_ids(hass, lights)
for entity_id in entity_ids:
state = hass.states.get(entity_id)

if state.attributes.get(ATTR_SUPPORTED_FEATURES) & SUPPORT_OFF_STATE:
turn_on(hass, entity_id, power_on=False, **kwargs)
elif is_on(hass, entity_id):
turn_on(hass, entity_id, **kwargs)


def set_lights_xy(hass, lights, x_val, y_val, brightness):
"""Set color of array of lights."""
for light in lights:
if is_on(hass, light):
turn_on(hass, light,
xy_color=[x_val, y_val],
brightness=brightness,
transition=30)
set_lights(hass, lights,
xy_color=[x_val, y_val],
brightness=brightness,
transition=30)


def set_lights_temp(hass, lights, mired, brightness):
"""Set color of array of lights."""
for light in lights:
if is_on(hass, light):
turn_on(hass, light,
color_temp=int(mired),
brightness=brightness,
transition=30)
set_lights(hass, lights,
color_temp=int(mired),
brightness=brightness,
transition=30)


# pylint: disable=unused-argument
Expand Down