Switch velbus from python-velbus to velbusaio (#54032)
* initial commit * use new release * Update for sensors * big update * pylint fixes, bump dependancy to 2021.8.2 * New version to try to fix the tests * Fix a lot of errors, bump version * more work * Bump version * Adde dimmer support * Make sure the counters are useable in the energy dashboard * bump version * Fix testcases * Update after review * Bump version to be able to have some decent exception catches, add the temperature device class * Readd the import of the platform from config file, but add a deprecation warning * More comments updated * Fix lefover index * Fix unique id to be backwards compatible * Fix small bug in covers * Fix testcases * Changes for theenery dashboard * Fixed services * Fix memo text * Make the interface for a service the port string instead of the device selector * Fix set_memo_text * added an async scan task, more comments * Accidently disabled some paltforms * More comments, bump version * Bump version, add extra attributes, enable mypy * Removed new features * More comments * Bump version * Update homeassistant/components/velbus/__init__.py Co-authored-by: brefra <frank_van_breugel@hotmail.com> * Readd the import step Co-authored-by: brefra <frank_van_breugel@hotmail.com>
This commit is contained in:
parent
1f997fcd58
commit
7472fb2049
14 changed files with 252 additions and 220 deletions
|
@ -1,7 +1,6 @@
|
|||
"""Support for Velbus switches."""
|
||||
import logging
|
||||
|
||||
from velbus.util import VelbusException
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.switch import SwitchEntity
|
||||
|
||||
|
@ -13,12 +12,11 @@ _LOGGER = logging.getLogger(__name__)
|
|||
|
||||
async def async_setup_entry(hass, entry, async_add_entities):
|
||||
"""Set up Velbus switch based on config_entry."""
|
||||
await hass.data[DOMAIN][entry.entry_id]["tsk"]
|
||||
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))
|
||||
for channel in cntrl.get_all("switch"):
|
||||
entities.append(VelbusSwitch(channel))
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
|
@ -26,20 +24,14 @@ class VelbusSwitch(VelbusEntity, SwitchEntity):
|
|||
"""Representation of a switch."""
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
def is_on(self) -> bool:
|
||||
"""Return true if the switch is on."""
|
||||
return self._module.is_on(self._channel)
|
||||
return self._channel.is_on()
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
"""Instruct the switch to turn on."""
|
||||
try:
|
||||
self._module.turn_on(self._channel)
|
||||
except VelbusException as err:
|
||||
_LOGGER.error("A Velbus error occurred: %s", err)
|
||||
await self._channel.turn_on()
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||
"""Instruct the switch to turn off."""
|
||||
try:
|
||||
self._module.turn_off(self._channel)
|
||||
except VelbusException as err:
|
||||
_LOGGER.error("A Velbus error occurred: %s", err)
|
||||
await self._channel.turn_off()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue