Skip to content
This repository was archived by the owner on Nov 4, 2024. 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
14 changes: 7 additions & 7 deletions custom_components/robovac/tuyalocalapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def get_prefix_size_and_validate(self, command, encrypted_data):
version = (0, 0)
if version != self.version:
return 0
if version < (3, 3):
if version < (3, 1):
hash = encrypted_data[3:19].decode("ascii")
expected_hash = self.hash(encrypted_data[19:])
if hash != expected_hash:
Expand All @@ -381,7 +381,7 @@ def decrypt(self, command, data):
prefix_size = self.get_prefix_size_and_validate(command, data)
data = data[prefix_size:]
decryptor = self.cipher.decryptor()
if self.version < (3, 3):
if self.version < (3, 1):
data = base64.b64decode(data)
decrypted_data = decryptor.update(data)
decrypted_data += decryptor.finalize()
Expand All @@ -402,7 +402,7 @@ def encrypt(self, command, data):
encrypted_data += encryptor.finalize()

prefix = ".".join(map(str, self.version)).encode("utf8")
if self.version < (3, 3):
if self.version < (3, 1):
payload = base64.b64encode(encrypted_data)
hash = self.hash(payload)
prefix += hash.encode("utf8")
Expand Down Expand Up @@ -488,7 +488,7 @@ def bytes(self):
self.command,
payload_size,
)
if self.device and self.device.version >= (3, 3):
if self.device and self.device.version >= (3, 1):
checksum = crc(header + payload_data)
else:
checksum = crc(payload_data)
Expand Down Expand Up @@ -630,7 +630,7 @@ def __init__(
local_key=None,
port=6668,
gateway_id=None,
version=(3, 3),
version=(3, 1),
):
"""Initialize the device."""
self.device_id = device_id
Expand Down Expand Up @@ -694,7 +694,7 @@ async def async_disconnect(self):

async def async_get(self, callback=None):
payload = {"gwId": self.gateway_id, "devId": self.device_id}
maybe_self = None if self.version < (3, 3) else self
maybe_self = None if self.version < (3, 1) else self
message = Message(Message.GET_COMMAND, payload, encrypt_for=maybe_self)
return await message.async_send(self, callback)

Expand All @@ -710,7 +710,7 @@ def set(self, dps):
async def _async_ping(self, ping_interval):
# print("ping")
self.last_ping = time.time()
maybe_self = None if self.version < (3, 3) else self
maybe_self = None if self.version < (3, 1) else self
message = Message(Message.PING_COMMAND, sequence=0, encrypt_for=maybe_self)
await self._async_send(message)
await asyncio.sleep(ping_interval)
Expand Down