Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch exceptions for all commands sent light.zha.Light. #16752

Merged
merged 1 commit into from
Sep 20, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 43 additions & 16 deletions homeassistant/components/light/zha.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,40 +81,65 @@ def is_on(self) -> bool:

async def async_turn_on(self, **kwargs):
"""Turn the entity on."""
from zigpy.exceptions import DeliveryError

duration = kwargs.get(light.ATTR_TRANSITION, DEFAULT_DURATION)
duration = duration * 10 # tenths of s
if light.ATTR_COLOR_TEMP in kwargs:
temperature = kwargs[light.ATTR_COLOR_TEMP]
await self._endpoint.light_color.move_to_color_temp(
temperature, duration)
try:
res = await self._endpoint.light_color.move_to_color_temp(
temperature, duration)
_LOGGER.debug("%s: moved to %i color temp: %s",
self.entity_id, temperature, res)
except DeliveryError as ex:
_LOGGER.error("%s: Couldn't change color temp: %s",
self.entity_id, ex)
return
self._color_temp = temperature

if light.ATTR_HS_COLOR in kwargs:
self._hs_color = kwargs[light.ATTR_HS_COLOR]
xy_color = color_util.color_hs_to_xy(*self._hs_color)
await self._endpoint.light_color.move_to_color(
int(xy_color[0] * 65535),
int(xy_color[1] * 65535),
duration,
)
try:
res = await self._endpoint.light_color.move_to_color(
int(xy_color[0] * 65535),
int(xy_color[1] * 65535),
duration,
)
_LOGGER.debug("%s: moved XY color to (%1.2f, %1.2f): %s",
self.entity_id, xy_color[0], xy_color[1], res)
except DeliveryError as ex:
_LOGGER.error("%s: Couldn't change color temp: %s",
self.entity_id, ex)
return

if self._brightness is not None:
brightness = kwargs.get(
light.ATTR_BRIGHTNESS, self._brightness or 255)
self._brightness = brightness
# Move to level with on/off:
await self._endpoint.level.move_to_level_with_on_off(
brightness,
duration
)
try:
res = await self._endpoint.level.move_to_level_with_on_off(
brightness,
duration
)
_LOGGER.debug("%s: moved to %i level with on/off: %s",
self.entity_id, brightness, res)
except DeliveryError as ex:
_LOGGER.error("%s: Couldn't change brightness level: %s",
self.entity_id, ex)
return
self._state = 1
self.async_schedule_update_ha_state()
return
from zigpy.exceptions import DeliveryError

try:
await self._endpoint.on_off.on()
res = await self._endpoint.on_off.on()
_LOGGER.debug("%s was turned on: %s", self.entity_id, res)
except DeliveryError as ex:
_LOGGER.error("Unable to turn the light on: %s", ex)
_LOGGER.error("%s: Unable to turn the light on: %s",
self.entity_id, ex)
return

self._state = 1
Expand All @@ -124,9 +149,11 @@ async def async_turn_off(self, **kwargs):
"""Turn the entity off."""
from zigpy.exceptions import DeliveryError
try:
await self._endpoint.on_off.off()
res = await self._endpoint.on_off.off()
_LOGGER.debug("%s was turned off: %s", self.entity_id, res)
except DeliveryError as ex:
_LOGGER.error("Unable to turn the light off: %s", ex)
_LOGGER.error("%s: Unable to turn the light off: %s",
self.entity_id, ex)
return

self._state = 0
Expand Down