diff --git a/pytuya/__init__.py b/pytuya/__init__.py index 8036bd4..42d5653 100644 --- a/pytuya/__init__.py +++ b/pytuya/__init__.py @@ -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' @@ -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): @@ -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): @@ -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 @@ -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)