Skip to content

fix: more support for ZCL non-value #1424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

Nerivec
Copy link
Collaborator

@Nerivec Nerivec commented Jun 15, 2025

Add ZCL-specific wrappers to BuffaloZcl to handle non-values, per ZigBee spec.
Fixes Koenkk/zigbee2mqtt#27102

TODO:

  • Current behavior is to use NaN for number non-values (including boolean since using 0/1). This must be checked against uses, and support added where needed.
  • Update ZHC, can remove the valueIgnore param that was used to sparsely ignore these non-values.
  • zboss adapter uses BuffaloZcl for frame reading, this might break that... @kirovilya

CC: @oddlama

@@ -3776,7 +3776,7 @@ describe("Controller", () => {
"65281": {
"1": 3285,
"10": 0,
"100": 0,
"100": false,
Copy link
Owner

Choose a reason for hiding this comment

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

Also need to update the Aqara converters to be able to deal with this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I reverted this.
That change was a bit too dangerous (too much typing lacking in ZHC/ZCL payloads). We can do it in a separate PR if the need arises.

Copy link

codspeed-hq bot commented Jul 18, 2025

CodSpeed Performance Report

Merging #1424 will not alter performance

Comparing Nerivec:zcl-nonvalue (d9986d1) with master (7f47140)

Summary

✅ 12 untouched benchmarks

@Nerivec
Copy link
Collaborator Author

Nerivec commented Jul 18, 2025

For ZHC, I guess most of the code should hit:

Both of these should allow using Number.NaN to represent non-value.
The current workaround was to use value_ignore (due to lack of support at parser level), though it's only used in a couple places.

@Koenkk how do you think non-values should translate (ignore, push the equivalent of "N/A", etc.)? At least for tz, it should not ignore the request anymore.

Also have to deal with converters that are not using modern extend yet (haven't looked if any).

@Nerivec Nerivec requested a review from Copilot July 18, 2025 16:10
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances ZCL (ZigBee Cluster Library) support for handling non-values per the ZigBee specification. The main change involves implementing proper ZCL wrappers in BuffaloZcl to handle non-values using specific bit patterns (e.g., 0xFF for 8-bit types, 0xFFFF for 16-bit types) instead of allowing undefined values to pass through unchecked.

Key changes include:

  • Addition of ZCL-specific read/write methods that handle non-values using Number.NaN for numeric types and undefined for bigint types
  • Updated interface definitions to use Number.NaN instead of undefined for time/date fields
  • Comprehensive test coverage for non-value handling across all data types

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/zspec/zcl/buffaloZcl.ts Core implementation adding ZCL-specific wrappers for all data types with non-value support
src/zspec/zcl/definition/enums.ts Minor documentation clarification for ARRAY and STRUCT non-value formats
src/controller/greenPower.ts Type name updates from GPD* to Gpd* for consistency
test/zspec/zcl/buffalo.test.ts Extensive test additions covering non-value read/write operations and test fixes
test/zcl.test.ts Test updates to use Number.NaN instead of 255 for non-values and payload size fixes
test/greenpower.test.ts Removal of a test case that relied on invalid frame parsing

this.write(elTypeNumeric, element, {});
}
} else {
this.writeUInt8(DataType.NO_DATA); // XXX: correct value?
Copy link
Preview

Copilot AI Jul 18, 2025

Choose a reason for hiding this comment

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

The comment 'XXX: correct value?' indicates uncertainty about the implementation. This should be resolved by verifying the ZigBee specification for the correct element type to use when writing non-value arrays.

Suggested change
this.writeUInt8(DataType.NO_DATA); // XXX: correct value?
this.writeUInt8(DataType.UNKNOWN); // ZigBee spec: Use UNKNOWN for non-value arrays

Copilot uses AI. Check for mistakes.

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

Successfully merging this pull request may close these issues.

Unknown values (as specified by ZCL) are being converted to valid but nonsensical values
2 participants