Added support for colored KNX lights (#12411)

This commit is contained in:
Julius Mittenzwei 2018-02-15 07:06:36 +01:00 committed by Paulus Schoutsen
parent 7e2e82d956
commit 96bd153c80
3 changed files with 19 additions and 6 deletions

View file

@ -10,7 +10,8 @@ import voluptuous as vol
from homeassistant.components.knx import ATTR_DISCOVER_DEVICES, DATA_KNX
from homeassistant.components.light import (
ATTR_BRIGHTNESS, PLATFORM_SCHEMA, SUPPORT_BRIGHTNESS, Light)
ATTR_BRIGHTNESS, ATTR_RGB_COLOR, PLATFORM_SCHEMA, SUPPORT_BRIGHTNESS,
SUPPORT_RGB_COLOR, Light)
from homeassistant.const import CONF_NAME
from homeassistant.core import callback
import homeassistant.helpers.config_validation as cv
@ -19,6 +20,8 @@ CONF_ADDRESS = 'address'
CONF_STATE_ADDRESS = 'state_address'
CONF_BRIGHTNESS_ADDRESS = 'brightness_address'
CONF_BRIGHTNESS_STATE_ADDRESS = 'brightness_state_address'
CONF_COLOR_ADDRESS = 'color_address'
CONF_COLOR_STATE_ADDRESS = 'color_state_address'
DEFAULT_NAME = 'KNX Light'
DEPENDENCIES = ['knx']
@ -29,6 +32,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_STATE_ADDRESS): cv.string,
vol.Optional(CONF_BRIGHTNESS_ADDRESS): cv.string,
vol.Optional(CONF_BRIGHTNESS_STATE_ADDRESS): cv.string,
vol.Optional(CONF_COLOR_ADDRESS): cv.string,
vol.Optional(CONF_COLOR_STATE_ADDRESS): cv.string,
})
@ -66,7 +71,9 @@ def async_add_devices_config(hass, config, async_add_devices):
group_address_switch_state=config.get(CONF_STATE_ADDRESS),
group_address_brightness=config.get(CONF_BRIGHTNESS_ADDRESS),
group_address_brightness_state=config.get(
CONF_BRIGHTNESS_STATE_ADDRESS))
CONF_BRIGHTNESS_STATE_ADDRESS),
group_address_color=config.get(CONF_COLOR_ADDRESS),
group_address_color_state=config.get(CONF_COLOR_STATE_ADDRESS))
hass.data[DATA_KNX].xknx.devices.add(light)
async_add_devices([KNXLight(hass, light)])
@ -120,6 +127,8 @@ class KNXLight(Light):
@property
def rgb_color(self):
"""Return the RBG color value."""
if self.device.supports_color:
return self.device.current_color()
return None
@property
@ -153,6 +162,8 @@ class KNXLight(Light):
flags = 0
if self.device.supports_dimming:
flags |= SUPPORT_BRIGHTNESS
if self.device.supports_color:
flags |= SUPPORT_RGB_COLOR
return flags
@asyncio.coroutine
@ -160,6 +171,8 @@ class KNXLight(Light):
"""Turn the light on."""
if ATTR_BRIGHTNESS in kwargs and self.device.supports_dimming:
yield from self.device.set_brightness(int(kwargs[ATTR_BRIGHTNESS]))
elif ATTR_RGB_COLOR in kwargs:
yield from self.device.set_color(kwargs[ATTR_RGB_COLOR])
else:
yield from self.device.set_on()