isy-nodejs 1.0.1-alpha.1 → 1.0.1-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Converters.js +66 -30
- package/dist/cjs/Converters.js.map +1 -1
- package/dist/cjs/Definitions/Global/Drivers.js +10 -3
- package/dist/cjs/Definitions/Global/Drivers.js.map +1 -1
- package/dist/cjs/Definitions/Global/Events.js +1 -2
- package/dist/cjs/Definitions/Global/Events.js.map +1 -1
- package/dist/cjs/Devices/Elk/ElkAlarmPanelDevice.js +3 -3
- package/dist/cjs/Devices/Elk/ElkAlarmSensorDevice.js +9 -6
- package/dist/cjs/Devices/Elk/ElkAlarmSensorDevice.js.map +1 -1
- package/dist/cjs/Devices/Insteon/InsteonBaseDevice.js +5 -3
- package/dist/cjs/Devices/Insteon/InsteonBaseDevice.js.map +1 -1
- package/dist/cjs/Devices/Insteon/InsteonFanDevice.js +7 -3
- package/dist/cjs/Devices/Insteon/InsteonFanDevice.js.map +1 -1
- package/dist/cjs/Devices/Insteon/InsteonMotionSensorDevice.js +5 -5
- package/dist/cjs/Devices/Insteon/InsteonRelayDevice.js +3 -8
- package/dist/cjs/Devices/Insteon/InsteonRelayDevice.js.map +1 -1
- package/dist/cjs/Devices/Insteon/RelayLampSwitch.js +72 -0
- package/dist/cjs/Devices/Insteon/RelayLampSwitch.js.map +1 -0
- package/dist/cjs/ISY.js +155 -135
- package/dist/cjs/ISY.js.map +1 -1
- package/dist/cjs/ISYNode.js +34 -15
- package/dist/cjs/ISYNode.js.map +1 -1
- package/dist/cjs/ISYScene.js +3 -3
- package/dist/cjs/ISYScene.js.map +1 -1
- package/dist/cjs/Matter/Behaviors/ISYBridgedDeviceBehavior.js +11 -4
- package/dist/cjs/Matter/Behaviors/ISYBridgedDeviceBehavior.js.map +1 -1
- package/dist/cjs/Matter/Behaviors/ISYClusterBehavior.js +26 -7
- package/dist/cjs/Matter/Behaviors/ISYClusterBehavior.js.map +1 -1
- package/dist/cjs/Matter/Behaviors/ISYOnOffBehavior.js +9 -7
- package/dist/cjs/Matter/Behaviors/ISYOnOffBehavior.js.map +1 -1
- package/dist/cjs/Matter/{Server → Bridge}/Server.js +27 -45
- package/dist/cjs/Matter/Bridge/Server.js.map +1 -0
- package/dist/cjs/Matter/Mappings/Insteon.js +19 -15
- package/dist/cjs/Matter/Mappings/Insteon.js.map +1 -1
- package/dist/cjs/Matter/Mappings/register.js +1 -0
- package/dist/cjs/Matter/Mappings/register.js.map +1 -0
- package/dist/cjs/Model/ClusterMap.js +12 -9
- package/dist/cjs/Model/ClusterMap.js.map +1 -1
- package/dist/cjs/Utils.js +29 -9
- package/dist/cjs/Utils.js.map +1 -1
- package/dist/cjs/types/CodeGeneration/EnumFactory.d.ts +1 -1
- package/dist/cjs/types/Converters.d.ts +28 -8
- package/dist/cjs/types/Converters.d.ts.map +1 -1
- package/dist/cjs/types/Definitions/Global/Drivers.d.ts +4 -3
- package/dist/cjs/types/Definitions/Global/Drivers.d.ts.map +1 -1
- package/dist/cjs/types/Definitions/Global/Events.d.ts.map +1 -1
- package/dist/cjs/types/Devices/Elk/ElkAlarmSensorDevice.d.ts.map +1 -1
- package/dist/cjs/types/Devices/EndpointFor.d.ts +2 -2
- package/dist/cjs/types/Devices/Insteon/InsteonBaseDevice.d.ts +3 -3
- package/dist/cjs/types/Devices/Insteon/InsteonBaseDevice.d.ts.map +1 -1
- package/dist/cjs/types/Devices/Insteon/InsteonDevice.d.ts +4 -4
- package/dist/cjs/types/Devices/Insteon/InsteonFanDevice.d.ts +5 -4
- package/dist/cjs/types/Devices/Insteon/InsteonFanDevice.d.ts.map +1 -1
- package/dist/cjs/types/Devices/Insteon/InsteonRelayDevice.d.ts +2 -4
- package/dist/cjs/types/Devices/Insteon/InsteonRelayDevice.d.ts.map +1 -1
- package/dist/cjs/types/Devices/Insteon/RelayLampSwitch.d.ts +93 -0
- package/dist/cjs/types/Devices/Insteon/RelayLampSwitch.d.ts.map +1 -0
- package/dist/cjs/types/ISY.d.ts +56 -52
- package/dist/cjs/types/ISY.d.ts.map +1 -1
- package/dist/cjs/types/ISYNode.d.ts +4 -4
- package/dist/cjs/types/ISYNode.d.ts.map +1 -1
- package/dist/cjs/types/Matter/Behaviors/ISYBridgedDeviceBehavior.d.ts +16 -6
- package/dist/cjs/types/Matter/Behaviors/ISYBridgedDeviceBehavior.d.ts.map +1 -1
- package/dist/cjs/types/Matter/Behaviors/ISYClusterBehavior.d.ts +13 -11
- package/dist/cjs/types/Matter/Behaviors/ISYClusterBehavior.d.ts.map +1 -1
- package/dist/cjs/types/Matter/Behaviors/ISYOnOffBehavior.d.ts +4 -4
- package/dist/cjs/types/Matter/Behaviors/ISYOnOffBehavior.d.ts.map +1 -1
- package/dist/cjs/types/Matter/Bridge/Server.d.ts +17 -0
- package/dist/cjs/types/Matter/Bridge/Server.d.ts.map +1 -0
- package/dist/cjs/types/Matter/Mappings/register.d.ts +1 -0
- package/dist/cjs/types/Matter/Mappings/register.d.ts.map +1 -0
- package/dist/cjs/types/Model/ClusterMap.d.ts +19 -11
- package/dist/cjs/types/Model/ClusterMap.d.ts.map +1 -1
- package/dist/cjs/types/Utils.d.ts +2 -5
- package/dist/cjs/types/Utils.d.ts.map +1 -1
- package/dist/esm/Converters.js +63 -28
- package/dist/esm/Converters.js.map +1 -1
- package/dist/esm/Definitions/Global/Drivers.js +10 -3
- package/dist/esm/Definitions/Global/Drivers.js.map +1 -1
- package/dist/esm/Definitions/Global/Events.js +1 -2
- package/dist/esm/Definitions/Global/Events.js.map +1 -1
- package/dist/esm/Devices/Elk/ElkAlarmPanelDevice.js +3 -3
- package/dist/esm/Devices/Elk/ElkAlarmSensorDevice.js +9 -6
- package/dist/esm/Devices/Elk/ElkAlarmSensorDevice.js.map +1 -1
- package/dist/esm/Devices/Insteon/InsteonBaseDevice.js +6 -4
- package/dist/esm/Devices/Insteon/InsteonBaseDevice.js.map +1 -1
- package/dist/esm/Devices/Insteon/InsteonFanDevice.js +7 -3
- package/dist/esm/Devices/Insteon/InsteonFanDevice.js.map +1 -1
- package/dist/esm/Devices/Insteon/InsteonMotionSensorDevice.js +5 -5
- package/dist/esm/Devices/Insteon/InsteonRelayDevice.js +3 -8
- package/dist/esm/Devices/Insteon/InsteonRelayDevice.js.map +1 -1
- package/dist/esm/Devices/Insteon/RelayLampSwitch.js +68 -0
- package/dist/esm/Devices/Insteon/RelayLampSwitch.js.map +1 -0
- package/dist/esm/ISY.js +191 -171
- package/dist/esm/ISY.js.map +1 -1
- package/dist/esm/ISYNode.js +34 -15
- package/dist/esm/ISYNode.js.map +1 -1
- package/dist/esm/ISYScene.js +3 -3
- package/dist/esm/ISYScene.js.map +1 -1
- package/dist/esm/Matter/Behaviors/ISYBridgedDeviceBehavior.js +11 -4
- package/dist/esm/Matter/Behaviors/ISYBridgedDeviceBehavior.js.map +1 -1
- package/dist/esm/Matter/Behaviors/ISYClusterBehavior.js +26 -7
- package/dist/esm/Matter/Behaviors/ISYClusterBehavior.js.map +1 -1
- package/dist/esm/Matter/Behaviors/ISYOnOffBehavior.js +10 -8
- package/dist/esm/Matter/Behaviors/ISYOnOffBehavior.js.map +1 -1
- package/dist/esm/Matter/{Server → Bridge}/Server.js +25 -44
- package/dist/esm/Matter/Bridge/Server.js.map +1 -0
- package/dist/esm/Matter/Mappings/Insteon.js +22 -18
- package/dist/esm/Matter/Mappings/Insteon.js.map +1 -1
- package/dist/esm/Matter/Mappings/register.js +2 -0
- package/dist/esm/Matter/Mappings/register.js.map +1 -0
- package/dist/esm/Model/ClusterMap.js +12 -9
- package/dist/esm/Model/ClusterMap.js.map +1 -1
- package/dist/esm/Utils.js +25 -8
- package/dist/esm/Utils.js.map +1 -1
- package/dist/esm/types/CodeGeneration/EnumFactory.d.ts +1 -1
- package/dist/esm/types/Converters.d.ts +28 -8
- package/dist/esm/types/Converters.d.ts.map +1 -1
- package/dist/esm/types/Definitions/Global/Drivers.d.ts +4 -3
- package/dist/esm/types/Definitions/Global/Drivers.d.ts.map +1 -1
- package/dist/esm/types/Definitions/Global/Events.d.ts.map +1 -1
- package/dist/esm/types/Devices/Elk/ElkAlarmSensorDevice.d.ts.map +1 -1
- package/dist/esm/types/Devices/EndpointFor.d.ts +2 -2
- package/dist/esm/types/Devices/Insteon/InsteonBaseDevice.d.ts +3 -3
- package/dist/esm/types/Devices/Insteon/InsteonBaseDevice.d.ts.map +1 -1
- package/dist/esm/types/Devices/Insteon/InsteonDevice.d.ts +4 -4
- package/dist/esm/types/Devices/Insteon/InsteonFanDevice.d.ts +5 -4
- package/dist/esm/types/Devices/Insteon/InsteonFanDevice.d.ts.map +1 -1
- package/dist/esm/types/Devices/Insteon/InsteonRelayDevice.d.ts +2 -4
- package/dist/esm/types/Devices/Insteon/InsteonRelayDevice.d.ts.map +1 -1
- package/dist/esm/types/Devices/Insteon/RelayLampSwitch.d.ts +93 -0
- package/dist/esm/types/Devices/Insteon/RelayLampSwitch.d.ts.map +1 -0
- package/dist/esm/types/ISY.d.ts +56 -52
- package/dist/esm/types/ISY.d.ts.map +1 -1
- package/dist/esm/types/ISYNode.d.ts +4 -4
- package/dist/esm/types/ISYNode.d.ts.map +1 -1
- package/dist/esm/types/Matter/Behaviors/ISYBridgedDeviceBehavior.d.ts +16 -6
- package/dist/esm/types/Matter/Behaviors/ISYBridgedDeviceBehavior.d.ts.map +1 -1
- package/dist/esm/types/Matter/Behaviors/ISYClusterBehavior.d.ts +13 -11
- package/dist/esm/types/Matter/Behaviors/ISYClusterBehavior.d.ts.map +1 -1
- package/dist/esm/types/Matter/Behaviors/ISYOnOffBehavior.d.ts +4 -4
- package/dist/esm/types/Matter/Behaviors/ISYOnOffBehavior.d.ts.map +1 -1
- package/dist/esm/types/Matter/Bridge/Server.d.ts +17 -0
- package/dist/esm/types/Matter/Bridge/Server.d.ts.map +1 -0
- package/dist/esm/types/Matter/Mappings/register.d.ts +2 -0
- package/dist/esm/types/Matter/Mappings/register.d.ts.map +1 -0
- package/dist/esm/types/Model/ClusterMap.d.ts +19 -11
- package/dist/esm/types/Model/ClusterMap.d.ts.map +1 -1
- package/dist/esm/types/Utils.d.ts +2 -5
- package/dist/esm/types/Utils.d.ts.map +1 -1
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +5 -9
- package/src/Converters.ts +137 -69
- package/src/Definitions/Global/Drivers.ts +16 -7
- package/src/Definitions/Global/Events.ts +4 -3
- package/src/Devices/Elk/ElkAlarmPanelDevice.ts +3 -3
- package/src/Devices/Elk/ElkAlarmSensorDevice.ts +15 -21
- package/src/Devices/Insteon/Generated/RelayLamp.ts +8 -7
- package/src/Devices/Insteon/InsteonBaseDevice.ts +10 -9
- package/src/Devices/Insteon/InsteonFanDevice.ts +16 -11
- package/src/Devices/Insteon/InsteonMotionSensorDevice.ts +5 -5
- package/src/Devices/Insteon/InsteonRelayDevice.ts +3 -5
- package/src/Devices/Insteon/RelayLampSwitch.ts +131 -0
- package/src/ISY.ts +816 -819
- package/src/ISYNode.ts +33 -17
- package/src/ISYScene.ts +3 -3
- package/src/Matter/Behaviors/ISYBridgedDeviceBehavior.ts +29 -11
- package/src/Matter/Behaviors/ISYClusterBehavior.ts +46 -28
- package/src/Matter/Behaviors/ISYOnOffBehavior.ts +49 -60
- package/src/Matter/{Server → Bridge}/Server.ts +47 -51
- package/src/Matter/Mappings/Insteon.ts +53 -60
- package/src/Matter/Mappings/register.ts +0 -0
- package/src/Model/ClassDefinition.ts +1 -1
- package/src/Model/ClusterMap.ts +31 -22
- package/src/Utils.ts +26 -19
- package/tsconfig.json +2 -2
- package/dist/cjs/Matter/Server/Server.js.map +0 -1
- package/dist/cjs/types/Matter/Server/Server.d.ts +0 -4
- package/dist/cjs/types/Matter/Server/Server.d.ts.map +0 -1
- package/dist/esm/Matter/Server/Server.js.map +0 -1
- package/dist/esm/types/Matter/Server/Server.d.ts +0 -4
- package/dist/esm/types/Matter/Server/Server.d.ts.map +0 -1
package/src/ISYNode.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { UnitOfMeasure } from './Definitions/Global/UOM.js';
|
|
|
6
6
|
import { ISY, NodeType, type ISYScene } from './ISY.js';
|
|
7
7
|
|
|
8
8
|
import { CliConfigSetLevels } from 'winston/lib/winston/config/index.js';
|
|
9
|
+
import { Converter } from './Converters.js';
|
|
9
10
|
import type { Command } from './Definitions/Global/Commands.js';
|
|
10
11
|
import { Event } from './Definitions/Global/Events.js';
|
|
11
12
|
import type { Constructor } from './Devices/Constructor.js';
|
|
@@ -164,21 +165,33 @@ export class ISYNode<
|
|
|
164
165
|
}
|
|
165
166
|
|
|
166
167
|
public convert(value: any, from: UnitOfMeasure, to: UnitOfMeasure): any {
|
|
167
|
-
return value;
|
|
168
|
+
if (from === to) return value;
|
|
169
|
+
else {
|
|
170
|
+
try {
|
|
171
|
+
return Converter.Standard[from][to].from(value);
|
|
172
|
+
} catch {
|
|
173
|
+
this.isy.logger.error(`Conversion from ${UnitOfMeasure[from]} to ${UnitOfMeasure[to]} not supported.`);
|
|
174
|
+
} finally {
|
|
175
|
+
return value;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
168
178
|
}
|
|
169
179
|
|
|
170
180
|
public convertFrom(value: any, uom: UnitOfMeasure, propertyName?: StringKeys<D>): any {
|
|
171
|
-
|
|
181
|
+
if (this.drivers[propertyName]?.uom != uom) {
|
|
182
|
+
this.logger(`Converting ${this.drivers[propertyName].label} to ${UnitOfMeasure[this.drivers[propertyName]?.uom]} from ${UnitOfMeasure[uom]}`);
|
|
183
|
+
return this.convert(value, uom, this.drivers[propertyName].uom);
|
|
184
|
+
}
|
|
172
185
|
}
|
|
173
186
|
|
|
174
187
|
public convertTo(value: any, uom: UnitOfMeasure, propertyName?: StringKeys<D>) {
|
|
175
|
-
if (this.drivers[propertyName]
|
|
176
|
-
this.isy.logger.debug(`Converting ${this.drivers[propertyName].label} from ${this.drivers[propertyName].uom} to ${UnitOfMeasure}`);
|
|
177
|
-
return this.
|
|
188
|
+
if (this.drivers[propertyName]?.uom != uom) {
|
|
189
|
+
this.isy.logger.debug(`Converting ${this.drivers[propertyName].label} from ${UnitOfMeasure[this.drivers[propertyName].uom]} to ${UnitOfMeasure[uom]}`);
|
|
190
|
+
return this.convert(value, uom, this.drivers[propertyName].uom);
|
|
178
191
|
}
|
|
179
192
|
}
|
|
180
193
|
|
|
181
|
-
public emit(event: '
|
|
194
|
+
public emit(event: 'propertyChanged' | 'controlTriggered', propertyName?: string, newValue?: any, oldValue?: any, formattedValue?: string, controlName?: string) {
|
|
182
195
|
//if ('PropertyChanged') return super.emit(event, propertyName, newValue, oldValue, formattedValue);
|
|
183
196
|
//else if ('ControlTriggered') return super.emit(event, controlName);
|
|
184
197
|
}
|
|
@@ -206,7 +219,7 @@ export class ISYNode<
|
|
|
206
219
|
|
|
207
220
|
public async getNotes(): Promise<NodeNotes> {
|
|
208
221
|
try {
|
|
209
|
-
const result = await this.isy.sendRequest(`nodes/${this.address}/notes
|
|
222
|
+
const result = await this.isy.sendRequest(`nodes/${this.address}/notes`,{trailingSlash: false,errorLogLevel: 'debug'});
|
|
210
223
|
if (result !== null && result !== undefined) {
|
|
211
224
|
return result.NodeProperties;
|
|
212
225
|
} else {
|
|
@@ -219,7 +232,7 @@ export class ISYNode<
|
|
|
219
232
|
|
|
220
233
|
public handleControlTrigger(controlName: keyof E & keyof C): boolean {
|
|
221
234
|
//this.lastChanged = new Date();
|
|
222
|
-
this.events.emit('
|
|
235
|
+
this.events.emit('controlTriggered', controlName);
|
|
223
236
|
return true;
|
|
224
237
|
}
|
|
225
238
|
|
|
@@ -240,23 +253,26 @@ export class ISYNode<
|
|
|
240
253
|
} else {
|
|
241
254
|
// this.logger(event.control);
|
|
242
255
|
const e = event.control;
|
|
243
|
-
const dispName = this.commands[e]
|
|
256
|
+
const dispName = this.commands[e]?.name;
|
|
244
257
|
if (dispName !== undefined && dispName !== null) {
|
|
245
|
-
this.logger(`Command ${dispName} (${e})
|
|
258
|
+
this.logger(`Command ${dispName} (${e}) event sent.`);
|
|
246
259
|
} else {
|
|
247
|
-
this.logger(`Command ${e}
|
|
260
|
+
this.logger(`Command ${e} event sent.`);
|
|
248
261
|
}
|
|
249
262
|
this.handleControlTrigger(e);
|
|
250
263
|
return true;
|
|
251
264
|
}
|
|
252
265
|
}
|
|
253
266
|
|
|
254
|
-
public handlePropertyChange(propertyName: StringKeys<D>, value: any, uom: UnitOfMeasure,
|
|
267
|
+
public handlePropertyChange(propertyName: StringKeys<D>, value: any, uom: UnitOfMeasure, prec?: number, formattedValue?: string): boolean {
|
|
255
268
|
this.lastChanged = new Date();
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
269
|
+
let driver = this.drivers[propertyName];
|
|
270
|
+
this.logger(`Driver ${propertyName} (${driver?.label} value update ${value} (${formattedValue}) uom: ${UnitOfMeasure[uom]} event received.`);
|
|
271
|
+
const oldValue = driver?.value;
|
|
272
|
+
if (driver?.patch(value, formattedValue, uom, prec)) {
|
|
273
|
+
this.logger(`Driver ${driver.label} updated from ${oldValue} to ${value} (${formattedValue})`);
|
|
274
|
+
this.emit('propertyChanged', propertyName, value, oldValue, formattedValue);
|
|
275
|
+
this.scenes?.forEach((element) => {
|
|
260
276
|
this.logger(`Recalulating ${element.deviceFriendlyName}`);
|
|
261
277
|
element.recalculateState();
|
|
262
278
|
});
|
|
@@ -523,7 +539,7 @@ export namespace ISYNode {
|
|
|
523
539
|
[K in C[U]["name"]]: C[K];
|
|
524
540
|
} : never;*/
|
|
525
541
|
|
|
526
|
-
export const With = <K extends Family, D extends DriverSignatures, C extends CommandSignatures, T extends Constructor<ISYNode<K,
|
|
542
|
+
export const With = <K extends Family, D extends DriverSignatures, C extends CommandSignatures, T extends Constructor<ISYNode<K, any, any, any>>>(Base: T) => {
|
|
527
543
|
return class extends Base implements Omit<ISYNode<K, D, C>, 'events'> {
|
|
528
544
|
declare drivers: Driver.ForAll<any, false>;
|
|
529
545
|
declare commands: Command.ForAll<C>;
|
package/src/ISYScene.ts
CHANGED
|
@@ -77,7 +77,7 @@ export class ISYScene extends ISYNode<Family.Scene, Driver.Signatures<'ST'>,Comm
|
|
|
77
77
|
get isOn() {
|
|
78
78
|
for (const device of this.members) {
|
|
79
79
|
if (device instanceof Insteon.Relay) {
|
|
80
|
-
if (device.drivers.ST?.value
|
|
80
|
+
if (device.drivers.ST?.value != 0) {
|
|
81
81
|
return true;
|
|
82
82
|
}
|
|
83
83
|
}
|
|
@@ -110,10 +110,10 @@ export class ISYScene extends ISYNode<Family.Scene, Driver.Signatures<'ST'>,Comm
|
|
|
110
110
|
}
|
|
111
111
|
public markAsChanged() {
|
|
112
112
|
this.lastChanged = new Date();
|
|
113
|
-
this.emit('
|
|
113
|
+
this.emit('propertyChanged', 'isOn', this.isOn, this.isOn, this.isOn ? 'on' : 'off');
|
|
114
114
|
|
|
115
115
|
if (this.isDimmable) {
|
|
116
|
-
this.emit('
|
|
116
|
+
this.emit('propertyChanged', 'brightnesslevel', this.brightnessLevel, this.brightnessLevel, this.brightnessLevel + '%');
|
|
117
117
|
|
|
118
118
|
}
|
|
119
119
|
}
|
|
@@ -11,11 +11,11 @@ import internal from 'stream';
|
|
|
11
11
|
import type { Driver } from '../../Definitions/Global/Drivers.js';
|
|
12
12
|
import { ISY, type Family, type ISYNode } from '../../ISY.js';
|
|
13
13
|
import type { ISYDevice } from '../../ISYDevice.js';
|
|
14
|
-
import { DeviceToClusterMap, MappingRegistry, type ClusterMapping } from '../../Model/ClusterMap.js';
|
|
14
|
+
import { DeviceToClusterMap, MappingRegistry, type ClusterMapping, type BehaviorMapping } from '../../Model/ClusterMap.js';
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
type ClusterForBehavior<B extends ClusterBehavior> = B extends ClusterBehavior.Type<infer C> ? C : never;
|
|
18
|
-
export class ISYBridgedDeviceBehavior extends Behavior {
|
|
18
|
+
export class ISYBridgedDeviceBehavior<N extends ISYNode<any, D, any, any>, D extends ISYNode.DriverSignatures = ISYNode.DriverSignatures> extends Behavior {
|
|
19
19
|
static override readonly id = 'isyNode';
|
|
20
20
|
|
|
21
21
|
static override readonly early = true;
|
|
@@ -23,16 +23,24 @@ export class ISYBridgedDeviceBehavior extends Behavior {
|
|
|
23
23
|
declare internal: ISYBridgedDeviceBehavior.Internal;
|
|
24
24
|
declare state: ISYBridgedDeviceBehavior.State;
|
|
25
25
|
|
|
26
|
-
declare events: ISYBridgedDeviceBehavior.Events
|
|
26
|
+
declare events: ISYBridgedDeviceBehavior.Events & ISYBridgedDeviceBehavior.EventsFor<N["drivers"]>;
|
|
27
27
|
|
|
28
28
|
override async initialize(_options?: {}) {
|
|
29
29
|
await super.initialize(_options);
|
|
30
30
|
var address = this.state.address;
|
|
31
|
-
|
|
32
|
-
this.internal.
|
|
31
|
+
const d = ISY.instance.nodeMap.get(this.state.address);
|
|
32
|
+
this.internal.device = d;
|
|
33
|
+
this.internal.map = MappingRegistry.getMapping(this.internal.device as unknown as ISYNode<Family, any, any, any>);
|
|
33
34
|
ISY.instance.logger.debug(`Initializing ${this.constructor.name} for ${this.internal.device.constructor.name} ${this.internal.device.name} with address ${address}`);
|
|
34
|
-
if (
|
|
35
|
-
|
|
35
|
+
if (d) {
|
|
36
|
+
d.events.on('PropertyChanged', this.handlePropertyChange.bind(this));
|
|
37
|
+
for(const f in d.drivers)
|
|
38
|
+
{
|
|
39
|
+
let evt = `${d.drivers[f].name}Changed`;
|
|
40
|
+
this.events[evt] = Observable<[{ driver: string; newValue: any; oldValue: any; formattedValue: string }]>();
|
|
41
|
+
//@ts-ignore
|
|
42
|
+
d.events.on(evt, (driver: string, newValue: any, oldValue: any, formattedValue: string) => this.events.emit(evt, { driver, newValue, oldValue, formattedValue } as unknown as any));
|
|
43
|
+
}
|
|
36
44
|
}
|
|
37
45
|
}
|
|
38
46
|
|
|
@@ -44,15 +52,15 @@ export class ISYBridgedDeviceBehavior extends Behavior {
|
|
|
44
52
|
return this.internal.map;
|
|
45
53
|
}
|
|
46
54
|
|
|
47
|
-
mapForBehavior<B extends
|
|
48
|
-
return this.map[behavior.cluster['name']];
|
|
55
|
+
mapForBehavior<B extends ClusterBehavior>(behavior: B): BehaviorMapping<B, typeof this.internal.device> {
|
|
56
|
+
return this.map.mapping[behavior.cluster['name']];
|
|
49
57
|
}
|
|
50
58
|
|
|
51
59
|
handlePropertyChange(driver: string, newValue: any, oldValue: any, formattedValue: string) {
|
|
52
60
|
this.events.propertyChanged.emit({ driver, newValue, oldValue, formattedValue });
|
|
53
61
|
}
|
|
54
62
|
|
|
55
|
-
[Symbol.asyncDispose]() {
|
|
63
|
+
override [Symbol.asyncDispose]() {
|
|
56
64
|
this.internal.device = null;
|
|
57
65
|
return super[Symbol.asyncDispose]();
|
|
58
66
|
}
|
|
@@ -64,8 +72,18 @@ export namespace ISYBridgedDeviceBehavior {
|
|
|
64
72
|
map?: DeviceToClusterMap<typeof this.device, any>;
|
|
65
73
|
}
|
|
66
74
|
|
|
67
|
-
export
|
|
75
|
+
export type EventsFor<D extends {[x: string]: Driver<any,any,any>}> = {
|
|
76
|
+
[s in keyof D as `${D[s]["name"]}Changed`] : Observable<[{ driver: s; newValue: any; oldValue: any; formattedValue: string }]>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
export class Events extends EventEmitter{
|
|
68
83
|
propertyChanged = Observable<[{ driver: string; newValue: any; oldValue: any; formattedValue: string }]>();
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
69
87
|
}
|
|
70
88
|
|
|
71
89
|
export class State {
|
|
@@ -1,38 +1,50 @@
|
|
|
1
|
-
import type { ClusterBehavior, ClusterInterface } from '@project-chip/matter.js/behavior/cluster';
|
|
2
|
-
|
|
3
|
-
import type { DriversOf, ISYNode } from '../../ISYNode.js';
|
|
4
|
-
|
|
5
1
|
import type { Behavior } from '@project-chip/matter.js/behavior';
|
|
2
|
+
import type { ClusterBehavior, ClusterInterface } from '@project-chip/matter.js/behavior/cluster';
|
|
6
3
|
import { BridgedDeviceBasicInformationServer } from '@project-chip/matter.js/behaviors/bridged-device-basic-information';
|
|
7
4
|
import type { LevelControlBehavior } from '@project-chip/matter.js/behaviors/level-control';
|
|
8
5
|
import type { OnOffBehavior, OnOffServer } from '@project-chip/matter.js/behaviors/on-off';
|
|
9
6
|
import type { Cluster, ClusterServerHandlers, ClusterType as CT } from '@project-chip/matter.js/cluster';
|
|
10
7
|
import '@project-chip/matter.js/device';
|
|
11
8
|
import { OnOffLightRequirements } from '@project-chip/matter.js/devices/OnOffLightDevice';
|
|
12
|
-
import {
|
|
9
|
+
import { Converter } from '../../Converters.js';
|
|
10
|
+
import { Driver, DriverType } from '../../Definitions/Global/Drivers.js';
|
|
13
11
|
import type { Constructor } from '../../Devices/Constructor.js';
|
|
14
12
|
import type { RelaxTypes } from '../../Devices/MapsTo.js';
|
|
15
13
|
import { ISY, type ISYDevice } from '../../ISY.js';
|
|
16
|
-
import {
|
|
17
|
-
|
|
14
|
+
import type { DriversOf, ISYNode } from '../../ISYNode.js';
|
|
15
|
+
import { BehaviorMapping, MappingRegistry, type ClusterMapping, type DeviceToClusterMap } from '../../Model/ClusterMap.js';
|
|
18
16
|
import { ISYBridgedDeviceBehavior } from './ISYBridgedDeviceBehavior.js';
|
|
19
17
|
|
|
20
|
-
|
|
18
|
+
// #region Type aliases (6)
|
|
21
19
|
|
|
20
|
+
export type ClusterForBehavior<B> = B extends ClusterBehavior.Type<infer C, infer D, infer E> ? C : never;
|
|
22
21
|
export type ConstructedType<B extends Constructor<any>> = B extends Constructor<infer C> ? C : never;
|
|
22
|
+
// <reference path="MatterDevice.js" />
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
export type DeviceBehavior<P extends ISYNode, T extends { cluster? }> = {
|
|
25
|
+
device: P;
|
|
23
26
|
|
|
24
|
-
|
|
27
|
+
bridgedDeviceBehavior: ISYBridgedDeviceBehavior<P>;
|
|
25
28
|
|
|
26
|
-
|
|
29
|
+
//ts-ignore
|
|
30
|
+
map: BehaviorMapping<T, P>;
|
|
27
31
|
|
|
32
|
+
handlePropertyChange(chg: PropertyChange<P>): void;
|
|
33
|
+
};
|
|
34
|
+
type NotUnknown<T extends ClusterBehavior> = T extends { cluster: { name: 'Unknown' } } ? never : T;
|
|
28
35
|
export type PropertyChange<P extends ISYNode<any, any, any, any>> = {
|
|
29
36
|
driver: keyof DriversOf<P>;
|
|
30
37
|
newValue: any;
|
|
31
38
|
oldValue: any;
|
|
32
39
|
formattedValue: string;
|
|
33
40
|
};
|
|
41
|
+
type t = ClusterForBehavior<LevelControlBehavior>;
|
|
42
|
+
|
|
43
|
+
// #endregion Type aliases (6)
|
|
34
44
|
|
|
35
|
-
|
|
45
|
+
// #region Functions (1)
|
|
46
|
+
|
|
47
|
+
export function ISYClusterBehavior<T extends Constructor<ClusterBehavior> & { cluster }, P extends ISYNode<any, any, any, any>>(
|
|
36
48
|
base: T,
|
|
37
49
|
p: Constructor<P>
|
|
38
50
|
): typeof base & { new (...args: any[]): DeviceBehavior<P, T> } {
|
|
@@ -41,30 +53,44 @@ export function ISYClusterBehavior<T extends Constructor<ClusterBehavior> & { cl
|
|
|
41
53
|
|
|
42
54
|
handlers: { [x in keyof DriversOf<P>]: (newValue, oldValue, formattedValue) => void } = {} as any;
|
|
43
55
|
|
|
56
|
+
bridgedDeviceBehavior: ISYBridgedDeviceBehavior<P>;
|
|
44
57
|
///public map: ClusterMapping<ToClusterTypeByName<ClusterForBehavior<ConstructedType<typeof base>>["name"]>,ISYDeviceNode<any, any, any>>;
|
|
45
58
|
|
|
46
|
-
map:
|
|
59
|
+
map: BehaviorMapping<T, P>;
|
|
47
60
|
|
|
48
61
|
override async initialize(_options?: {}) {
|
|
49
62
|
await super.initialize(_options);
|
|
50
|
-
var behavior = await this.agent.load(ISYBridgedDeviceBehavior)
|
|
63
|
+
var behavior = (await this.agent.load(ISYBridgedDeviceBehavior)) as ISYBridgedDeviceBehavior<P>;
|
|
64
|
+
this.bridgedDeviceBehavior = behavior;
|
|
51
65
|
//var behavior = this.agent.get(ISYBridgedDeviceBehavior);
|
|
52
66
|
this._device = behavior.device as P;
|
|
67
|
+
//@ts-ignore
|
|
53
68
|
this.map = behavior.mapForBehavior<T>(this as unknown as T);
|
|
54
69
|
for (const key2 in this.map.attributes) {
|
|
55
|
-
|
|
56
|
-
|
|
70
|
+
let val = this.map.attributes[key2];
|
|
71
|
+
let driverObj = null;
|
|
72
|
+
if (typeof val === 'string' || typeof val === 'symbol' || typeof val === 'number') {
|
|
73
|
+
driverObj = this._device.drivers[val];
|
|
74
|
+
this.handlers[val] = (newValue, oldValue, formattedValue) => {
|
|
57
75
|
this.state[key2 as string] = newValue;
|
|
58
76
|
};
|
|
59
|
-
} else if (
|
|
60
|
-
|
|
77
|
+
} else if (val.driver as DriversOf<P>) {
|
|
78
|
+
driverObj = this._device.drivers[val.driver as string];
|
|
79
|
+
|
|
80
|
+
let { driver, converter } = val;
|
|
81
|
+
const convFunc = Converter.get(converter)?.from;
|
|
61
82
|
this.handlers[driver] = (newValue, oldValue, formattedValue) => {
|
|
62
|
-
this.state[key2 as string] =
|
|
83
|
+
if (convFunc) this.state[key2 as string] = convFunc(newValue);
|
|
84
|
+
else this.state[key2 as string] = newValue;
|
|
63
85
|
};
|
|
64
86
|
}
|
|
87
|
+
if (driverObj) {
|
|
88
|
+
let evt = `${driverObj.name}Changed`;
|
|
89
|
+
this.reactTo(behavior.events[evt], this.handlePropertyChange.bind(this), { lock: false });
|
|
90
|
+
}
|
|
65
91
|
}
|
|
66
92
|
|
|
67
|
-
this.reactTo(behavior.events.propertyChanged, this.handlePropertyChange, { lock: false });
|
|
93
|
+
//this.reactTo(behavior.events.propertyChanged, this.handlePropertyChange, { lock: false });
|
|
68
94
|
|
|
69
95
|
//this._device.on("PropertyChanged", this.handlePropertyChange.bind(this));
|
|
70
96
|
}
|
|
@@ -95,13 +121,5 @@ export function ISYClusterBehavior<T extends Constructor<ClusterBehavior> & { cl
|
|
|
95
121
|
}
|
|
96
122
|
};
|
|
97
123
|
}
|
|
98
|
-
// <reference path="MatterDevice.js" />
|
|
99
|
-
// @ts-ignore
|
|
100
|
-
|
|
101
|
-
export type DeviceBehavior<P extends ISYNode, T extends { cluster }> = {
|
|
102
|
-
device: P;
|
|
103
124
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
handlePropertyChange(chg: PropertyChange<P>): void;
|
|
107
|
-
};
|
|
125
|
+
// #endregion Functions (1)
|
|
@@ -1,80 +1,69 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { LevelControlInterface, LevelControlServer } from '@project-chip/matter.js/behaviors/level-control';
|
|
2
|
+
import type { OnOffBehavior, OnOffServer } from '@project-chip/matter.js/behaviors/on-off';
|
|
3
|
+
import type { MutableCluster, OnOffCluster } from '@project-chip/matter.js/cluster';
|
|
4
|
+
import { DimmableLightRequirements } from '@project-chip/matter.js/devices/DimmableLightDevice';
|
|
5
|
+
import { OnOffLightRequirements } from '@project-chip/matter.js/devices/OnOffLightDevice';
|
|
4
6
|
import { OnOffLightSwitchDevice } from '@project-chip/matter.js/devices/OnOffLightSwitchDevice';
|
|
5
7
|
import type { MaybePromise } from '@project-chip/matter.js/util';
|
|
6
|
-
import { MappingRegistry } from '../../Model/ClusterMap.js';
|
|
7
|
-
import type { MutableCluster, OnOffCluster } from '@project-chip/matter.js/cluster';
|
|
8
|
-
import type { OnOffBehavior, OnOffServer } from '@project-chip/matter.js/behaviors/on-off';
|
|
9
|
-
import type { LevelControlServer, LevelControlInterface } from '@project-chip/matter.js/behaviors/level-control';
|
|
10
8
|
import { DriverType } from '../../Definitions/Global/Drivers.js';
|
|
11
|
-
import { DimmableLightRequirements } from '@project-chip/matter.js/devices/DimmableLightDevice';
|
|
12
9
|
import { InsteonDimmableDevice } from '../../Devices/Insteon/InsteonDimmableDevice.js';
|
|
10
|
+
import { InsteonRelayDevice } from '../../Devices/Insteon/InsteonRelayDevice.js';
|
|
11
|
+
import { MappingRegistry } from '../../Model/ClusterMap.js';
|
|
12
|
+
import { ClusterForBehavior, ISYClusterBehavior, type PropertyChange } from './ISYClusterBehavior.js';
|
|
13
13
|
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export class ISYOnOffBehavior extends ISYClusterBehavior(OnOffLightRequirements.OnOffServer, InsteonRelayDevice)
|
|
21
|
-
{
|
|
22
|
-
|
|
23
|
-
override async initialize(_options?: {}) {
|
|
24
|
-
await super.initialize(_options);
|
|
25
|
-
//this.state.onOff = await this.device.state;
|
|
26
|
-
|
|
27
|
-
|
|
14
|
+
import { Converter } from '../../Converters.js';
|
|
28
15
|
|
|
29
|
-
|
|
16
|
+
export class ISYOnOffBehavior extends ISYClusterBehavior(OnOffLightRequirements.OnOffServer, InsteonRelayDevice) {
|
|
17
|
+
override async initialize(_options?: {}) {
|
|
18
|
+
await super.initialize(_options);
|
|
19
|
+
//this.state.onOff = await this.device.state;
|
|
20
|
+
}
|
|
30
21
|
|
|
22
|
+
override on = async () => {
|
|
23
|
+
await super.on();
|
|
24
|
+
await this.device.on();
|
|
31
25
|
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
//this.device.commands.DON = true;
|
|
27
|
+
};
|
|
34
28
|
|
|
29
|
+
override async off() {
|
|
30
|
+
await super.off();
|
|
31
|
+
await this.device.off();
|
|
35
32
|
|
|
36
|
-
//this.device.commands.DON = true;
|
|
37
|
-
}
|
|
38
33
|
|
|
39
|
-
override async off() {
|
|
40
|
-
//await super.off();
|
|
41
|
-
// this.device.drivers = false;
|
|
42
|
-
}
|
|
43
34
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
35
|
+
// this.device.drivers = false;
|
|
36
|
+
}
|
|
47
37
|
|
|
48
|
-
|
|
49
|
-
if (driver === "ST") {
|
|
50
|
-
this.state.onOff = newValue;
|
|
38
|
+
override toggle = async () => {
|
|
51
39
|
|
|
52
|
-
|
|
40
|
+
//this.device.state = !(await this.device.state);
|
|
41
|
+
};
|
|
53
42
|
|
|
54
|
-
|
|
55
|
-
|
|
43
|
+
override async handlePropertyChange({ driver, newValue, oldValue, formattedValue }: PropertyChange<InsteonRelayDevice>) {
|
|
44
|
+
/*if (driver === 'ST') {
|
|
45
|
+
this.state.onOff = newValue;
|
|
46
|
+
}*/
|
|
56
47
|
|
|
57
48
|
|
|
49
|
+
return super.handlePropertyChange({ driver, newValue, oldValue, formattedValue });
|
|
50
|
+
}
|
|
58
51
|
}
|
|
59
52
|
|
|
60
|
-
|
|
61
53
|
export class ISYDimmableBehavior extends ISYClusterBehavior(DimmableLightRequirements.LevelControlServer, InsteonDimmableDevice) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
54
|
+
override async initialize(_options?: {}) {
|
|
55
|
+
await super.initialize(_options);
|
|
56
|
+
this.state.currentLevel = this.device.drivers.ST.value;
|
|
57
|
+
|
|
58
|
+
//this.state.onLevel = this.device.drivers.OL;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
override setLevel(level: number): MaybePromise<void> {
|
|
62
|
+
level = Converter.Matter.LevelFrom0To255.LightingLevel.from(level);
|
|
63
|
+
if (level > 0) {
|
|
64
|
+
return this.device.sendCommand('DON', level);
|
|
65
|
+
} else {
|
|
66
|
+
return this.device.sendCommand('DOF');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|