Skip to content
This repository has been archived by the owner on Jun 16, 2024. It is now read-only.

Fix TypeError issue; send zeroes for RGB/W if dimmer is zero; improve logging #38

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.project
/.pydevproject
19 changes: 11 additions & 8 deletions custom_components/dmx/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,18 +323,21 @@ def dmx_values(self):
return color_rgb_to_rgbw(*scaled_rgb)
elif self._type == CONF_LIGHT_TYPE_DRGB:
drgb = [self._brightness]
drgb.extend(self._rgb)
drgb.extend(self._rgb if self._brightness > 0 else [0, 0, 0])
_LOGGER.debug("drgb: " + ', '.join([str(x) for x in drgb]));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Ruth, sorry for the delay in getting to this. Can you help me understand why the RGB values should be zeroed for these lights? In my mind that's what the dimmer channel is there for.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was probably me being paranoid in the DRGB case then; however it won't do any harm for the RGB values to be zero if the dimmer channel is also zero, as the end result will be no light output either way.

return drgb
elif self._type == CONF_LIGHT_TYPE_DRGBW:
drgbw = [self._brightness]
drgbw.extend(self._rgb)
drgbw.append(self._white_value)
drgbw.extend(self._rgb if self._brightness > 0 else [0, 0, 0])
drgbw.append(self._white_value if self.brightness > 0 else 0)
_LOGGER.debug("drgbw: " + ', '.join([str(x) for x in drgbw]));
return drgbw
elif self._type == CONF_LIGHT_TYPE_RGBWD:
rgbwd = list()
rgbwd.extend(self._rgb)
rgbwd.append(self._white_value)
rgbwd.extend(self._rgb if self._brightness > 0 else [0, 0, 0])
rgbwd.append(self._white_value if self._brightness > 0 else 0)
rgbwd.append(self._brightness)
_LOGGER.debug("rgbwd: " + ', '.join([str(x) for x in rgbwd]));
return rgbwd
elif self._type == CONF_LIGHT_TYPE_SWITCH:
if self.is_on:
Expand Down Expand Up @@ -469,7 +472,7 @@ def __init__(self, host, universe, port, default_level,
self._number_of_channels += 1

# Initialise the DMX channel array with the default values
self._channels = [self._default_level] * self._number_of_channels
self._channels = [int(self._default_level)] * self._number_of_channels

# Initialise socket
self._socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
Expand All @@ -492,7 +495,7 @@ def send(self):
packet = self._base_packet[:]
packet.extend(self._channels)
self._socket.sendto(packet, (self._host, self._port))
_LOGGER.debug("Sending Art-Net frame")
_LOGGER.debug("Sending Art-Net frame to " + self._host + ":" + str(self._port) + " - " + ', '.join([str(x) for x in packet]));

def set_channels(self, channels, value, send_immediately=True):
# Single value for standard channels, RGB channels will have 3 or more
Expand All @@ -502,7 +505,7 @@ def set_channels(self, channels, value, send_immediately=True):

for x, channel in enumerate(channels):
default_value = value_arr[min(x, len(value_arr) - 1)]
self._channels[channel-1] = default_value
self._channels[channel-1] = int(default_value)

if send_immediately:
self.send()
Expand Down