Qwikswitch async refactor & sensor (#13509)
This commit is contained in:
1 parent
298e6eeef1
commit
3fdb0002a7
5 files changed
+185
-111
No files matched your search
@@ -4,18 +4,32 @@ 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/
|
||||
"""
|
||||
import logging
|
||||
from homeassistant.components.qwikswitch import (
|
||||
QSToggleEntity, DOMAIN as QWIKSWITCH)
|
||||
from homeassistant.components.light import SUPPORT_BRIGHTNESS, Light
|
||||
|
||||
DEPENDENCIES = ['qwikswitch']
|
||||
DEPENDENCIES = [QWIKSWITCH]
|
||||
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
async def async_setup_platform(hass, _, add_devices, discovery_info=None):
|
||||
"""Add lights from the main Qwikswitch component."""
|
||||
if discovery_info is None:
|
||||
logging.getLogger(__name__).error(
|
||||
"Configure Qwikswitch Light component failed")
|
||||
return False
|
||||
return
|
||||
|
||||
add_devices(hass.data['qwikswitch']['light'])
|
||||
return True
|
||||
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)."""
|
||||
return self._qsusb[self.qsid, 1] if self._dim else None
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
"""Flag supported features."""
|
||||
return SUPPORT_BRIGHTNESS if self._dim else 0
|
||||
Reference in new issue
Block a user