Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

function state fix and mode scene added #36

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
10 changes: 6 additions & 4 deletions pytuya/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,11 @@ def extract_payload(self,data):
start=data.find(b'{"devId')
if(start!=-1):
result = data[start:] #in 2 steps to deal with the case where '}}' is present before {"devId'
end=result.find(b'}}')+2
end=result.find(b'}}')
if(end==-1):
Copy link
Owner

Choose a reason for hiding this comment

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

👍 nice! I've not encountered this but this is definitely a hole you've plugged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not surprise that you did not encountered that case. Without the persistent socket this case should not occur like that. You probably observe something related. I suspect that the encoded status payload you got is probably not a complete payload but just the dps with the first key. In my understanding, this is sometimes send by the device (part of the protocol) and you got that message instead of the status.

return (True,data)
else:
end=end+2
result = result[:end]

#log.debug('result=%r', result)
Expand All @@ -303,14 +307,12 @@ def extract_payload(self,data):
return (False,result)

#encrypted data: incomplete dps {'devId': 'NUM', 'dps': {'1': bool}, 't': NUM, 's': NUM}
return(True,data)
return (True,data)

#start=data.find(PROTOCOL_VERSION_BYTES)
#if(start == -1): #if not found
# if(len(data)<=28):
# return (True,data) #no information from set command (data to small)
# #the data should be like that:
# #b'\x00\x00U\xaa\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x0c\x00\x00\x00\x00x\x93p\x91\x00\x00\xaaU'
# else:
# log.debug('Unexpected status() payload=%r', data)
# return (True,data)
Expand Down