Skip to content

[tuya] Add support for protocol version 3.5#626

Merged
J-N-K merged 3 commits intosmarthomej:5.0.xfrom
CyborgAndy:5.0.x-tuya-add-protocol-v35
May 4, 2025
Merged

[tuya] Add support for protocol version 3.5#626
J-N-K merged 3 commits intosmarthomej:5.0.xfrom
CyborgAndy:5.0.x-tuya-add-protocol-v35

Conversation

@CyborgAndy
Copy link
Contributor

Closes #603

Signed-off-by: Andriy Yemets <cyborg.andy@gmail.com>
@CyborgAndy CyborgAndy requested a review from J-N-K as a code owner May 4, 2025 12:39
Copy link
Member

@J-N-K J-N-K left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise LGTM

} else {
byte[] decodedMessage = protocol == V3_4 ? CryptoUtil.decryptAesEcb(payload, sessionKey, true)
: CryptoUtil.decryptAesEcb(payload, sessionKey, false);
byte[] decodedMessage = protocol == V3_5 ? CryptoUtil.decryptAesGcm(payload, sessionKey, header, null) : protocol == V3_4 ? CryptoUtil.decryptAesEcb(payload, sessionKey, true) : CryptoUtil.decryptAesEcb(payload, sessionKey, false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's really hard to read. What do you think of using an enhanced switch statement?

byte[] decodedMessage = switch (protocol) {
    case V3_5 -> CryptoUtil.decryptAesGcm(payload, sessionKey, header, null);
    case V3_4 -> CryptoUtil.decryptAesEcb(payload, sessionKey, true);
    default -> CryptoUtil.decryptAesEcb(payload, sessionKey, false);
}

}

Optional<byte[]> bufferOptional = protocol == V3_4 ? encode34(msg.commandType, payloadBytes, sessionKey)
Optional<byte[]> bufferOptional = protocol == V3_5 ? encode35(msg.commandType, payloadBytes, sessionKey) : protocol == V3_4 ? encode34(msg.commandType, payloadBytes, sessionKey)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

@J-N-K
Copy link
Member

J-N-K commented May 4, 2025

Please also run mvn spotless:apply

CyborgAndy added 2 commits May 4, 2025 17:10
Signed-off-by: Andriy Yemets <cyborg.andy@gmail.com>
Signed-off-by: Andriy Yemets <cyborg.andy@gmail.com>
Copy link
Member

@J-N-K J-N-K left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@J-N-K J-N-K merged commit f968aaf into smarthomej:5.0.x May 4, 2025
2 checks passed
J-N-K pushed a commit that referenced this pull request May 4, 2025
* [tuya] Add support for protocol version 3.5

Signed-off-by: Andriy Yemets <cyborg.andy@gmail.com>

* [tuya] Fix long ternary operators

Signed-off-by: Andriy Yemets <cyborg.andy@gmail.com>

* [tuya] Apply spotless

Signed-off-by: Andriy Yemets <cyborg.andy@gmail.com>

---------

Signed-off-by: Andriy Yemets <cyborg.andy@gmail.com>
J-N-K pushed a commit that referenced this pull request May 4, 2025
* [tuya] Add support for protocol version 3.5

Signed-off-by: Andriy Yemets <cyborg.andy@gmail.com>

* [tuya] Fix long ternary operators

Signed-off-by: Andriy Yemets <cyborg.andy@gmail.com>

* [tuya] Apply spotless

Signed-off-by: Andriy Yemets <cyborg.andy@gmail.com>

---------

Signed-off-by: Andriy Yemets <cyborg.andy@gmail.com>
@CyborgAndy CyborgAndy deleted the 5.0.x-tuya-add-protocol-v35 branch July 11, 2025 20:00
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.

TUYA, missing protocol version: 3.5 for new Q3-2024 tuya devices

2 participants