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

Fix crash for unsupported dimension events #145

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
22 changes: 13 additions & 9 deletions custom_components/myhome/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,16 @@ def handle_event(self, message: OWNLightingEvent):
self._gateway_handler.log_id,
message.human_readable_log,
)
self._attr_is_on = message.is_on
if ColorMode.BRIGHTNESS in self._attr_supported_color_modes and message.brightness is not None:
self._attr_brightness_pct = message.brightness
self._attr_brightness = percent_to_eight_bits(message.brightness)

if self._off_icon is not None and self._on_icon is not None:
self._attr_icon = self._on_icon if self._attr_is_on else self._off_icon

self.async_schedule_update_ha_state()
#This should be in try block as message.is_on can throw error for unsupported message types (like for some dimensions)
try:
self._attr_is_on = message.is_on
if ColorMode.BRIGHTNESS in self._attr_supported_color_modes and message.brightness is not None:
self._attr_brightness_pct = message.brightness
self._attr_brightness = percent_to_eight_bits(message.brightness)

if self._off_icon is not None and self._on_icon is not None:
self._attr_icon = self._on_icon if self._attr_is_on else self._off_icon

self.async_schedule_update_ha_state()
except TypeError:
pass