Skip to content
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

feat: implement discoverable and transparently-typed CC value definitions #4704

Merged
merged 29 commits into from Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
96bda7b
feat: implement transparently-typed CC value definitions, step 1: static
AlCalzone Jun 10, 2022
592002c
feat: finish Basic CC
AlCalzone Jun 10, 2022
aec7f04
refactor: put properties behind `id` getter, rename `withEndpoint`
AlCalzone Jun 10, 2022
cdf89ea
fix: test
AlCalzone Jun 10, 2022
b6837e7
feat: do some TypeScript magic
AlCalzone Jun 13, 2022
31ceeed
feat: migrate some CCs to new value IDs
AlCalzone Jun 13, 2022
bcbba75
feat: doc generation update (WIP)
AlCalzone Jun 13, 2022
f8be584
fix: path generation on Windows
AlCalzone Jun 13, 2022
abe31a8
feat: add additional metadata to generated CC docs
AlCalzone Jun 13, 2022
7ca5c4c
refactor: make types of metadata templates transparent
AlCalzone Jun 14, 2022
6e4c97d
feat: separate options and metadata, hide internal values from docs
AlCalzone Jun 14, 2022
f5f15fa
refactor: first batch of CCs updated
AlCalzone Jun 14, 2022
2a4bb49
fix: improve inference from optional types
AlCalzone Jun 14, 2022
7f4de03
refactor: next batch of CCs migrated to new value IDs
AlCalzone Jun 14, 2022
b3e5f1b
refactor: next batch of CCs migrated
AlCalzone Jun 14, 2022
c67c429
feat: next batch
AlCalzone Jun 15, 2022
9e73cb7
feat: next batch
AlCalzone Jun 15, 2022
4c9925f
feat: another batch
AlCalzone Jun 15, 2022
e709c76
feat: and another batch
AlCalzone Jun 15, 2022
05b70ab
feat: last batch
AlCalzone Jun 15, 2022
37f7d04
refactor: make CC values less awkward to work with
AlCalzone Jun 15, 2022
8275b89
refactor: get rid of @ccValueMetadata
AlCalzone Jun 15, 2022
b8de717
docs: forgot one
AlCalzone Jun 15, 2022
bde1f06
refactor: disable tests that use getCCValueMetadata
AlCalzone Jun 15, 2022
2616770
refactor: make it possible to lookup and reverse test CC values
AlCalzone Jun 20, 2022
23a22d3
refactor: replace @ccValue magic with a bit less magic
AlCalzone Jun 21, 2022
87a2312
fix: fix tests and make getValueMetadata respect @ccValues
AlCalzone Jun 21, 2022
a7eafc3
fix: docs generation and lint
AlCalzone Jun 21, 2022
50cf40c
feat: make it possible to selectively exclude CC values
AlCalzone Jun 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
98 changes: 94 additions & 4 deletions .vscode/typescript.code-snippets
Expand Up @@ -430,16 +430,20 @@
"prefix": "zwcc",
"body": [
"import {",
"\tCCCommand,",
"\tCommandClass,",
"\tcommandClass,",
"\texpectedCCResponse,",
"\timplementedVersion,",
"\tgotDeserializationOptions,",
"\ttype CCCommandOptions,",
"\ttype CommandClassDeserializationOptions,",
"} from \"../lib/CommandClass\";",
"import {",
"\tCCCommand,",
"\tccValue,",
"\tccValues,",
"\tcommandClass,",
"\texpectedCCResponse,",
"\timplementedVersion,",
"} from \"../lib/CommandClassDecorators\";",
"import {",
"\tCommandClasses,",
"\tMessageOrCCLogEntry,",
"\tMessagePriority,",
Expand All @@ -457,6 +461,7 @@
"",
"@commandClass(CommandClasses.${1})",
"@implementedVersion(${2:1})",
"@ccValues(${1}CCValues)",
"export class ${1}CC extends CommandClass {",
"\tdeclare ccCommand: ${1}Command;",
"}",
Expand All @@ -465,6 +470,91 @@
],
"description": "Z-Wave Command Class implementation"
},
"Z-Wave CC Values": {
"scope": "typescript",
"prefix": "zwccvalues",
"body": [
"export const ${1:${TM_FILENAME_BASE/(.*)CC$/$1/}}CCValues = Object.freeze({",
"\t...V${0}.defineStaticCCValues(CommandClasses.${2:${TM_FILENAME_BASE/(.*)CC$/$1/}}, {",
"\t\t// Static CC values go here",
"\t}),",
"",
"\t...V.defineDynamicCCValues(CommandClasses.${2}, {",
"\t\t// Dynamic CC values go here",
"\t}),",
"});",
""
],
"description": "Z-Wave Command Class values definition"
},
"Z-Wave CC Value (static, property only)": {
"scope": "typescript",
"prefix": "zwccvaluestatic",
"body": [
"...V.staticProperty(",
"\t\"${1:property}\",",
"\t${2:// undefined, // meta}",
"\t${3:// { internal: true \\}, // value options}",
"),"
],
"description": "Static CC value"
},
"Z-Wave CC Value (static, named property)": {
"scope": "typescript",
"prefix": "zwccvaluestaticname",
"body": [
"...V.staticPropertyWithName(",
"\t\"${1:valueName}\",",
"\t\"${2:property}\",",
"\t${3:// undefined, // meta}",
"\t${4:// { internal: true \\}, // value options}",
"),"
],
"description": "Static CC value with name"
},
"Z-Wave CC Value (static, named, property & key)": {
"scope": "typescript",
"prefix": "zwccvaluestaticpropkey",
"body": [
"...V.staticPropertyAndKeyWithName(",
"\t\"${1:valueName}\",",
"\t\"${2:property}\",",
"\t\"${3:propertyKey}\",",
"\t${4:// undefined, // meta}",
"\t${5:// { internal: true \\}, // value options}",
"),"
],
"description": "Static CC value with name, property and propertyKey"
},
"Z-Wave CC Value (dynamic, named property)": {
"scope": "typescript",
"prefix": "zwccvaluedynamicname",
"body": [
"...V.dynamicPropertyWithName(",
"\t\"${1:valueName}\",",
"\t(${2:arg1}: ${3:number}) => ${0:${2}},",
"\t({ property }) => typeof property === \"${3}\",",
"\t// (${2}: ${3}) => ({ ...ValueMetadata.Any }), // meta, can also be a static value",
"\t// (${2}: ${3}) => ({ internal: true }), // value options, can also be a static value",
"),"
],
"description": "Dynamic CC value with name"
},
"Z-Wave CC Value (dynamic, named, property & key)": {
"scope": "typescript",
"prefix": "zwccvaluedynamicpropkey",
"body": [
"...V.dynamicPropertyAndKeyWithName(",
"\t\"${1:valueName}\",",
"\t\"${1}\",",
"\t(${2:arg1}: ${3:number}) => ${0:${2}},",
"\t({ property, propertyKey }) => property === \"${1}\",",
"\t// (${2}: ${3}) => ({ ...ValueMetadata.Any }), // meta, can also be a static value",
"\t// (${2}: ${3}) => ({ internal: true }), // value options, can also be a static value",
"),"
],
"description": "Dynamic CC value with name, property and propertyKey"
},
"Z-Wave CC Command": {
"scope": "typescript",
"prefix": "zwcccmd",
Expand Down
63 changes: 63 additions & 0 deletions docs/api/CCs/AlarmSensor.md
Expand Up @@ -21,3 +21,66 @@ Retrieves the current value from this sensor.
```ts
async getSupportedSensorTypes(): Promise<readonly AlarmSensorType[] | undefined>;
```

## Alarm Sensor CC values

### `duration(sensorType: AlarmSensorType)`

```ts
{
commandClass: CommandClasses["Alarm Sensor"],
endpoint: number,
property: "duration",
propertyKey: AlarmSensorType,
}
```

- **label:** `${string} duration`
- **description:** For how long the alarm should be active
- **min. CC version:** 1
- **readable:** true
- **writeable:** false
- **stateful:** true
- **secret:** false
- **value type:** `"number"`

### `severity(sensorType: AlarmSensorType)`

```ts
{
commandClass: CommandClasses["Alarm Sensor"],
endpoint: number,
property: "severity",
propertyKey: AlarmSensorType,
}
```

- **label:** `${string} severity`
- **min. CC version:** 1
- **readable:** true
- **writeable:** false
- **stateful:** true
- **secret:** false
- **value type:** `"number"`
- **min. value:** 1
- **max. value:** 100

### `state(sensorType: AlarmSensorType)`

```ts
{
commandClass: CommandClasses["Alarm Sensor"],
endpoint: number,
property: "state",
propertyKey: AlarmSensorType,
}
```

- **label:** `${string} state`
- **description:** Whether the alarm is active
- **min. CC version:** 1
- **readable:** true
- **writeable:** false
- **stateful:** true
- **secret:** false
- **value type:** `"boolean"`
83 changes: 83 additions & 0 deletions docs/api/CCs/BarrierOperator.md
Expand Up @@ -42,3 +42,86 @@ async setEventSignaling(
subsystemState: SubsystemState,
): Promise<void>;
```

## Barrier Operator CC values

### `currentState`

```ts
{
commandClass: CommandClasses["Barrier Operator"],
endpoint: number,
property: "currentState",
}
```

- **label:** Current Barrier State
- **min. CC version:** 1
- **readable:** true
- **writeable:** false
- **stateful:** true
- **secret:** false
- **value type:** `"number"`
- **min. value:** 0
- **max. value:** 255

### `position`

```ts
{
commandClass: CommandClasses["Barrier Operator"],
endpoint: number,
property: "position",
}
```

- **label:** Barrier Position
- **min. CC version:** 1
- **readable:** true
- **writeable:** false
- **stateful:** true
- **secret:** false
- **value type:** `"number"`
- **min. value:** 0
- **max. value:** 100

### `signalingState(subsystemType: SubsystemType)`

```ts
{
commandClass: CommandClasses["Barrier Operator"],
endpoint: number,
property: "signalingState",
propertyKey: SubsystemType,
}
```

- **label:** `Signaling State (${string})`
- **min. CC version:** 1
- **readable:** true
- **writeable:** true
- **stateful:** true
- **secret:** false
- **value type:** `"number"`
- **min. value:** 0
- **max. value:** 255

### `targetState`

```ts
{
commandClass: CommandClasses["Barrier Operator"],
endpoint: number,
property: "targetState",
}
```

- **label:** Target Barrier State
- **min. CC version:** 1
- **readable:** true
- **writeable:** true
- **stateful:** true
- **secret:** false
- **value type:** `"number"`
- **min. value:** 0
- **max. value:** 255
80 changes: 80 additions & 0 deletions docs/api/CCs/Basic.md
Expand Up @@ -15,3 +15,83 @@ async get(): Promise<Pick<BasicCCReport, "currentValue" | "targetValue" | "durat
```ts
async set(targetValue: number): Promise<void>;
```

## Basic CC values

### `compatEvent`

```ts
{
commandClass: CommandClasses.Basic,
endpoint: number,
property: "event",
}
```

- **label:** Event value
- **min. CC version:** 1
- **readable:** true
- **writeable:** false
- **stateful:** false
- **secret:** false
- **value type:** `"number"`
- **min. value:** 0
- **max. value:** 255

### `currentValue`

```ts
{
commandClass: CommandClasses.Basic,
endpoint: number,
property: "currentValue",
}
```

- **label:** Current value
- **min. CC version:** 1
- **readable:** true
- **writeable:** false
- **stateful:** true
- **secret:** false
- **value type:** `"number"`
- **min. value:** 0
- **max. value:** 99

### `duration`

```ts
{
commandClass: CommandClasses.Basic,
endpoint: number,
property: "duration",
}
```

- **label:** Remaining duration
- **min. CC version:** 1
- **readable:** true
- **writeable:** false
- **stateful:** true
- **secret:** false
- **value type:** `"duration"`

### `targetValue`

```ts
{
commandClass: CommandClasses.Basic,
endpoint: number,
property: "targetValue",
}
```

- **label:** Target value
- **min. CC version:** 1
- **readable:** true
- **writeable:** true
- **stateful:** true
- **secret:** false
- **value type:** `"number"`
- **min. value:** 0
- **max. value:** 255