light.yeelight: catch i/o related exceptions from the backend lib (#6952)
Fixes/mitigates problems with #5949 and #6624
This commit is contained in:
parent
0bb224d8c7
commit
6d8af58891
1 changed files with 38 additions and 12 deletions
|
@ -255,7 +255,8 @@ class YeelightLight(Light):
|
|||
def set_flash(self, flash) -> None:
|
||||
"""Activate flash."""
|
||||
if flash:
|
||||
from yeelight import RGBTransition, SleepTransition, Flow
|
||||
from yeelight import (RGBTransition, SleepTransition, Flow,
|
||||
BulbException)
|
||||
if self._bulb.last_properties["color_mode"] != 1:
|
||||
_LOGGER.error("Flash supported currently only in RGB mode.")
|
||||
return
|
||||
|
@ -280,10 +281,14 @@ class YeelightLight(Light):
|
|||
duration=duration))
|
||||
|
||||
flow = Flow(count=count, transitions=transitions)
|
||||
self._bulb.start_flow(flow)
|
||||
try:
|
||||
self._bulb.start_flow(flow)
|
||||
except BulbException as ex:
|
||||
_LOGGER.error("Unable to set flash: %s", ex)
|
||||
|
||||
def turn_on(self, **kwargs) -> None:
|
||||
"""Turn the bulb on."""
|
||||
import yeelight
|
||||
brightness = kwargs.get(ATTR_BRIGHTNESS)
|
||||
colortemp = kwargs.get(ATTR_COLOR_TEMP)
|
||||
rgb = kwargs.get(ATTR_RGB_COLOR)
|
||||
|
@ -293,22 +298,43 @@ class YeelightLight(Light):
|
|||
if ATTR_TRANSITION in kwargs: # passed kwarg overrides config
|
||||
duration = int(kwargs.get(ATTR_TRANSITION) * 1000) # kwarg in s
|
||||
|
||||
self._bulb.turn_on(duration=duration)
|
||||
try:
|
||||
self._bulb.turn_on(duration=duration)
|
||||
except yeelight.BulbException as ex:
|
||||
_LOGGER.error("Unable to turn the bulb on: %s", ex)
|
||||
return
|
||||
|
||||
if self.config[CONF_MODE_MUSIC] and not self._bulb.music_mode:
|
||||
self.set_music_mode(self.config[CONF_MODE_MUSIC])
|
||||
try:
|
||||
self.set_music_mode(self.config[CONF_MODE_MUSIC])
|
||||
except yeelight.BulbException as ex:
|
||||
_LOGGER.error("Unable to turn on music mode,"
|
||||
"consider disabling it: %s", ex)
|
||||
|
||||
# values checked for none in methods
|
||||
self.set_rgb(rgb, duration)
|
||||
self.set_colortemp(colortemp, duration)
|
||||
self.set_brightness(brightness, duration)
|
||||
self.set_flash(flash)
|
||||
try:
|
||||
# values checked for none in methods
|
||||
self.set_rgb(rgb, duration)
|
||||
self.set_colortemp(colortemp, duration)
|
||||
self.set_brightness(brightness, duration)
|
||||
self.set_flash(flash)
|
||||
except yeelight.BulbException as ex:
|
||||
_LOGGER.error("Unable to set bulb properties: %s", ex)
|
||||
return
|
||||
|
||||
# save the current state if we had a manual change.
|
||||
if self.config[CONF_SAVE_ON_CHANGE]:
|
||||
if brightness or colortemp or rgb:
|
||||
if self.config[CONF_SAVE_ON_CHANGE] and (brightness
|
||||
or colortemp
|
||||
or rgb):
|
||||
try:
|
||||
self.set_default()
|
||||
except yeelight.BulbException as ex:
|
||||
_LOGGER.error("Unable to set the defaults: %s", ex)
|
||||
return
|
||||
|
||||
def turn_off(self, **kwargs) -> None:
|
||||
"""Turn off."""
|
||||
self._bulb.turn_off()
|
||||
import yeelight
|
||||
try:
|
||||
self._bulb.turn_off()
|
||||
except yeelight.BulbException as ex:
|
||||
_LOGGER.error("Unable to turn the bulb off: %s", ex)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue