core/homeassistant/components/qwikswitch/switch.py

29 lines
887 B
Python
Raw Normal View History

"""Support for Qwikswitch relays."""
from __future__ import annotations
from homeassistant.components.switch import SwitchEntity
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
2017-01-17 22:40:34 +00:00
from . import DOMAIN as QWIKSWITCH, QSToggleEntity
async def async_setup_platform(
hass: HomeAssistant,
_: ConfigType,
add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
2018-03-25 21:32:13 +00:00
"""Add switches from the main Qwikswitch component."""
if discovery_info is None:
return
qsusb = hass.data[QWIKSWITCH]
devs = [QSSwitch(qsid, qsusb) for qsid in discovery_info[QWIKSWITCH]]
add_entities(devs)
class QSSwitch(QSToggleEntity, SwitchEntity):
"""Switch based on a Qwikswitch relay module."""