Skip to content

Feature/typed cluster interfaces#157

Draft
RobinBol wants to merge 3 commits intofeature/zigbee-basic-extendedfrom
feature/typed-cluster-interfaces
Draft

Feature/typed cluster interfaces#157
RobinBol wants to merge 3 commits intofeature/zigbee-basic-extendedfrom
feature/typed-cluster-interfaces

Conversation

@RobinBol
Copy link
Collaborator

@RobinBol RobinBol commented Jan 26, 2026

TODO:

  • Don't strip JSDoc comments

- Add scripts/generate-types.js to parse cluster definitions and generate
  TypeScript interfaces with proper attribute/command typing
- Generate typed attributes for each cluster with:
  - Proper enum8/enum16 types as string literal unions
  - Proper map8/map16 types as Partial<Record<flag, boolean>>
  - Correct primitive type mappings (uint8→number, bool→boolean, etc.)
- Generate typed command methods with proper argument types
- Add ClusterRegistry interface for type-safe cluster access
- Add npm run generate-types script for regenerating types
- Add typescript as devDependency for type verification

Usage:
  const cluster = endpoint.clusters.doorLock;
  if (cluster) {
    const attrs = await cluster.readAttributes(['lockState', 'lockType']);
    // attrs.lockState is typed as 'notFullyLocked' | 'locked' | 'unlocked' | ...
  }
Automatically regenerates index.d.ts when cluster definitions change:
- Triggers on push to develop when lib/clusters/*.js files change
- Runs generate-types script and commits updated types
- Uses [skip ci] to prevent infinite loop
@RobinBol RobinBol requested a review from Copilot January 26, 2026 20:51
@RobinBol RobinBol self-assigned this Jan 26, 2026
Copy link

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 introduces automated TypeScript type generation for zigbee-clusters by adding a script that parses JavaScript cluster definitions and generates corresponding TypeScript interfaces.

Changes:

  • Added a type generation script that parses cluster files and generates TypeScript interfaces
  • Added npm script and GitHub Actions workflow to automate type generation
  • Added TypeScript and @types/node as dev dependencies

Reviewed changes

Copilot reviewed 3 out of 5 changed files in this pull request and generated 1 comment.

File Description
scripts/generate-types.js New script that parses cluster definitions and generates TypeScript interfaces with typed attributes and commands
package.json Added generate-types npm script and TypeScript-related dev dependencies
.github/workflows/generate-types.yml GitHub Actions workflow to automatically regenerate types when cluster files change

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Address Copilot review feedback by documenting that Buffer arguments
(octstr, securityKey128, buffer types) are intentionally optional
because ZCL allows empty octet strings and the runtime serializes
undefined values as empty Buffers.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant