Skip to content

Commit

Permalink
Discovery: skip decryption of broadcast message with UDP command (#95)
Browse files Browse the repository at this point in the history
* Fix climates platform definitions

* Skip decryption of broadcast messages with UDP command

* Should fix discovering 3.1 devices.
  • Loading branch information
presidentio committed Jan 4, 2024
1 parent b69b3bc commit 8f3ffe1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions custom_components/localtuya/core/tuya_devices/climates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion custom_components/localtuya/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Expand Down

0 comments on commit 8f3ffe1

Please sign in to comment.