core/homeassistant/components/qwikswitch/light.py

29 lines
915 B
Python
Raw Normal View History

"""Support for Qwikswitch Relays and Dimmers."""
2020-04-26 16:49:41 +00:00
from homeassistant.components.light import SUPPORT_BRIGHTNESS, LightEntity
2017-01-17 22:40:34 +00:00
from . import DOMAIN as QWIKSWITCH, QSToggleEntity
async def async_setup_platform(hass, _, add_entities, discovery_info=None):
2018-03-25 21:32:13 +00:00
"""Add lights from the main Qwikswitch component."""
if discovery_info is None:
return
qsusb = hass.data[QWIKSWITCH]
devs = [QSLight(qsid, qsusb) for qsid in discovery_info[QWIKSWITCH]]
add_entities(devs)
2020-04-26 16:49:41 +00:00
class QSLight(QSToggleEntity, LightEntity):
"""Light based on a Qwikswitch relay/dimmer module."""
@property
def brightness(self):
"""Return the brightness of this light (0-255)."""
return self.device.value if self.device.is_dimmer else None
@property
def supported_features(self):
"""Flag supported features."""
return SUPPORT_BRIGHTNESS if self.device.is_dimmer else 0