Skip to content

refactor Tuya decoding cluster 0xef00#1982

Open
pipiche38 wants to merge 2 commits into
stable8from
refactor/tuya-ts0601-decoding
Open

refactor Tuya decoding cluster 0xef00#1982
pipiche38 wants to merge 2 commits into
stable8from
refactor/tuya-ts0601-decoding

Conversation

@pipiche38

@pipiche38 pipiche38 commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes the decoding of the Tuya 0xEF00 (TS0601) manufacturer-specific cluster
in tuyaReadRawAPS, and adds
unit-test coverage for the function.

Background

The 0xEF00 cluster delivers device datapoints (DPs) through several commands. In
both reference projects, commands 0x01 (dataResponse), 0x02 (dataReport),
0x05 (activeStatusReport) and 0x06 (activeStatusReportAlt) share the same
body layout
: status (uint8) + transid (uint8) followed by a list of
datapoints, each encoded as dp (uint8) + datatype (uint8) + len (uint16) +
data.

The previous implementation handled only 0x01/0x02 properly.

Problems fixed

Issue Before After
0x05 activeStatusReport Fell through to UNMANAGED, datapoints dropped Decoded like 0x01/0x02
0x06 activeStatusReportAlt Parsed a single, mis-read DP (the 2-byte length was read as a phantom byte + 1-byte length; loop never iterated) Decoded as a full datapoint list
Manufacturer-specific frames (FCF bit 2 set) Manuf code shifted the payload → 0x02 mis-read as 0x00, datapoints corrupted (e.g. Excellux NTCHT01) 2-byte manuf code stripped so standard offsets stay valid
Default response on manuf frames Manuf code not propagated tuya_default_response forwards the code (logical byte order, matching Modules/tools_fcf.py)

Changes

  • Modules/tuya.py
    • Merged 0x01/0x02/0x05/0x06 into one datapoint-parsing loop, bounded by idx + 8 <= len(MsgPayload) to tolerate truncated trailing fragments.
    • Detect manufacturer-specific frames (FCF & 0x04), extract the manufacturer code in logical/big-endian order, and strip it from the payload before parsing.
    • tuya_default_response() now accepts and forwards manuf_code to zcl_raw_default_response(..., manufcode=...).
  • tests/Modules/test_tuya.py (new) — 24 tests covering command demux, single/multi datapoint parsing for 0x01/0x02/0x05/0x06, manufacturer-specific frames, MCU version (0x11), time sync (0x24), gateway status (0x25), no-op commands, and the UNMANAGED fallthrough.

Testing

  • python -m py_compile Modules/tuya.py
  • pytest tests/Modules/test_tuya.py24 passed
  • pytest tests/1187 passed
  • flake8 ... --select=E9,F63,F7,F820

Compatibility

No persistent data-format or configuration changes. Behaviour for 0x01/0x02
is unchanged; 0x05/0x06 and manufacturer-specific frames are now decoded
correctly rather than dropped or corrupted. Backward compatible with stable8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant