Skip to content

Cluster Attribute with ID 0x0000 is not supported if the attribute type is DataTypes.string #145

@dfischer0

Description

@dfischer0

You cannot create a Cluster attribute with an ID = 0x0000 and a type of DataTypes.string. If you do, you get an error during startup:

    at new NodeError (node:internal/errors:405:5)
    at boundsError (node:internal/buffer:88:9)
    at Buffer.readUInt8 (node:internal/buffer:254:5)
    at Buffer.readUIntLE (node:internal/buffer:184:17)
    at DataType.utf8StringFromBuf [as fromBuffer] (/app/node_modules/@athombv/data-types/lib/DataTypes.js:307:20)
    at DataType.fromBuf [as fromBuffer] (/app/node_modules/zigbee-clusters/lib/zclFrames.js:72:30)
    at new DataType (/app/node_modules/@athombv/data-types/lib/DataType.js:20:30)
    at ZCLAttributeDataRecord (/app/node_modules/zigbee-clusters/lib/zclFrames.js:35:60)
    at Cluster._addPrototypeMethods (/app/node_modules/zigbee-clusters/lib/Cluster.js:1003:7)
    at Cluster.addCluster (/app/node_modules/zigbee-clusters/lib/Cluster.js:922:10) {
  code: 'ERR_OUT_OF_RANGE'

This is because of the initialization of the attribute's ZCLAttributeDataRecord, which uses the attribute's type instead of noData when initializing its defaultValue field.

This is a simple test to reproduce the issue:

  it('should support adding a Cluster with string attribute with 0x0000 ID', async function() {
    class MyCluster extends Cluster {

      static get ID() {
        return 0x1234;
      }

      static get ATTRIBUTES() {
        return {
          priceOption: { id: 0x0000, type: ZCLDataTypes.string },
        };
      }

    }

    Cluster.addCluster(MyCluster);
  });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions