Skip to content

Commit

Permalink
fix(LiteFamily): split packets to chunks in the right way
Browse files Browse the repository at this point in the history
Fix #37
  • Loading branch information
IATkachenko committed Jul 8, 2022
1 parent 4282e4e commit 499cb1f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions tion_btle/light_family.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,20 @@ def chunks(lst, n):
for j in range(0, len(lst), n):
yield lst[j:j + n]

request.pop()

if len(request) < 20:
request[0] = self.SINGLE_PACKET_ID
request.insert(0, self.SINGLE_PACKET_ID)
return [request]

request[0] = self.FIRST_PACKET_ID
result = list(chunks(request, 20))
result = list(chunks(request, 19))

for i in range(1, len(result)):
if i == len(result)-1:
for i in range(0, len(result)):
if i == 0: # First packet
result[i].insert(0, self.FIRST_PACKET_ID)
elif i == len(result)-1: # Last packet
result[i].insert(0, self.END_PACKET_ID)
else:
else: # Middle packets
result[i].insert(0, self.MIDDLE_PACKET_ID)

return result
Expand Down

0 comments on commit 499cb1f

Please sign in to comment.