From 8f3ffe14b787c09e17f212d37f9461e2dd3fc376 Mon Sep 17 00:00:00 2001 From: Vitalii Herhel Date: Fri, 5 Jan 2024 01:06:20 +0200 Subject: [PATCH] Discovery: skip decryption of broadcast message with UDP command (#95) * Fix climates platform definitions * Skip decryption of broadcast messages with UDP command * Should fix discovering 3.1 devices. --- custom_components/localtuya/core/tuya_devices/climates.py | 4 ++-- custom_components/localtuya/discovery.py | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/custom_components/localtuya/core/tuya_devices/climates.py b/custom_components/localtuya/core/tuya_devices/climates.py index 4af3dec0e..3fdde75d4 100644 --- a/custom_components/localtuya/core/tuya_devices/climates.py +++ b/custom_components/localtuya/core/tuya_devices/climates.py @@ -80,7 +80,7 @@ def localtuya_climate( values_precsion=0.1, target_precision=0.1, ), - ) + ), ), # Heater # https://developer.tuya.com/en/docs/iot/f?id=K9gf46epy4j82 @@ -98,7 +98,7 @@ def localtuya_climate( target_precision=0.1, preset_set="auto/smart", ), - ) + ), ), # Heater # https://developer.tuya.com/en/docs/iot/categoryrs?id=Kaiuz0nfferyx diff --git a/custom_components/localtuya/discovery.py b/custom_components/localtuya/discovery.py index 181be424b..a6fc01831 100644 --- a/custom_components/localtuya/discovery.py +++ b/custom_components/localtuya/discovery.py @@ -23,6 +23,7 @@ PREFIX_55AA_BIN = b"\x00\x00U\xaa" PREFIX_6699_BIN = b"\x00\x00\x66\x99" +UDP_COMMAND = b"\x00\x00\x00\x00" DEFAULT_TIMEOUT = 6.0 @@ -37,7 +38,10 @@ def _unpad(data): def decrypt_udp(message): """Decrypt encrypted UDP broadcasts.""" if message[:4] == PREFIX_55AA_BIN: - return decrypt(message[20:-8], UDP_KEY) + payload = message[20:-8] + if message[8:12] == UDP_COMMAND: + return payload + return decrypt(payload, UDP_KEY) if message[:4] == PREFIX_6699_BIN: unpacked = pytuya.unpack_message(message, hmac_key=UDP_KEY, no_retcode=None) payload = unpacked.payload.decode()