mclarkk / lifxlan

Python library for accessing LIFX devices locally using the official LIFX LAN protocol.
MIT License
503 stars 115 forks source link

bitstring 4.x .CreationError: Token with length 64 packed with value of length 0 (bits:64=0). #173

Closed D-J-See closed 1 year ago

D-J-See commented 1 year ago

Hi. Just posting this incase anyone else experiences this. Got this error when trying pretty much anything after a container rebuild today:

`

from lifxlan import * print(LifxLAN().get_lights()) Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.9/site-packages/lifxlan/lifxlan.py", line 42, in get_lights self.discover_devices() File "/usr/local/lib/python3.9/site-packages/lifxlan/lifxlan.py", line 50, in discover_devices responses = self.broadcast_with_resp(GetService, StateService,) File "/usr/local/lib/python3.9/site-packages/lifxlan/lifxlan.py", line 234, in broadcast_with_resp msg = msg_type(BROADCAST_MAC, self.source_id, seq_num=0, payload=payload, ack_requested=False, response_requested=True) File "/usr/local/lib/python3.9/site-packages/lifxlan/msgtypes.py", line 19, in init super(GetService, self).init(MSG_IDS[GetService], target_addr, source_id, seq_num, ack_requested, response_requested) File "/usr/local/lib/python3.9/site-packages/lifxlan/message.py", line 43, in init self.packed_message = self.generate_packed_message() File "/usr/local/lib/python3.9/site-packages/lifxlan/message.py", line 47, in generate_packed_message self.header = self.get_header() File "/usr/local/lib/python3.9/site-packages/lifxlan/message.py", line 55, in get_header frame_addr = self.get_frame_addr() File "/usr/local/lib/python3.9/site-packages/lifxlan/message.py", line 80, in get_frame_addr mac_addr = little_endian(bitstring.pack(mac_addr_format, convert_MAC_to_int(self.target_addr))) File "/usr/local/lib/python3.9/site-packages/bitstring.py", line 4689, in pack s._addright(BitStream._init_with_token(name, length, value)) File "/usr/local/lib/python3.9/site-packages/bitstring.py", line 1435, in _init_with_token raise CreationError(f"Token with length {token_length} packed with value of length {b.len} " bitstring.CreationError: Token with length 64 packed with value of length 0 (bits:64=0). `

Due to bitstring major 4.x release, which has breaking changes. For now hardcode the bitstring version to 3.1.9 or ~3.1.

wdfrench13 commented 1 year ago

I had this issue present as a MemoryError when calling any function for a initiated lightbulb. Reverting to 3.1.9 fixed the issue for me. Thanks for sharing!

phalendj commented 1 year ago

Hi,

The issue is that lifxlan used a default behavior for bitstring where '64' is interpreted as 'uint:64'. v4.0.1 eliminated that default behavior. Going through msgtypes.py and messages.py and adding 'uint:' fixes the behavior.

D-J-See commented 1 year ago

Thanks @phalendj ! @exking Thanks for PR - spooky, after 5 weeks I just logged in to raise one myself :).