mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
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
9254e7e862
commit
d952a07658
@ -255,7 +255,8 @@ class YeelightLight(Light):
|
|||||||
def set_flash(self, flash) -> None:
|
def set_flash(self, flash) -> None:
|
||||||
"""Activate flash."""
|
"""Activate flash."""
|
||||||
if flash:
|
if flash:
|
||||||
from yeelight import RGBTransition, SleepTransition, Flow
|
from yeelight import (RGBTransition, SleepTransition, Flow,
|
||||||
|
BulbException)
|
||||||
if self._bulb.last_properties["color_mode"] != 1:
|
if self._bulb.last_properties["color_mode"] != 1:
|
||||||
_LOGGER.error("Flash supported currently only in RGB mode.")
|
_LOGGER.error("Flash supported currently only in RGB mode.")
|
||||||
return
|
return
|
||||||
@ -280,10 +281,14 @@ class YeelightLight(Light):
|
|||||||
duration=duration))
|
duration=duration))
|
||||||
|
|
||||||
flow = Flow(count=count, transitions=transitions)
|
flow = Flow(count=count, transitions=transitions)
|
||||||
|
try:
|
||||||
self._bulb.start_flow(flow)
|
self._bulb.start_flow(flow)
|
||||||
|
except BulbException as ex:
|
||||||
|
_LOGGER.error("Unable to set flash: %s", ex)
|
||||||
|
|
||||||
def turn_on(self, **kwargs) -> None:
|
def turn_on(self, **kwargs) -> None:
|
||||||
"""Turn the bulb on."""
|
"""Turn the bulb on."""
|
||||||
|
import yeelight
|
||||||
brightness = kwargs.get(ATTR_BRIGHTNESS)
|
brightness = kwargs.get(ATTR_BRIGHTNESS)
|
||||||
colortemp = kwargs.get(ATTR_COLOR_TEMP)
|
colortemp = kwargs.get(ATTR_COLOR_TEMP)
|
||||||
rgb = kwargs.get(ATTR_RGB_COLOR)
|
rgb = kwargs.get(ATTR_RGB_COLOR)
|
||||||
@ -293,22 +298,43 @@ class YeelightLight(Light):
|
|||||||
if ATTR_TRANSITION in kwargs: # passed kwarg overrides config
|
if ATTR_TRANSITION in kwargs: # passed kwarg overrides config
|
||||||
duration = int(kwargs.get(ATTR_TRANSITION) * 1000) # kwarg in s
|
duration = int(kwargs.get(ATTR_TRANSITION) * 1000) # kwarg in s
|
||||||
|
|
||||||
|
try:
|
||||||
self._bulb.turn_on(duration=duration)
|
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:
|
if self.config[CONF_MODE_MUSIC] and not self._bulb.music_mode:
|
||||||
|
try:
|
||||||
self.set_music_mode(self.config[CONF_MODE_MUSIC])
|
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)
|
||||||
|
|
||||||
|
try:
|
||||||
# values checked for none in methods
|
# values checked for none in methods
|
||||||
self.set_rgb(rgb, duration)
|
self.set_rgb(rgb, duration)
|
||||||
self.set_colortemp(colortemp, duration)
|
self.set_colortemp(colortemp, duration)
|
||||||
self.set_brightness(brightness, duration)
|
self.set_brightness(brightness, duration)
|
||||||
self.set_flash(flash)
|
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.
|
# save the current state if we had a manual change.
|
||||||
if self.config[CONF_SAVE_ON_CHANGE]:
|
if self.config[CONF_SAVE_ON_CHANGE] and (brightness
|
||||||
if brightness or colortemp or rgb:
|
or colortemp
|
||||||
|
or rgb):
|
||||||
|
try:
|
||||||
self.set_default()
|
self.set_default()
|
||||||
|
except yeelight.BulbException as ex:
|
||||||
|
_LOGGER.error("Unable to set the defaults: %s", ex)
|
||||||
|
return
|
||||||
|
|
||||||
def turn_off(self, **kwargs) -> None:
|
def turn_off(self, **kwargs) -> None:
|
||||||
"""Turn off."""
|
"""Turn off."""
|
||||||
|
import yeelight
|
||||||
|
try:
|
||||||
self._bulb.turn_off()
|
self._bulb.turn_off()
|
||||||
|
except yeelight.BulbException as ex:
|
||||||
|
_LOGGER.error("Unable to turn the bulb off: %s", ex)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user