2019-02-14 04:35:12 +00:00
|
|
|
"""Support for LightwaveRF switches."""
|
2020-04-26 16:50:37 +00:00
|
|
|
from homeassistant.components.switch import SwitchEntity
|
2018-12-02 19:58:31 +00:00
|
|
|
from homeassistant.const import CONF_NAME
|
|
|
|
|
2019-03-21 05:56:46 +00:00
|
|
|
from . import LIGHTWAVE_LINK
|
|
|
|
|
2018-12-02 19:58:31 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
2018-12-02 19:58:31 +00:00
|
|
|
"""Find and return LightWave switches."""
|
|
|
|
if not discovery_info:
|
|
|
|
return
|
|
|
|
|
|
|
|
switches = []
|
|
|
|
lwlink = hass.data[LIGHTWAVE_LINK]
|
|
|
|
|
|
|
|
for device_id, device_config in discovery_info.items():
|
|
|
|
name = device_config[CONF_NAME]
|
|
|
|
switches.append(LWRFSwitch(name, device_id, lwlink))
|
|
|
|
|
|
|
|
async_add_entities(switches)
|
|
|
|
|
|
|
|
|
2020-04-26 16:50:37 +00:00
|
|
|
class LWRFSwitch(SwitchEntity):
|
2018-12-02 19:58:31 +00:00
|
|
|
"""Representation of a LightWaveRF switch."""
|
|
|
|
|
|
|
|
def __init__(self, name, device_id, lwlink):
|
|
|
|
"""Initialize LWRFSwitch entity."""
|
|
|
|
self._name = name
|
|
|
|
self._device_id = device_id
|
|
|
|
self._state = None
|
|
|
|
self._lwlink = lwlink
|
|
|
|
|
|
|
|
@property
|
|
|
|
def should_poll(self):
|
|
|
|
"""No polling needed for a LightWave light."""
|
|
|
|
return False
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Lightwave switch name."""
|
|
|
|
return self._name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Lightwave switch is on state."""
|
|
|
|
return self._state
|
|
|
|
|
|
|
|
async def async_turn_on(self, **kwargs):
|
|
|
|
"""Turn the LightWave switch on."""
|
|
|
|
self._state = True
|
|
|
|
self._lwlink.turn_on_switch(self._device_id, self._name)
|
2020-04-01 21:19:51 +00:00
|
|
|
self.async_write_ha_state()
|
2018-12-02 19:58:31 +00:00
|
|
|
|
|
|
|
async def async_turn_off(self, **kwargs):
|
|
|
|
"""Turn the LightWave switch off."""
|
|
|
|
self._state = False
|
|
|
|
self._lwlink.turn_off(self._device_id, self._name)
|
2020-04-01 21:19:51 +00:00
|
|
|
self.async_write_ha_state()
|