Skip to content

Export types#181

Open
JELoohuis wants to merge 9 commits intoathombv:masterfrom
JELoohuis:export-types
Open

Export types#181
JELoohuis wants to merge 9 commits intoathombv:masterfrom
JELoohuis:export-types

Conversation

@JELoohuis
Copy link
Copy Markdown

@JELoohuis JELoohuis commented Apr 10, 2026

Depends on athombv/node-data-types#42

Some of the generated types were incomplete, so I rewrote the generation to document more of the properties available at runtime, as well as adding some additional types based on the JS sources and runtime introspection.

I enabled type checking for the definition file and added the SDK types, since these are used by the ZCLNode.

Some broken enum8 attributes in the Metering cluster definition, where the function was not properly called, were also fixed.

@RobinBol RobinBol self-assigned this Apr 10, 2026
Comment thread .eslintrc.json
Comment on lines 1 to +3
{
"extends": "athom"
} No newline at end of file
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Unrelated change

Comment thread package.json
"homepage": "https://github.com/athombv/node-zigbee-clusters#readme",
"devDependencies": {
"@athombv/jsdoc-template": "^1.6.3",
"@types/homey": "npm:homey-apps-sdk-v3-types@^0.3.12",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This package should not be coupled to the SDK types.

Comment on lines +409 to +413
async function stall(): Promise<void> {
await new Promise(resolve => {
setTimeout(resolve, 1_000_000_000);
});
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not sure what this is used for, the only call of this method is commented out

if (definition.args !== undefined) {
stringBuilder.print(", args: ");
if (Object.keys(definition.args).length === 0) {
stringBuilder.print("Record<never, never> /* TODO fix */ ");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Open TODO

} else if (typeName.startsWith('map')) {
formatMapDataType(stringBuilder, className, command, typeName, typeArgs);
} else if (typeName.startsWith("_Array")) {
stringBuilder.print("Array<unknown>");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

_Array types just emit Array<unknown>. The old script resolved the inner type. This loses type safety on array attributes/args.

await fs.appendFile(filePath, templateBody);

console.log("Done!");
// await stall();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// await stall();

stringBuilder.decreaseIndent();
stringBuilder.printLine("};");

await fs.appendFile(filePath, stringBuilder.toString());
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why repeatedly append to the file instead of building the full string in memory?

Comment thread index.d.ts
timeout?: number,
disableDefaultResponse?: boolean,
},
): Promise<void>;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Quite some methods now lost the response type.

Comment thread index.d.ts
COMMANDS: unknown;
class OnOffCluster<Attributes extends types.AttributeDefinitions = OnOffClusterAttributes, Commands extends types.CommandDefinitions = OnOffClusterCommands> extends Cluster<Attributes, Commands> {
setOff(
args: {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Every generated command method requires args: { manufacturerId?: number } even for no-arg commands like setOff(). Old types had opts? only. Consumers now must pass {} to call simple commands.

Comment thread index.d.ts
},
},
getGroupMembership: { id: 0x02, direction: "DIRECTION_SERVER_TO_CLIENT", args: {
groupIds: ZCLDataType<Array<unknown>>,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This should not be unknown but number

Comment thread index.d.ts
multiplier: { id: 0x301, type: ZCLDataType<number> },
divisor: { id: 0x302, type: ZCLDataType<number> },
siteId: { id: 0x307, type: ZCLDataType<string> },
meterSerialNumber: { id: 0x308, type: ZCLDataType<string> },
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

octstr mapped to string instead of Buffer. Old script used Buffer. Affects siteId, meterSerialNumber, pinCode, etc.

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.

2 participants