Skip to content

Commit f12afe0

Browse files
committed
Ensure that the value passed to ws2811_led_set is an int
The caller can't cast this when value is a slice This matters when a Numpy array is being used. Signed-off-by: David Greaves <[email protected]>
1 parent 50cc48b commit f12afe0

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

library/rpi_ws281x/rpi_ws281x.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,13 @@ def __setitem__(self, pos, value):
110110
"""
111111
# Handle if a slice of positions are passed in by setting the appropriate
112112
# LED data values to the provided value.
113+
# Cast to int() as value may be a numpy non-int value.
113114
if isinstance(pos, slice):
114115
for n in range(*pos.indices(self.size)):
115-
ws.ws2811_led_set(self._channel, n, value)
116+
ws.ws2811_led_set(self._channel, n, int(value))
116117
# Else assume the passed in value is a number to the position.
117118
else:
118-
return ws.ws2811_led_set(self._channel, pos, value)
119+
return ws.ws2811_led_set(self._channel, pos, int(value))
119120

120121
def __len__(self):
121122
return ws.ws2811_channel_t_count_get(self._channel)

0 commit comments

Comments
 (0)