mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Light component now supports sending flash command
This commit is contained in:
parent
e7dff308ef
commit
99447eaa17
@ -82,6 +82,12 @@ ATTR_BRIGHTNESS = "brightness"
|
|||||||
# String representing a profile (built-in ones or external defined)
|
# String representing a profile (built-in ones or external defined)
|
||||||
ATTR_PROFILE = "profile"
|
ATTR_PROFILE = "profile"
|
||||||
|
|
||||||
|
# If the light should flash, can be FLASH_SHORT or FLASH_LONG
|
||||||
|
ATTR_FLASH = "flash"
|
||||||
|
FLASH_SHORT = "short"
|
||||||
|
FLASH_LONG = "long"
|
||||||
|
|
||||||
|
|
||||||
LIGHT_PROFILES_FILE = "light_profiles.csv"
|
LIGHT_PROFILES_FILE = "light_profiles.csv"
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -96,40 +102,31 @@ def is_on(hass, entity_id=None):
|
|||||||
|
|
||||||
# pylint: disable=too-many-arguments
|
# pylint: disable=too-many-arguments
|
||||||
def turn_on(hass, entity_id=None, transition=None, brightness=None,
|
def turn_on(hass, entity_id=None, transition=None, brightness=None,
|
||||||
rgb_color=None, xy_color=None, profile=None):
|
rgb_color=None, xy_color=None, profile=None, flash=None):
|
||||||
""" Turns all or specified light on. """
|
""" Turns all or specified light on. """
|
||||||
data = {}
|
data = {
|
||||||
|
key: value for key, value in [
|
||||||
if entity_id:
|
(ATTR_ENTITY_ID, entity_id),
|
||||||
data[ATTR_ENTITY_ID] = entity_id
|
(ATTR_PROFILE, profile),
|
||||||
|
(ATTR_TRANSITION, transition),
|
||||||
if profile:
|
(ATTR_BRIGHTNESS, brightness),
|
||||||
data[ATTR_PROFILE] = profile
|
(ATTR_RGB_COLOR, rgb_color),
|
||||||
|
(ATTR_XY_COLOR, xy_color),
|
||||||
if transition is not None:
|
(ATTR_FLASH, flash),
|
||||||
data[ATTR_TRANSITION] = transition
|
] if value is not None
|
||||||
|
}
|
||||||
if brightness is not None:
|
|
||||||
data[ATTR_BRIGHTNESS] = brightness
|
|
||||||
|
|
||||||
if rgb_color:
|
|
||||||
data[ATTR_RGB_COLOR] = rgb_color
|
|
||||||
|
|
||||||
if xy_color:
|
|
||||||
data[ATTR_XY_COLOR] = xy_color
|
|
||||||
|
|
||||||
hass.services.call(DOMAIN, SERVICE_TURN_ON, data)
|
hass.services.call(DOMAIN, SERVICE_TURN_ON, data)
|
||||||
|
|
||||||
|
|
||||||
def turn_off(hass, entity_id=None, transition=None):
|
def turn_off(hass, entity_id=None, transition=None):
|
||||||
""" Turns all or specified light off. """
|
""" Turns all or specified light off. """
|
||||||
data = {}
|
data = {
|
||||||
|
key: value for key, value in [
|
||||||
if entity_id:
|
(ATTR_ENTITY_ID, entity_id),
|
||||||
data[ATTR_ENTITY_ID] = entity_id
|
(ATTR_TRANSITION, transition),
|
||||||
|
] if value is not None
|
||||||
if transition is not None:
|
}
|
||||||
data[ATTR_TRANSITION] = transition
|
|
||||||
|
|
||||||
hass.services.call(DOMAIN, SERVICE_TURN_OFF, data)
|
hass.services.call(DOMAIN, SERVICE_TURN_OFF, data)
|
||||||
|
|
||||||
@ -273,6 +270,13 @@ def setup(hass, config):
|
|||||||
# ValueError if not all values can be converted to int
|
# ValueError if not all values can be converted to int
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
if ATTR_FLASH in dat:
|
||||||
|
if dat[ATTR_FLASH] == FLASH_SHORT:
|
||||||
|
params[ATTR_FLASH] = FLASH_SHORT
|
||||||
|
|
||||||
|
elif dat[ATTR_FLASH] == FLASH_LONG:
|
||||||
|
params[ATTR_FLASH] = FLASH_LONG
|
||||||
|
|
||||||
for light in lights:
|
for light in lights:
|
||||||
# pylint: disable=star-args
|
# pylint: disable=star-args
|
||||||
light.turn_on(**params)
|
light.turn_on(**params)
|
||||||
|
@ -7,7 +7,7 @@ import homeassistant.util as util
|
|||||||
from homeassistant.helpers import ToggleDevice
|
from homeassistant.helpers import ToggleDevice
|
||||||
from homeassistant.const import ATTR_FRIENDLY_NAME, CONF_HOST
|
from homeassistant.const import ATTR_FRIENDLY_NAME, CONF_HOST
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
ATTR_BRIGHTNESS, ATTR_XY_COLOR, ATTR_TRANSITION)
|
ATTR_BRIGHTNESS, ATTR_XY_COLOR, ATTR_TRANSITION, ATTR_FLASH, FLASH_LONG)
|
||||||
|
|
||||||
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
|
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
|
||||||
MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(seconds=1)
|
MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(seconds=1)
|
||||||
@ -95,6 +95,11 @@ class HueLight(ToggleDevice):
|
|||||||
if ATTR_XY_COLOR in kwargs:
|
if ATTR_XY_COLOR in kwargs:
|
||||||
command['xy'] = kwargs[ATTR_XY_COLOR]
|
command['xy'] = kwargs[ATTR_XY_COLOR]
|
||||||
|
|
||||||
|
flash = kwargs.get(ATTR_FLASH)
|
||||||
|
|
||||||
|
if flash is not None:
|
||||||
|
command['alert'] = 'lselect' if flash == FLASH_LONG else 'select'
|
||||||
|
|
||||||
self.bridge.set_light(self.light_id, command)
|
self.bridge.set_light(self.light_id, command)
|
||||||
|
|
||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user