2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Velbus switches."""
|
2017-07-26 12:03:29 +00:00
|
|
|
import logging
|
|
|
|
|
2018-08-05 08:47:17 +00:00
|
|
|
from homeassistant.components.switch import SwitchDevice
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2019-07-29 07:21:26 +00:00
|
|
|
from . import VelbusEntity
|
|
|
|
from .const import DOMAIN
|
2017-07-26 12:03:29 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2019-02-13 20:21:14 +00:00
|
|
|
async def async_setup_platform(
|
|
|
|
hass, config, async_add_entities, discovery_info=None):
|
2019-07-29 07:21:26 +00:00
|
|
|
"""Old way."""
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_entry(hass, entry, async_add_entities):
|
|
|
|
"""Set up Velbus switch based on config_entry."""
|
|
|
|
cntrl = hass.data[DOMAIN][entry.entry_id]['cntrl']
|
|
|
|
modules_data = hass.data[DOMAIN][entry.entry_id]['switch']
|
|
|
|
entities = []
|
|
|
|
for address, channel in modules_data:
|
|
|
|
module = cntrl.get_module(address)
|
|
|
|
entities.append(
|
|
|
|
VelbusSwitch(module, channel))
|
|
|
|
async_add_entities(entities)
|
2017-07-26 12:03:29 +00:00
|
|
|
|
|
|
|
|
2018-08-05 08:47:17 +00:00
|
|
|
class VelbusSwitch(VelbusEntity, SwitchDevice):
|
2017-07-26 12:03:29 +00:00
|
|
|
"""Representation of a switch."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
|
|
|
"""Return true if the switch is on."""
|
2018-08-05 08:47:17 +00:00
|
|
|
return self._module.is_on(self._channel)
|
2017-07-26 12:03:29 +00:00
|
|
|
|
|
|
|
def turn_on(self, **kwargs):
|
|
|
|
"""Instruct the switch to turn on."""
|
2018-08-05 08:47:17 +00:00
|
|
|
self._module.turn_on(self._channel)
|
2017-07-26 12:03:29 +00:00
|
|
|
|
|
|
|
def turn_off(self, **kwargs):
|
|
|
|
"""Instruct the switch to turn off."""
|
2018-08-05 08:47:17 +00:00
|
|
|
self._module.turn_off(self._channel)
|