Skip to content
This repository was archived by the owner on Sep 4, 2021. It is now read-only.
Open
Changes from all commits
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
11 changes: 8 additions & 3 deletions pytuya/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import pyaes # https://github.com/ricmoo/pyaes


version_tuple = (7, 0, 6)
version_tuple = (7, 0, 4)
version = version_string = __version__ = '%d.%d.%d' % version_tuple
__author__ = 'clach04'

Expand All @@ -51,6 +51,9 @@
PROTOCOL_VERSION_BYTES_31 = b'3.1'
PROTOCOL_VERSION_BYTES_33 = b'3.3'

PROTOCOL_VERSION_3_1 = 3.1
PROTOCOL_VERSION_3_3 = 3.3

IS_PY2 = sys.version_info[0] == 2

class AESCipher(object):
Expand Down Expand Up @@ -181,6 +184,8 @@ def _send_receive(self, payload):
return data

def set_version(self, version):
if (version != PROTOCOL_VERSION_3_1) and (version != PROTOCOL_VERSION_3_3):
raise ValueError("Unsupported verison")
self.version = version

def generate_payload(self, command, data=None):
Expand Down Expand Up @@ -214,7 +219,7 @@ def generate_payload(self, command, data=None):
json_payload = json_payload.encode('utf-8')
log.debug('json_payload=%r', json_payload)

if self.version == 3.3:
if self.version == PROTOCOL_VERSION_3_3:
self.cipher = AESCipher(self.local_key) # expect to connect and then disconnect to set new
json_payload = self.cipher.encrypt(json_payload, False)
self.cipher = None
Expand Down Expand Up @@ -302,7 +307,7 @@ def status(self):
if not isinstance(result, str):
result = result.decode()
result = json.loads(result)
elif self.version == 3.3:
elif self.version == PROTOCOL_VERSION_3_3:
cipher = AESCipher(self.local_key)
result = cipher.decrypt(result, False)
log.debug('decrypted result=%r', result)
Expand Down