mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
zha: catch the exception from bellows if a device isn't available. (#13314)
* catch the exception from bellows if a device isn't available. * fix import of zigpy exception * fix lint import
This commit is contained in:
parent
2bc7e58780
commit
f287955422
@ -5,7 +5,6 @@ For more details on this platform, please refer to the documentation
|
|||||||
at https://home-assistant.io/components/light.zha/
|
at https://home-assistant.io/components/light.zha/
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.components import light, zha
|
from homeassistant.components import light, zha
|
||||||
from homeassistant.const import STATE_UNKNOWN
|
from homeassistant.const import STATE_UNKNOWN
|
||||||
import homeassistant.util.color as color_util
|
import homeassistant.util.color as color_util
|
||||||
@ -112,14 +111,25 @@ class Light(zha.Entity, light.Light):
|
|||||||
self._state = 1
|
self._state = 1
|
||||||
self.async_schedule_update_ha_state()
|
self.async_schedule_update_ha_state()
|
||||||
return
|
return
|
||||||
|
from zigpy.exceptions import DeliveryError
|
||||||
|
try:
|
||||||
await self._endpoint.on_off.on()
|
await self._endpoint.on_off.on()
|
||||||
|
except DeliveryError as ex:
|
||||||
|
_LOGGER.error("Unable to turn the light on: %s", ex)
|
||||||
|
return
|
||||||
|
|
||||||
self._state = 1
|
self._state = 1
|
||||||
self.async_schedule_update_ha_state()
|
self.async_schedule_update_ha_state()
|
||||||
|
|
||||||
async def async_turn_off(self, **kwargs):
|
async def async_turn_off(self, **kwargs):
|
||||||
"""Turn the entity off."""
|
"""Turn the entity off."""
|
||||||
|
from zigpy.exceptions import DeliveryError
|
||||||
|
try:
|
||||||
await self._endpoint.on_off.off()
|
await self._endpoint.on_off.off()
|
||||||
|
except DeliveryError as ex:
|
||||||
|
_LOGGER.error("Unable to turn the light off: %s", ex)
|
||||||
|
return
|
||||||
|
|
||||||
self._state = 0
|
self._state = 0
|
||||||
self.async_schedule_update_ha_state()
|
self.async_schedule_update_ha_state()
|
||||||
|
|
||||||
|
@ -57,12 +57,24 @@ class Switch(zha.Entity, SwitchDevice):
|
|||||||
|
|
||||||
async def async_turn_on(self, **kwargs):
|
async def async_turn_on(self, **kwargs):
|
||||||
"""Turn the entity on."""
|
"""Turn the entity on."""
|
||||||
|
from zigpy.exceptions import DeliveryError
|
||||||
|
try:
|
||||||
await self._endpoint.on_off.on()
|
await self._endpoint.on_off.on()
|
||||||
|
except DeliveryError as ex:
|
||||||
|
_LOGGER.error("Unable to turn the switch on: %s", ex)
|
||||||
|
return
|
||||||
|
|
||||||
self._state = 1
|
self._state = 1
|
||||||
|
|
||||||
async def async_turn_off(self, **kwargs):
|
async def async_turn_off(self, **kwargs):
|
||||||
"""Turn the entity off."""
|
"""Turn the entity off."""
|
||||||
|
from zigpy.exceptions import DeliveryError
|
||||||
|
try:
|
||||||
await self._endpoint.on_off.off()
|
await self._endpoint.on_off.off()
|
||||||
|
except DeliveryError as ex:
|
||||||
|
_LOGGER.error("Unable to turn the switch off: %s", ex)
|
||||||
|
return
|
||||||
|
|
||||||
self._state = 0
|
self._state = 0
|
||||||
|
|
||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user