hass-core/homeassistant/components/switch/velbus.py
Thomas Delaet 8a81ee3b4f Velbus auto-discovery (#13742)
* remove velbus fan and light platforms

these platforms should not be there since they can be created with template components based on switch platform

* use latest version of python-velbus which supports auto-discovery of modules

* fix linting errors

* fix linting errors

* fix linting errors

* address review comments from @MartinHjelmare

* update based on automatic feedback

* fix linting errors

* update dependency

* syntax corrections

* fix lint warning

* split out common functionality in VelbusEntity
use sync methods for loading platforms
support unique_ids so that entities are registred in entity registry

* fix linting errors

* fix linting errors

* fix linting errors

* integrate review comments (common functionality in VelbusEntity class)

* rename DOMAIN import to VELBUS_DOMAIN

* revert change created by requirements script

* regen
2018-08-05 10:47:17 +02:00

45 lines
1.3 KiB
Python

"""
Support for Velbus switches.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/switch.velbus/
"""
import logging
from homeassistant.components.switch import SwitchDevice
from homeassistant.components.velbus import (
DOMAIN as VELBUS_DOMAIN, VelbusEntity)
_LOGGER = logging.getLogger(__name__)
DEPENDENCIES = ['velbus']
async def async_setup_platform(hass, config, async_add_devices,
discovery_info=None):
"""Set up the Velbus Switch platform."""
if discovery_info is None:
return
switches = []
for switch in discovery_info:
module = hass.data[VELBUS_DOMAIN].get_module(switch[0])
channel = switch[1]
switches.append(VelbusSwitch(module, channel))
async_add_devices(switches)
class VelbusSwitch(VelbusEntity, SwitchDevice):
"""Representation of a switch."""
@property
def is_on(self):
"""Return true if the switch is on."""
return self._module.is_on(self._channel)
def turn_on(self, **kwargs):
"""Instruct the switch to turn on."""
self._module.turn_on(self._channel)
def turn_off(self, **kwargs):
"""Instruct the switch to turn off."""
self._module.turn_off(self._channel)