Skip to content

Commit 234fd10

Browse files
committed
ButtonPacket did not work in CPython
1 parent c3d29b3 commit 234fd10

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

adafruit_bluefruit_connect/button_packet.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ def __init__(self, button, pressed):
5555
# This check will catch wrong length and also non-sequence args (like an int).
5656
try:
5757
assert len(button) == 1
58+
assert isinstance(button, str)
5859
except Exception as err:
59-
raise ValueError("Button must be a single char or byte.") from err
60+
raise ValueError("Button must be a single char.") from err
6061

6162
self._button = button
6263
self._pressed = pressed
@@ -77,7 +78,7 @@ def to_bytes(self):
7778
partial_packet = struct.pack(
7879
self._FMT_CONSTRUCT,
7980
self._TYPE_HEADER,
80-
self._button,
81+
bytes(self._button, "utf-8"),
8182
b"1" if self._pressed else b"0",
8283
)
8384
return self.add_checksum(partial_packet)

0 commit comments

Comments
 (0)