Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for colored KNX lights #12411

Merged
merged 2 commits into from
Feb 15, 2018
Merged
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
6 changes: 3 additions & 3 deletions homeassistant/components/knx.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.script import Script

REQUIREMENTS = ['xknx==0.7.18']
REQUIREMENTS = ['xknx==0.8.3']

DOMAIN = "knx"
DATA_KNX = "data_knx"
Expand Down Expand Up @@ -216,7 +216,7 @@ def telegram_received_cb(self, telegram):
@asyncio.coroutine
def service_send_to_knx_bus(self, call):
"""Service for sending an arbitrary KNX message to the KNX bus."""
from xknx.knx import Telegram, Address, DPTBinary, DPTArray
from xknx.knx import Telegram, GroupAddress, DPTBinary, DPTArray
attr_payload = call.data.get(SERVICE_KNX_ATTR_PAYLOAD)
attr_address = call.data.get(SERVICE_KNX_ATTR_ADDRESS)

Expand All @@ -226,7 +226,7 @@ def calculate_payload(attr_payload):
return DPTBinary(attr_payload)
return DPTArray(attr_payload)
payload = calculate_payload(attr_payload)
address = Address(attr_address)
address = GroupAddress(attr_address)

telegram = Telegram()
telegram.payload = payload
Expand Down
17 changes: 15 additions & 2 deletions homeassistant/components/light/knx.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

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
Expand All @@ -19,6 +20,8 @@
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']
Expand All @@ -29,6 +32,8 @@
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,
})


Expand Down Expand Up @@ -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)])

Expand Down Expand Up @@ -120,6 +127,8 @@ def xy_color(self):
@property
def rgb_color(self):
"""Return the RBG color value."""
if self.device.supports_color:
return self.device.current_color()
return None

@property
Expand Down Expand Up @@ -153,13 +162,17 @@ def supported_features(self):
flags = 0
if self.device.supports_dimming:
flags |= SUPPORT_BRIGHTNESS
if self.device.supports_color:
flags |= SUPPORT_RGB_COLOR
return flags

@asyncio.coroutine
def async_turn_on(self, **kwargs):
"""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()

Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ xbee-helper==0.0.7
xboxapi==0.1.1

# homeassistant.components.knx
xknx==0.7.18
xknx==0.8.3

# homeassistant.components.media_player.bluesound
# homeassistant.components.sensor.startca
Expand Down