2016-07-24 00:03:29 +00:00
|
|
|
"""
|
|
|
|
Support for Qwikswitch Relays and Dimmers.
|
|
|
|
|
|
|
|
For more details about this platform, please refer to the documentation at
|
|
|
|
https://home-assistant.io/components/light.qwikswitch/
|
|
|
|
"""
|
2018-03-29 21:29:46 +00:00
|
|
|
from homeassistant.components.qwikswitch import (
|
|
|
|
QSToggleEntity, DOMAIN as QWIKSWITCH)
|
|
|
|
from homeassistant.components.light import SUPPORT_BRIGHTNESS, Light
|
2017-01-17 22:40:34 +00:00
|
|
|
|
2018-03-29 21:29:46 +00:00
|
|
|
DEPENDENCIES = [QWIKSWITCH]
|
2016-07-24 00:03:29 +00:00
|
|
|
|
|
|
|
|
2018-03-29 21:29:46 +00:00
|
|
|
async def async_setup_platform(hass, _, add_devices, discovery_info=None):
|
2018-03-25 21:32:13 +00:00
|
|
|
"""Add lights from the main Qwikswitch component."""
|
2016-07-24 00:03:29 +00:00
|
|
|
if discovery_info is None:
|
2018-03-29 21:29:46 +00:00
|
|
|
return
|
2016-07-24 00:03:29 +00:00
|
|
|
|
2018-03-29 21:29:46 +00:00
|
|
|
qsusb = hass.data[QWIKSWITCH]
|
|
|
|
devs = [QSLight(qsid, qsusb) for qsid in discovery_info[QWIKSWITCH]]
|
|
|
|
add_devices(devs)
|
|
|
|
|
|
|
|
|
|
|
|
class QSLight(QSToggleEntity, Light):
|
|
|
|
"""Light based on a Qwikswitch relay/dimmer module."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def brightness(self):
|
|
|
|
"""Return the brightness of this light (0-255)."""
|
2018-04-08 19:59:19 +00:00
|
|
|
return self.device.value if self.device.is_dimmer else None
|
2018-03-29 21:29:46 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def supported_features(self):
|
|
|
|
"""Flag supported features."""
|
2018-04-08 19:59:19 +00:00
|
|
|
return SUPPORT_BRIGHTNESS if self.device.is_dimmer else 0
|