Make the velbus component more robust in handling errors (#25567)
* Add some try excepts for velbus as the python-velbus lib is not good in handling these * Only catch velbusExceptions * only wrap the lines that can cause the exception * Fix indentation mixup
This commit is contained in:
parent
67cae00caa
commit
15ae970941
4 changed files with 42 additions and 10 deletions
|
@ -7,6 +7,7 @@ import voluptuous as vol
|
|||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.const import CONF_PORT, CONF_NAME
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
|
||||
|
@ -54,8 +55,6 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
|
|||
"""Establish connection with velbus."""
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
|
||||
controller = velbus.Controller(entry.data[CONF_PORT])
|
||||
|
||||
def callback():
|
||||
modules = controller.get_modules()
|
||||
discovery_info = {
|
||||
|
@ -80,10 +79,18 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
|
|||
hass.config_entries.async_forward_entry_setup(
|
||||
entry, category))
|
||||
|
||||
try:
|
||||
controller = velbus.Controller(entry.data[CONF_PORT])
|
||||
controller.scan(callback)
|
||||
except velbus.util.VelbusException as err:
|
||||
_LOGGER.error('An error occurred: %s', err)
|
||||
raise ConfigEntryNotReady
|
||||
|
||||
def syn_clock(self, service=None):
|
||||
try:
|
||||
controller.sync_clock()
|
||||
except velbus.util.VelbusException as err:
|
||||
_LOGGER.error('An error occurred: %s', err)
|
||||
|
||||
hass.services.async_register(
|
||||
DOMAIN, 'sync_clock', syn_clock,
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
"""Support for Velbus thermostat."""
|
||||
import logging
|
||||
|
||||
from velbus.util import VelbusException
|
||||
|
||||
from homeassistant.components.climate import ClimateDevice
|
||||
from homeassistant.components.climate.const import (
|
||||
HVAC_MODE_HEAT, SUPPORT_TARGET_TEMPERATURE)
|
||||
|
@ -76,7 +78,11 @@ class VelbusClimate(VelbusEntity, ClimateDevice):
|
|||
temp = kwargs.get(ATTR_TEMPERATURE)
|
||||
if temp is None:
|
||||
return
|
||||
try:
|
||||
self._module.set_temp(temp)
|
||||
except VelbusException as err:
|
||||
_LOGGER.error('A Velbus error occurred: %s', err)
|
||||
return
|
||||
self.schedule_update_ha_state()
|
||||
|
||||
def set_hvac_mode(self, hvac_mode):
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
"""Support for Velbus covers."""
|
||||
import logging
|
||||
|
||||
from velbus.util import VelbusException
|
||||
|
||||
from homeassistant.components.cover import (
|
||||
CoverDevice, SUPPORT_CLOSE, SUPPORT_OPEN, SUPPORT_STOP)
|
||||
|
||||
|
@ -55,12 +57,21 @@ class VelbusCover(VelbusEntity, CoverDevice):
|
|||
|
||||
def open_cover(self, **kwargs):
|
||||
"""Open the cover."""
|
||||
try:
|
||||
self._module.open(self._channel)
|
||||
except VelbusException as err:
|
||||
_LOGGER.error('A Velbus error occurred: %s', err)
|
||||
|
||||
def close_cover(self, **kwargs):
|
||||
"""Close the cover."""
|
||||
try:
|
||||
self._module.close(self._channel)
|
||||
except VelbusException as err:
|
||||
_LOGGER.error('A Velbus error occurred: %s', err)
|
||||
|
||||
def stop_cover(self, **kwargs):
|
||||
"""Stop the cover."""
|
||||
try:
|
||||
self._module.stop(self._channel)
|
||||
except VelbusException as err:
|
||||
_LOGGER.error('A Velbus error occurred: %s', err)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
"""Support for Velbus switches."""
|
||||
import logging
|
||||
|
||||
from velbus.util import VelbusException
|
||||
|
||||
from homeassistant.components.switch import SwitchDevice
|
||||
|
||||
from . import VelbusEntity
|
||||
|
@ -37,8 +39,14 @@ class VelbusSwitch(VelbusEntity, SwitchDevice):
|
|||
|
||||
def turn_on(self, **kwargs):
|
||||
"""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)
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
"""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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue