2019-02-13 20:21:14 +00:00
|
|
|
"""Support for control of ElkM1 outputs (relays)."""
|
2018-10-10 17:05:19 +00:00
|
|
|
from homeassistant.components.switch import SwitchDevice
|
|
|
|
|
2019-03-21 05:56:46 +00:00
|
|
|
from . import DOMAIN as ELK_DOMAIN, ElkEntity, create_elk_entities
|
|
|
|
|
2018-10-10 17:05:19 +00:00
|
|
|
|
2019-02-13 20:21:14 +00:00
|
|
|
async def async_setup_platform(
|
|
|
|
hass, config, async_add_entities, discovery_info=None):
|
2018-10-10 17:05:19 +00:00
|
|
|
"""Create the Elk-M1 switch platform."""
|
|
|
|
if discovery_info is None:
|
|
|
|
return
|
|
|
|
elk = hass.data[ELK_DOMAIN]['elk']
|
|
|
|
entities = create_elk_entities(hass, elk.outputs, 'output', ElkOutput, [])
|
|
|
|
async_add_entities(entities, True)
|
|
|
|
|
|
|
|
|
|
|
|
class ElkOutput(ElkEntity, SwitchDevice):
|
|
|
|
"""Elk output as switch."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self) -> bool:
|
|
|
|
"""Get the current output status."""
|
|
|
|
return self._element.output_on
|
|
|
|
|
|
|
|
async def async_turn_on(self, **kwargs):
|
|
|
|
"""Turn on the output."""
|
|
|
|
self._element.turn_on(0)
|
|
|
|
|
|
|
|
async def async_turn_off(self, **kwargs):
|
|
|
|
"""Turn off the output."""
|
|
|
|
self._element.turn_off()
|