core/homeassistant/components/light/rfxtrx.py

69 lines
2.0 KiB
Python
Raw Normal View History

2015-09-27 09:13:49 +00:00
"""
2015-10-08 09:08:17 +00:00
Support for RFXtrx lights.
2015-09-27 09:13:49 +00:00
2015-10-08 09:08:17 +00:00
For more details about this platform, please refer to the documentation at
2015-11-09 12:12:18 +00:00
https://home-assistant.io/components/light.rfxtrx/
2015-09-27 09:13:49 +00:00
"""
import logging
2016-02-19 05:27:50 +00:00
import homeassistant.components.rfxtrx as rfxtrx
from homeassistant.components.light import (ATTR_BRIGHTNESS,
SUPPORT_BRIGHTNESS, Light)
DEPENDENCIES = ['rfxtrx']
2015-09-27 09:13:49 +00:00
_LOGGER = logging.getLogger(__name__)
PLATFORM_SCHEMA = rfxtrx.DEFAULT_SCHEMA
SUPPORT_RFXTRX = SUPPORT_BRIGHTNESS
2015-09-27 09:13:49 +00:00
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
2016-03-07 21:08:21 +00:00
"""Setup the RFXtrx platform."""
2015-11-26 07:27:31 +00:00
import RFXtrx as rfxtrxmod
2016-04-06 17:34:51 +00:00
lights = rfxtrx.get_devices_from_config(config, RfxtrxLight)
2015-09-27 21:51:19 +00:00
add_devices_callback(lights)
2015-09-27 09:13:49 +00:00
def light_update(event):
2016-03-07 21:08:21 +00:00
"""Callback for light updates from the RFXtrx gateway."""
2016-02-11 13:15:51 +00:00
if not isinstance(event.device, rfxtrxmod.LightingDevice) or \
not event.device.known_to_be_dimmable:
2015-10-07 17:15:50 +00:00
return
2016-04-06 17:34:51 +00:00
new_device = rfxtrx.get_new_device(event, config, RfxtrxLight)
if new_device:
add_devices_callback([new_device])
2016-04-06 17:34:51 +00:00
rfxtrx.apply_received_command(event)
2015-10-07 17:15:50 +00:00
# Subscribe to main rfxtrx events
2015-09-27 09:13:49 +00:00
if light_update not in rfxtrx.RECEIVED_EVT_SUBSCRIBERS:
rfxtrx.RECEIVED_EVT_SUBSCRIBERS.append(light_update)
2016-04-06 17:34:51 +00:00
class RfxtrxLight(rfxtrx.RfxtrxDevice, Light):
2016-03-07 21:08:21 +00:00
"""Represenation of a RFXtrx light."""
2016-01-23 10:50:09 +00:00
@property
def brightness(self):
2016-03-07 21:08:21 +00:00
"""Return the brightness of this light between 0..255."""
return self._brightness
@property
def supported_features(self):
"""Flag supported features."""
return SUPPORT_RFXTRX
2015-09-27 09:13:49 +00:00
def turn_on(self, **kwargs):
2016-03-07 21:08:21 +00:00
"""Turn the light on."""
brightness = kwargs.get(ATTR_BRIGHTNESS)
if brightness is None:
self._brightness = 255
2016-04-06 17:34:51 +00:00
self._send_command("turn_on")
else:
self._brightness = brightness
_brightness = (brightness * 100 // 255)
2016-04-06 17:34:51 +00:00
self._send_command("dim", _brightness)