Skip to content

Commit

Permalink
Sets initial state based on default brightness level
Browse files Browse the repository at this point in the history
  • Loading branch information
jnimmo committed Apr 13, 2020
1 parent 4918968 commit 2d449bf
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions custom_components/dmx/light.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Home Assistant support for DMX lights over IP.
Date: 2019-03-03
Date: 2020-04-13
Homepage: https://github.com/jnimmo/hass-dmx
Author: James Nimmo
"""
Expand Down Expand Up @@ -202,10 +202,9 @@ def __init__(self, light, dmx_gateway, send_immediately, default_type):
# Brightness needs to be set to the maximum default RGB level, then
# scale up the RGB values to what HA uses
if self._rgb:
self._brightness = max(self._rgb)
self._rgb = scale_rgb_to_brightness(self._rgb, self._brightness)
self._brightness = max(self._rgb) * (self._brightness/255)

if self._brightness >= 0 or self._white_value >= 0:
if self._brightness > 0 or self._white_value > 0:
self._state = STATE_ON
else:
self._state = STATE_OFF
Expand Down Expand Up @@ -393,6 +392,9 @@ def async_turn_on(self, **kwargs):
# Update state from service call
if ATTR_BRIGHTNESS in kwargs:
self._brightness = kwargs[ATTR_BRIGHTNESS]

if self._brightness == 0:
self._brightness = 255

if ATTR_HS_COLOR in kwargs:
self._rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR])
Expand Down

0 comments on commit 2d449bf

Please sign in to comment.