2019-04-03 17:40:03 +02:00
|
|
|
"""Support for Qwikswitch Relays and Dimmers."""
|
2022-01-03 15:11:59 +01:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2022-04-27 16:17:12 +02:00
|
|
|
from homeassistant.components.light import ColorMode, LightEntity
|
2022-01-03 15:11:59 +01:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
2017-01-17 23:40:34 +01:00
|
|
|
|
2019-03-20 22:56:46 -07:00
|
|
|
from . import DOMAIN as QWIKSWITCH, QSToggleEntity
|
|
|
|
|
2016-07-24 02:03:29 +02:00
|
|
|
|
2022-01-03 15:11:59 +01:00
|
|
|
async def async_setup_platform(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
_: ConfigType,
|
|
|
|
add_entities: AddEntitiesCallback,
|
|
|
|
discovery_info: DiscoveryInfoType | None = None,
|
|
|
|
) -> None:
|
2018-03-25 23:32:13 +02:00
|
|
|
"""Add lights from the main Qwikswitch component."""
|
2016-07-24 02:03:29 +02:00
|
|
|
if discovery_info is None:
|
2018-03-29 23:29:46 +02:00
|
|
|
return
|
2016-07-24 02:03:29 +02:00
|
|
|
|
2018-03-29 23:29:46 +02:00
|
|
|
qsusb = hass.data[QWIKSWITCH]
|
|
|
|
devs = [QSLight(qsid, qsusb) for qsid in discovery_info[QWIKSWITCH]]
|
2018-08-24 16:37:30 +02:00
|
|
|
add_entities(devs)
|
2018-03-29 23:29:46 +02:00
|
|
|
|
|
|
|
|
2020-04-26 18:49:41 +02:00
|
|
|
class QSLight(QSToggleEntity, LightEntity):
|
2018-03-29 23:29:46 +02:00
|
|
|
"""Light based on a Qwikswitch relay/dimmer module."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def brightness(self):
|
|
|
|
"""Return the brightness of this light (0-255)."""
|
2018-08-26 21:25:39 +02:00
|
|
|
return self.device.value if self.device.is_dimmer else None
|
2018-03-29 23:29:46 +02:00
|
|
|
|
|
|
|
@property
|
2022-04-27 16:17:12 +02:00
|
|
|
def color_mode(self) -> ColorMode:
|
|
|
|
"""Return the color mode of the light."""
|
|
|
|
return ColorMode.BRIGHTNESS if self.device.is_dimmer else ColorMode.ONOFF
|
|
|
|
|
|
|
|
@property
|
|
|
|
def supported_color_modes(self) -> set[ColorMode]:
|
|
|
|
"""Flag supported color modes."""
|
|
|
|
return {self.color_mode}
|