hass-core/homeassistant/components/velbus/switch.py
Maikel Punie 1f9f201571 Enable velbus config entries (#25308)
* Initial work on config_flow

* Finish config flow

* Pylint checks, make sure the import only happens once

* Added support for unloading, small fixes

* Check in the hassfest output files

* Flake8 fixes

* pylint mistake after flake8 fixes

* Work on comments

* Abort the import if it is already imported

* More comments resolved

* Added testcases for velbus config flow

* Fix pylint and flake8

* Added connection test to the config flow

* More sugestions

* renamed the abort reason

* excluded all but the config_flow.py from the velbus component in coveragerc

* Rewrote testcases with a patched version of _test_connection

* Docstyle fixes

* Updated the velbus testcases

* just yield

* flake8 fixes
2019-07-29 09:21:26 +02:00

44 lines
1.2 KiB
Python

"""Support for Velbus switches."""
import logging
from homeassistant.components.switch import SwitchDevice
from . import VelbusEntity
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
async def async_setup_platform(
hass, config, async_add_entities, discovery_info=None):
"""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)
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)