isy-nodejs 1.0.5-alpha.1 → 1.0.6-alpha.1
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/esm/CodeGeneration/EnumFactory.js +1 -1
- package/dist/esm/CodeGeneration/EnumFactory.js.map +1 -1
- package/dist/esm/CodeGeneration/NodeClassFactory.js +5 -4
- package/dist/esm/CodeGeneration/NodeClassFactory.js.map +1 -1
- package/dist/esm/Converters.js.map +1 -1
- package/dist/esm/Definitions/Global/Drivers.js +7 -5
- package/dist/esm/Definitions/Global/Drivers.js.map +1 -1
- package/dist/esm/Devices/DynamicNode.js +19 -0
- package/dist/esm/Devices/DynamicNode.js.map +1 -0
- package/dist/esm/Devices/GenericNode.js +17 -0
- package/dist/esm/Devices/GenericNode.js.map +1 -0
- package/dist/esm/Devices/Insteon/InsteonDevice.js.map +1 -1
- package/dist/esm/Devices/Insteon/InsteonDeviceFactory.js +86 -102
- package/dist/esm/Devices/Insteon/InsteonDeviceFactory.js.map +1 -1
- package/dist/esm/Devices/Insteon/InsteonLockDevice.js +4 -5
- package/dist/esm/Devices/Insteon/InsteonLockDevice.js.map +1 -1
- package/dist/esm/Devices/Insteon/InsteonMotionSensorDevice.js +4 -5
- package/dist/esm/Devices/Insteon/InsteonMotionSensorDevice.js.map +1 -1
- package/dist/esm/Devices/Insteon/InsteonRelayDevice.js.map +1 -1
- package/dist/esm/Devices/Insteon/InsteonThermostatDevice.js +2 -24
- package/dist/esm/Devices/Insteon/InsteonThermostatDevice.js.map +1 -1
- package/dist/esm/Devices/Insteon/index.js +3 -0
- package/dist/esm/Devices/Insteon/index.js.map +1 -1
- package/dist/esm/Devices/MapsTo.js +0 -11
- package/dist/esm/Devices/MapsTo.js.map +1 -1
- package/dist/esm/Devices/NodeFactory.js +1 -1
- package/dist/esm/Devices/NodeFactory.js.map +1 -1
- package/dist/esm/Devices/ZWave/ZWaveBaseDevice.js +2 -2
- package/dist/esm/Devices/ZWave/ZWaveBaseDevice.js.map +1 -1
- package/dist/esm/Devices/ZWave/ZWaveDimmerSwitchDevice.js +2 -2
- package/dist/esm/Devices/ZWave/ZWaveDimmerSwitchDevice.js.map +1 -1
- package/dist/esm/Devices/ZWave/ZWaveLockDevice.js +5 -5
- package/dist/esm/Devices/ZWave/ZWaveLockDevice.js.map +1 -1
- package/dist/esm/ISY.js +3 -3
- package/dist/esm/ISY.js.map +1 -1
- package/dist/esm/ISYConstants.js +0 -5
- package/dist/esm/ISYConstants.js.map +1 -1
- package/dist/esm/ISYDevice.js.map +1 -1
- package/dist/esm/ISYNode.js +12 -7
- 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 +1 -1
- package/dist/esm/Matter/Behaviors/ISYBridgedDeviceBehavior.js.map +1 -1
- package/dist/esm/Matter/Behaviors/ISYClusterBehavior.js +1 -0
- package/dist/esm/Matter/Behaviors/ISYClusterBehavior.js.map +1 -1
- package/dist/esm/Matter/Bridge/Server.js +1 -1
- package/dist/esm/Matter/Bridge/Server.js.map +1 -1
- package/dist/esm/Matter/Mappings/Insteon.js +3 -5
- package/dist/esm/Matter/Mappings/Insteon.js.map +1 -1
- package/dist/esm/Matter/Mappings/MappingRegistry.js +26 -9
- package/dist/esm/Matter/Mappings/MappingRegistry.js.map +1 -1
- package/dist/esm/Utils.js.map +1 -1
- package/dist/esm/types/CodeGeneration/EnumFactory.d.ts +2 -2
- package/dist/esm/types/CodeGeneration/EnumFactory.d.ts.map +1 -1
- package/dist/esm/types/CodeGeneration/NodeClassFactory.d.ts +11 -9
- package/dist/esm/types/CodeGeneration/NodeClassFactory.d.ts.map +1 -1
- package/dist/esm/types/Converters.d.ts +25 -16
- package/dist/esm/types/Converters.d.ts.map +1 -1
- package/dist/esm/types/Definitions/Global/Drivers.d.ts.map +1 -1
- package/dist/esm/types/Devices/DynamicNode.d.ts +11 -0
- package/dist/esm/types/Devices/DynamicNode.d.ts.map +1 -0
- package/dist/esm/types/Devices/EndpointFor.d.ts +3 -3
- package/dist/esm/types/Devices/GenericNode.d.ts +9 -0
- package/dist/esm/types/Devices/GenericNode.d.ts.map +1 -0
- package/dist/esm/types/Devices/Insteon/InsteonDevice.d.ts +10 -10
- package/dist/esm/types/Devices/Insteon/InsteonDevice.d.ts.map +1 -1
- package/dist/esm/types/Devices/Insteon/InsteonDeviceFactory.d.ts +3 -4
- package/dist/esm/types/Devices/Insteon/InsteonDeviceFactory.d.ts.map +1 -1
- package/dist/esm/types/Devices/Insteon/InsteonMotionSensorDevice.d.ts +3 -3
- package/dist/esm/types/Devices/Insteon/InsteonMotionSensorDevice.d.ts.map +1 -1
- package/dist/esm/types/Devices/Insteon/InsteonRelayDevice.d.ts.map +1 -1
- package/dist/esm/types/Devices/Insteon/InsteonThermostatDevice.d.ts +2 -9
- package/dist/esm/types/Devices/Insteon/InsteonThermostatDevice.d.ts.map +1 -1
- package/dist/esm/types/Devices/Insteon/index.d.ts +3 -0
- package/dist/esm/types/Devices/Insteon/index.d.ts.map +1 -1
- package/dist/esm/types/Devices/MapsTo.d.ts +1 -3
- package/dist/esm/types/Devices/MapsTo.d.ts.map +1 -1
- package/dist/esm/types/Devices/ZWave/ZWaveBaseDevice.d.ts +2 -2
- package/dist/esm/types/Devices/ZWave/ZWaveBaseDevice.d.ts.map +1 -1
- package/dist/esm/types/Devices/ZWave/ZWaveDimmerSwitchDevice.d.ts +2 -2
- package/dist/esm/types/Devices/ZWave/ZWaveDimmerSwitchDevice.d.ts.map +1 -1
- package/dist/esm/types/Devices/ZWave/ZWaveLockDevice.d.ts +2 -1
- package/dist/esm/types/Devices/ZWave/ZWaveLockDevice.d.ts.map +1 -1
- package/dist/esm/types/ISY.d.ts.map +1 -1
- package/dist/esm/types/ISYConstants.d.ts +0 -263
- package/dist/esm/types/ISYConstants.d.ts.map +1 -1
- package/dist/esm/types/ISYDevice.d.ts.map +1 -1
- package/dist/esm/types/ISYNode.d.ts +5 -5
- package/dist/esm/types/ISYNode.d.ts.map +1 -1
- package/dist/esm/types/Matter/Behaviors/ISYBridgedDeviceBehavior.d.ts +4 -4
- package/dist/esm/types/Matter/Behaviors/ISYBridgedDeviceBehavior.d.ts.map +1 -1
- package/dist/esm/types/Matter/Behaviors/ISYClusterBehavior.d.ts +2 -2
- package/dist/esm/types/Matter/Behaviors/ISYClusterBehavior.d.ts.map +1 -1
- package/dist/esm/types/Matter/Mappings/Insteon.d.ts.map +1 -1
- package/dist/esm/types/Matter/Mappings/MappingRegistry.d.ts +35 -21
- package/dist/esm/types/Matter/Mappings/MappingRegistry.d.ts.map +1 -1
- package/dist/esm/types/Model/EnumDefinition.d.ts +1 -1
- package/dist/esm/types/Utils.d.ts +5 -5
- package/dist/esm/types/Utils.d.ts.map +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +3 -2
- package/src/CodeGeneration/EnumFactory.ts +1 -1
- package/src/CodeGeneration/NodeClassFactory.ts +7 -4
- package/src/Converters.ts +7 -4
- package/src/Definitions/Global/Drivers.ts +8 -6
- package/src/Devices/DynamicNode.ts +37 -0
- package/src/Devices/GenericNode.ts +31 -0
- package/src/Devices/Insteon/InsteonDevice.ts +0 -3
- package/src/Devices/Insteon/InsteonDeviceFactory.ts +93 -104
- package/src/Devices/Insteon/InsteonFanDevice.ts +1 -1
- package/src/Devices/Insteon/InsteonLockDevice.ts +5 -5
- package/src/Devices/Insteon/InsteonMotionSensorDevice.ts +8 -5
- package/src/Devices/Insteon/InsteonRelayDevice.ts +1 -8
- package/src/Devices/Insteon/InsteonThermostatDevice.ts +3 -20
- package/src/Devices/Insteon/index.ts +6 -0
- package/src/Devices/MapsTo.ts +0 -25
- package/src/Devices/NCD/Generated/Relay.ts +17 -14
- package/src/Devices/NodeFactory.ts +1 -1
- package/src/Devices/ZWave/ZWaveBaseDevice.ts +2 -1
- package/src/Devices/ZWave/ZWaveDimmerSwitchDevice.ts +2 -1
- package/src/Devices/ZWave/ZWaveLockDevice.ts +7 -6
- package/src/Devices/ZigBeeLegacy/Generated/Relay.ts +14 -17
- package/src/Devices/ZigBeeLegacy/Generated/Thermostat.ts +70 -87
- package/src/ISY.ts +3 -4
- package/src/ISYConstants.ts +0 -10
- package/src/ISYDevice.ts +0 -4
- package/src/ISYNode.ts +7 -2
- package/src/ISYScene.ts +3 -3
- package/src/Matter/Behaviors/ISYBridgedDeviceBehavior.ts +12 -30
- package/src/Matter/Behaviors/ISYClusterBehavior.ts +8 -7
- package/src/Matter/Bridge/Server.ts +1 -1
- package/src/Matter/Mappings/Insteon.ts +7 -7
- package/src/Matter/Mappings/MappingRegistry.ts +93 -35
- package/src/Utils.ts +21 -18
|
@@ -7,16 +7,13 @@ import { ClusterBehavior } from '@project-chip/matter.js/behavior/cluster';
|
|
|
7
7
|
|
|
8
8
|
import { EventEmitter, Observable } from '@project-chip/matter.js/util';
|
|
9
9
|
import internal from 'stream';
|
|
10
|
+
import { server } from 'typescript';
|
|
10
11
|
import type { Driver } from '../../Definitions/Global/Drivers.js';
|
|
12
|
+
import type { Family } from '../../Definitions/index.js';
|
|
11
13
|
import { ISY } from '../../ISY.js';
|
|
12
14
|
import type { ISYDevice } from '../../ISYDevice.js';
|
|
13
|
-
import { server } from 'typescript';
|
|
14
15
|
import type { ISYNode } from '../../ISYNode.js';
|
|
15
|
-
import type
|
|
16
|
-
import { MappingRegistry, type BehaviorMapping, type DeviceToClusterMap } from '../Mappings/MappingRegistry.js';
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
import { MappingRegistry, type ClusterMapping, type DeviceToClusterMap } from '../Mappings/MappingRegistry.js';
|
|
20
17
|
|
|
21
18
|
type ClusterForBehavior<B extends ClusterBehavior> = B extends ClusterBehavior.Type<infer C> ? C : never;
|
|
22
19
|
export class ISYBridgedDeviceBehavior<N extends ISYNode<any, D, any, any>, D extends ISYNode.DriverSignatures = ISYNode.DriverSignatures> extends Behavior {
|
|
@@ -27,7 +24,7 @@ export class ISYBridgedDeviceBehavior<N extends ISYNode<any, D, any, any>, D ext
|
|
|
27
24
|
declare internal: ISYBridgedDeviceBehavior.Internal;
|
|
28
25
|
declare state: ISYBridgedDeviceBehavior.State;
|
|
29
26
|
|
|
30
|
-
declare events: ISYBridgedDeviceBehavior.Events & ISYBridgedDeviceBehavior.EventsFor<N[
|
|
27
|
+
declare events: ISYBridgedDeviceBehavior.Events & ISYBridgedDeviceBehavior.EventsFor<N['drivers']>;
|
|
31
28
|
|
|
32
29
|
override async initialize(_options?: {}) {
|
|
33
30
|
await super.initialize(_options);
|
|
@@ -40,20 +37,15 @@ export class ISYBridgedDeviceBehavior<N extends ISYNode<any, D, any, any>, D ext
|
|
|
40
37
|
if (d) {
|
|
41
38
|
d.events.on('propertyChanged', this.handlePropertyChange.bind(this));
|
|
42
39
|
|
|
43
|
-
for(const f in d.drivers)
|
|
44
|
-
{
|
|
40
|
+
for (const f in d.drivers) {
|
|
45
41
|
let evt = `${d.drivers[f].name}Changed`;
|
|
46
42
|
const obs = Observable<[{ driver: string; newValue: any; oldValue: any; formattedValue: string }]>();
|
|
47
43
|
|
|
48
|
-
|
|
49
|
-
|
|
50
44
|
d.events.on(evt, (driver: string, newValue: any, oldValue: any, formattedValue: string) => obs.emit({ driver, newValue, oldValue, formattedValue }));
|
|
51
45
|
this.events[evt] = obs;
|
|
52
46
|
|
|
53
|
-
|
|
54
47
|
//@ts-ignore
|
|
55
48
|
//d.events.on(evt, (driver: string, newValue: any, oldValue: any, formattedValue: string) => this.events.emit(evt, { driver, newValue, oldValue, formattedValue } as unknown as any));
|
|
56
|
-
|
|
57
49
|
}
|
|
58
50
|
}
|
|
59
51
|
}
|
|
@@ -66,21 +58,17 @@ export class ISYBridgedDeviceBehavior<N extends ISYNode<any, D, any, any>, D ext
|
|
|
66
58
|
return this.internal.map;
|
|
67
59
|
}
|
|
68
60
|
|
|
69
|
-
mapForBehavior<B extends ClusterBehavior>(behavior: B):
|
|
70
|
-
return this.map.mapping[behavior.cluster
|
|
61
|
+
mapForBehavior<B extends ClusterBehavior>(behavior: B): ClusterMapping<B, typeof this.internal.device> {
|
|
62
|
+
return this.map.mapping[behavior.cluster.name];
|
|
71
63
|
}
|
|
72
64
|
|
|
73
65
|
handlePropertyChange(driver: string, newValue: any, oldValue: any, formattedValue: string) {
|
|
74
|
-
|
|
75
66
|
this.events.propertyChanged.emit({ driver, newValue, oldValue, formattedValue });
|
|
76
|
-
|
|
77
|
-
|
|
78
67
|
}
|
|
79
68
|
|
|
80
69
|
override [Symbol.asyncDispose]() {
|
|
81
|
-
|
|
82
70
|
this.internal.device = null;
|
|
83
|
-
|
|
71
|
+
|
|
84
72
|
|
|
85
73
|
return super[Symbol.asyncDispose]();
|
|
86
74
|
}
|
|
@@ -92,18 +80,12 @@ export namespace ISYBridgedDeviceBehavior {
|
|
|
92
80
|
map?: DeviceToClusterMap<typeof this.device, any>;
|
|
93
81
|
}
|
|
94
82
|
|
|
95
|
-
export type EventsFor<D extends {[x: string]: Driver<any,any,any>}> = {
|
|
96
|
-
[s in keyof D as `${D[s][
|
|
97
|
-
}
|
|
98
|
-
|
|
83
|
+
export type EventsFor<D extends { [x: string]: Driver<any, any, any> }> = {
|
|
84
|
+
[s in keyof D as `${D[s]['name']}Changed`]: Observable<[{ driver: s; newValue: any; oldValue: any; formattedValue: string }]>;
|
|
85
|
+
};
|
|
99
86
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
export class Events extends EventEmitter{
|
|
87
|
+
export class Events extends EventEmitter {
|
|
103
88
|
propertyChanged = Observable<[{ driver: string; newValue: any; oldValue: any; formattedValue: string }]>();
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
89
|
}
|
|
108
90
|
|
|
109
91
|
export class State {
|
|
@@ -5,8 +5,9 @@ import { Converter } from '../../Converters.js';
|
|
|
5
5
|
import type { Constructor } from '../../Devices/Constructor.js';
|
|
6
6
|
import type { DriversOf, ISYNode } from '../../ISYNode.js';
|
|
7
7
|
|
|
8
|
+
import type { ClusterMapping } from '../Mappings/MappingRegistry.js';
|
|
8
9
|
import { ISYBridgedDeviceBehavior } from './ISYBridgedDeviceBehavior.js';
|
|
9
|
-
import
|
|
10
|
+
import { isYieldExpression } from 'typescript';
|
|
10
11
|
|
|
11
12
|
// #region Type aliases (6)
|
|
12
13
|
|
|
@@ -20,7 +21,7 @@ export type DeviceBehavior<P extends ISYNode<any, any, any, any>, T extends { cl
|
|
|
20
21
|
bridgedDeviceBehavior: ISYBridgedDeviceBehavior<P>;
|
|
21
22
|
|
|
22
23
|
//ts-ignore
|
|
23
|
-
map:
|
|
24
|
+
map: ClusterMapping<T, P>;
|
|
24
25
|
|
|
25
26
|
handlePropertyChange(chg: PropertyChange<P>): void;
|
|
26
27
|
};
|
|
@@ -49,7 +50,7 @@ export function ISYClusterBehavior<T extends Constructor<ClusterBehavior> & { cl
|
|
|
49
50
|
bridgedDeviceBehavior: ISYBridgedDeviceBehavior<P>;
|
|
50
51
|
///public map: ClusterMapping<ToClusterTypeByName<ClusterForBehavior<ConstructedType<typeof base>>["name"]>,ISYDeviceNode<any, any, any>>;
|
|
51
52
|
|
|
52
|
-
map:
|
|
53
|
+
map: ClusterMapping<T, P>;
|
|
53
54
|
|
|
54
55
|
override async initialize(_options?: {}) {
|
|
55
56
|
await super.initialize(_options);
|
|
@@ -58,6 +59,7 @@ export function ISYClusterBehavior<T extends Constructor<ClusterBehavior> & { cl
|
|
|
58
59
|
this.bridgedDeviceBehavior = behavior;
|
|
59
60
|
//var behavior = this.agent.get(ISYBridgedDeviceBehavior);
|
|
60
61
|
this._device = behavior.device as P;
|
|
62
|
+
this._device.logger('Initializing cluster behavior');
|
|
61
63
|
//@ts-ignore
|
|
62
64
|
|
|
63
65
|
this.map = behavior.mapForBehavior<T>(this as unknown as T);
|
|
@@ -70,17 +72,16 @@ export function ISYClusterBehavior<T extends Constructor<ClusterBehavior> & { cl
|
|
|
70
72
|
this.handlers[val] = (newValue, oldValue, formattedValue) => {
|
|
71
73
|
this.state[key2 as string] = newValue;
|
|
72
74
|
};
|
|
73
|
-
|
|
74
|
-
} else if (val.driver as DriversOf<P>) {
|
|
75
|
+
} else if (val.driver as keyof DriversOf<P>) {
|
|
75
76
|
driverObj = this._device.drivers[val.driver as string];
|
|
76
77
|
|
|
77
78
|
let { driver, converter } = val;
|
|
78
79
|
const convFunc = Converter.get(converter)?.to;
|
|
79
|
-
if(!convFunc) throw new Error(`Converter ${converter} not found`);
|
|
80
|
+
if (!convFunc) throw new Error(`Converter ${converter} not found`);
|
|
80
81
|
this.state[key2 as string] = convFunc(this._device.drivers[driver as string].value);
|
|
81
82
|
this.handlers[driver] = (newValue, oldValue, formattedValue) => {
|
|
82
83
|
//if (convFunc) this.state[key2 as string] = convFunc(newValue);
|
|
83
|
-
|
|
84
|
+
this.state[key2 as string] = convFunc(newValue);
|
|
84
85
|
};
|
|
85
86
|
}
|
|
86
87
|
if (driverObj) {
|
|
@@ -354,7 +354,7 @@ async function initializeConfiguration(isy: ISY, config?: Config): Promise<Confi
|
|
|
354
354
|
});
|
|
355
355
|
|
|
356
356
|
logger.info(`Matter storage location: ${storageService.location} (Directory)`);
|
|
357
|
-
logger.info(`Matter storage service type: ${storageService.factory.name}`);
|
|
357
|
+
//logger.info(`Matter storage service type: ${storageService.factory.name}`);
|
|
358
358
|
|
|
359
359
|
const deviceStorage = (await storageService.open('bridge')).createContext('data');
|
|
360
360
|
|
|
@@ -6,7 +6,7 @@ import * as Insteon from '../../Devices/Insteon/index.js';
|
|
|
6
6
|
//import InsteonMap from "./Insteon.json";
|
|
7
7
|
|
|
8
8
|
import { OnOffLightDevice, DimmableLightDevice } from '@matter/node/devices';
|
|
9
|
-
import {
|
|
9
|
+
import { MappingRegistry, type EndpointMapping, type FamilyToClusterMap } from './MappingRegistry.js';
|
|
10
10
|
|
|
11
11
|
export const map: FamilyToClusterMap<Family.Insteon> = {
|
|
12
12
|
Family: Family.Insteon,
|
|
@@ -16,7 +16,7 @@ export const map: FamilyToClusterMap<Family.Insteon> = {
|
|
|
16
16
|
mapping: {
|
|
17
17
|
OnOff: {
|
|
18
18
|
attributes: {
|
|
19
|
-
onOff: { driver: 'ST', converter: '
|
|
19
|
+
onOff: { driver: 'ST', converter: 'LightingLevel.Boolean' }
|
|
20
20
|
},
|
|
21
21
|
commands: { on: 'DON' }
|
|
22
22
|
}
|
|
@@ -44,7 +44,8 @@ export const map: FamilyToClusterMap<Family.Insteon> = {
|
|
|
44
44
|
},
|
|
45
45
|
commands: { on: 'DON' }
|
|
46
46
|
},
|
|
47
|
-
|
|
47
|
+
|
|
48
|
+
|
|
48
49
|
LevelControl: {
|
|
49
50
|
// @ts-ignore
|
|
50
51
|
attributes: {
|
|
@@ -60,7 +61,7 @@ export const map: FamilyToClusterMap<Family.Insteon> = {
|
|
|
60
61
|
deviceType: DimmableLightDevice,
|
|
61
62
|
// @ts-ignore
|
|
62
63
|
mapping: {
|
|
63
|
-
|
|
64
|
+
|
|
64
65
|
OnOff: {
|
|
65
66
|
attributes: {
|
|
66
67
|
onOff: { driver: 'ST', converter: 'Percent.Boolean' }
|
|
@@ -81,9 +82,8 @@ export const map: FamilyToClusterMap<Family.Insteon> = {
|
|
|
81
82
|
}
|
|
82
83
|
};
|
|
83
84
|
|
|
84
|
-
map.KeypadDimmer = map.DimmerLamp;
|
|
85
|
-
map.KeypadRelay = map.
|
|
86
|
-
|
|
85
|
+
map.KeypadDimmer = {...map.DimmerLamp};
|
|
86
|
+
map.KeypadRelay = {...map.RelayLamp};
|
|
87
87
|
|
|
88
88
|
|
|
89
89
|
|
|
@@ -1,34 +1,36 @@
|
|
|
1
|
-
import * as Clusters from '@
|
|
1
|
+
import type * as Clusters from '@matter/types/clusters';
|
|
2
|
+
import * as Cluster from '@matter/types/cluster'
|
|
2
3
|
|
|
3
4
|
import type { Converter } from '../../Converters.js';
|
|
4
5
|
import { DriverType } from '../../Definitions/Global/Drivers.js';
|
|
5
6
|
import { Devices, Insteon } from '../../Devices/index.js';
|
|
6
|
-
|
|
7
|
+
import type {Simplify, SimplifyDeep} from 'type-fest';
|
|
7
8
|
import { ClusterBehavior, MutableEndpoint, SupportedBehaviors } from '@matter/main';
|
|
8
|
-
import
|
|
9
|
+
import { DimmableLightDevice, OnOffLightDevice } from '@matter/main/devices';
|
|
9
10
|
import { BridgedDeviceBasicInformationBehavior } from '@matter/node/behaviors';
|
|
10
11
|
import type { DeviceTypeDefinition } from '@project-chip/matter.js/device';
|
|
11
12
|
import { Family } from '../../Definitions/index.js';
|
|
13
|
+
import type { Constructor } from '../../Devices/Constructor.js';
|
|
12
14
|
import { NodeFactory } from '../../Devices/NodeFactory.js';
|
|
13
15
|
import { CommandsOf, DriversOf, ISYNode } from '../../ISYNode.js';
|
|
16
|
+
import { ClusterType } from '../../Model/ClusterType.js';
|
|
17
|
+
import type { PathsWithLimit, PickOfType, Remove } from '../../Utils.js';
|
|
14
18
|
import { ISYBridgedDeviceBehavior } from '../Behaviors/ISYBridgedDeviceBehavior.js';
|
|
15
19
|
import { ISYOnOffBehavior } from '../Behaviors/Insteon/ISYOnOffBehavior.js';
|
|
16
|
-
import type { PathsWithLimit, PickOfType, Remove } from '../../Utils.js';
|
|
17
|
-
import { ClusterType } from '../../Model/ClusterType.js';
|
|
18
|
-
import type { Constructor } from '../../Devices/Constructor.js';
|
|
19
20
|
|
|
20
21
|
// #region Type aliases (16)
|
|
21
22
|
|
|
22
23
|
export type AttributeMapping<B, D> =
|
|
23
|
-
B extends { cluster: { attributes: infer E extends { [K in string]:
|
|
24
|
+
B extends { cluster: { attributes: infer E extends { [K in string]: Cluster.ClusterType.Attribute } } } ?
|
|
24
25
|
Partial<Record<keyof E, keyof DriversOf<D> | { driver: keyof DriversOf<D>; converter?: Converter.KnownConverters }>>
|
|
25
26
|
: never;
|
|
26
|
-
export type
|
|
27
|
-
attributes?:
|
|
28
|
-
commands?:
|
|
27
|
+
export type ClusterMapping<B, T extends ISYNode<any, any, any, any>> = {
|
|
28
|
+
attributes?: ClusterAttributeMapping<B, T>;
|
|
29
|
+
commands?: ClusterCommandMapping<B, T>;
|
|
30
|
+
|
|
29
31
|
};
|
|
30
32
|
export type ClusterAttributeMapping<A, K> = {
|
|
31
|
-
[key in keyof
|
|
33
|
+
[key in keyof Cluster.ClusterType.AttributesOf<A>]: { driver: Extract<keyof DriversOf<K>, string>; converter?: Converter.KnownConverters } | Extract<keyof DriversOf<K>, string>;
|
|
32
34
|
};
|
|
33
35
|
// export type ClusterTypeCommandMapping<A extends ClusterType, K> = {
|
|
34
36
|
// [key in keyof Clusters.ClusterType.CommandsOf<ToCompleteClusterByName<A>>]?:
|
|
@@ -36,7 +38,7 @@ export type ClusterAttributeMapping<A, K> = {
|
|
|
36
38
|
// | CommandsOf<K>
|
|
37
39
|
// };
|
|
38
40
|
export type ClusterCommandMapping<A, K> = {
|
|
39
|
-
[key in keyof
|
|
41
|
+
[key in keyof Cluster.ClusterType.CommandsOf<A>]: { command: keyof CommandsOf<K>; parameters?: parameterMapping } | keyof CommandsOf<K>;
|
|
40
42
|
};
|
|
41
43
|
//export type FamilyToDeviceMap<T extends Family> = Record<keyof Devices<T>, DeviceToClusterMap<ISYDevice<T>>>;
|
|
42
44
|
|
|
@@ -44,14 +46,14 @@ export type ClusterCommandMapping<A, K> = {
|
|
|
44
46
|
// attributes: ClusterTypeAttributeMapping<A,K>,
|
|
45
47
|
// commands: ClusterTypeCommandMapping<A,K>
|
|
46
48
|
// };
|
|
47
|
-
export type ClusterMapping<A, K> = {
|
|
49
|
+
/*export type ClusterMapping<A, K> = {
|
|
48
50
|
attributes: ClusterAttributeMapping<A, K>;
|
|
49
51
|
commands: ClusterCommandMapping<A, K>;
|
|
50
|
-
}
|
|
52
|
+
};*/
|
|
51
53
|
export type CommandMapping<B, D> =
|
|
52
54
|
B extends (
|
|
53
55
|
{
|
|
54
|
-
cluster: { commands: infer E extends { [K in string]:
|
|
56
|
+
cluster: { commands: infer E extends { [K in string]: Cluster.ClusterType.Command } };
|
|
55
57
|
}
|
|
56
58
|
) ?
|
|
57
59
|
Partial<Record<keyof E, keyof CommandsOf<D> | { command: keyof CommandsOf<D>; parameters?: parameterMapping }>>
|
|
@@ -89,12 +91,43 @@ export type CommandMapping<B, D> =
|
|
|
89
91
|
// behavior?: typeof ClusterBehavior;
|
|
90
92
|
|
|
91
93
|
// }
|
|
92
|
-
export
|
|
94
|
+
export interface DeviceToClusterMap<T extends ISYNode<Family, any, any, any>, D extends MutableEndpoint> {
|
|
93
95
|
deviceType: D;
|
|
94
96
|
mapping: EndpointMapping<D, T>;
|
|
95
97
|
};
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
export interface Mapping<T extends ISYNode, D extends MutableEndpoint> {
|
|
103
|
+
deviceType: D;
|
|
104
|
+
|
|
105
|
+
nodeType?: T;
|
|
106
|
+
mapping?: {
|
|
107
|
+
[K in keyof D['behaviors']]?:
|
|
108
|
+
{attributes?: {
|
|
109
|
+
[K2 in keyof Cluster.ClusterType.AttributesOf<D['behaviors'][K]>]: { driver: keyof DriversOf<T>; converter?: Converter.KnownConverters } | keyof DriversOf<T>;
|
|
110
|
+
},
|
|
111
|
+
commands?: {
|
|
112
|
+
[K2 in keyof Cluster.ClusterType.CommandsOf<D['behaviors'][K]>]: { command: keyof CommandsOf<T>; converter?: Converter.KnownConverters } | keyof CommandsOf<T>;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function addA<T extends ISYNode<any,any,any,any>,D extends MutableEndpoint>(mapping1: Mapping<T,D>, mapping2: Mapping<T,D>) : Mapping<T,D> {
|
|
122
|
+
return {deviceType: mapping1.deviceType, nodeType: mapping1.nodeType, mapping: {...mapping1.mapping, ...mapping2.mapping}};
|
|
123
|
+
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
96
129
|
export type EndpointMapping<A extends MutableEndpoint, D extends ISYNode<Family, any, any, any>> = {
|
|
97
|
-
[K in StringKeys<
|
|
130
|
+
[K in StringKeys<A['behaviors']>]?: ClusterMapping<A['behaviors'][K],D> //{
|
|
98
131
|
/*attributes?: AttributeMapping<A['behaviors'][Uncapitalize<K>], D>;
|
|
99
132
|
commands?: CommandMapping<A['behaviors'][Uncapitalize<K>], D>;*/
|
|
100
133
|
//};
|
|
@@ -124,13 +157,20 @@ export type FamilyToClusterMap<T extends SupportedFamily> = { Family: T } & {
|
|
|
124
157
|
[Type in Extract<keyof Devices.Insteon, `${string}Node`> as Remove<Type, 'Node'>]?: DeviceToClusterMap<InstanceType<Devices.Insteon[Type]>, MutableEndpoint>;
|
|
125
158
|
};
|
|
126
159
|
|
|
160
|
+
interface ISYtoMatterMapping<N extends ISYNode, M extends MutableEndpoint> extends DeviceToClusterMap<N, M> {
|
|
161
|
+
|
|
127
162
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function add<const F extends SupportedFamily, const T extends ISYNode<F>, const D extends MutableEndpoint>(
|
|
166
|
+
familyToClusterMap: FamilyToClusterMap<F>,
|
|
167
|
+
deviceClass: Constructor<T>,
|
|
168
|
+
mapping: DeviceToClusterMap<T, D>
|
|
169
|
+
) {
|
|
170
|
+
const map = {};
|
|
171
|
+
map[deviceClass.name] = mapping;
|
|
132
172
|
|
|
133
|
-
|
|
173
|
+
return { ...map, ...familyToClusterMap };
|
|
134
174
|
}
|
|
135
175
|
export type SBAttributeMapping<SB extends SupportedBehaviors, D> = {
|
|
136
176
|
[K in keyof SB]: Partial<Record<any, DriversOf<D> | { driver: DriversOf<D>; converter?: string }>>;
|
|
@@ -140,7 +180,7 @@ export type SBCommandMapping<SB extends SupportedBehaviors, D> = {
|
|
|
140
180
|
[K in Capitalize<keyof SB>]?: SB[Uncapitalize<K>] extends { cluster: { commands } } ? Partial<Record<string, CommandsOf<D> | { driver: DriversOf<D>; converter?: string }>> : never;
|
|
141
181
|
};
|
|
142
182
|
type StringKeys<T> = Extract<keyof T, string>;
|
|
143
|
-
type a =
|
|
183
|
+
type a = Cluster.ClusterType.CommandsOf<OnOffLightDevice['behaviors']['onOff']['cluster']>;
|
|
144
184
|
type d = FamilyToClusterMap<Family.Insteon>;
|
|
145
185
|
export type parameterMapping = {
|
|
146
186
|
[key: string]: { parameter: string; converter?: string };
|
|
@@ -192,16 +232,18 @@ export class MappingRegistry {
|
|
|
192
232
|
return m;
|
|
193
233
|
}
|
|
194
234
|
|
|
195
|
-
public static getMappingForBehavior<T extends ISYNode<any, any, any, any>, const B extends ClusterBehavior>(device: T, behavior: B):
|
|
235
|
+
public static getMappingForBehavior<T extends ISYNode<any, any, any, any>, const B extends ClusterBehavior>(device: T, behavior: B): ClusterMapping<B, T> {
|
|
196
236
|
//var m = MappingRegistry.getMapping(device);
|
|
197
237
|
|
|
198
238
|
//return m[behavior.cluster.name];
|
|
199
239
|
for (var m in MappingRegistry.getMapping(device).mapping) {
|
|
200
|
-
if (behavior.cluster.name === m) return MappingRegistry.getMapping(device).mapping[m] as unknown as
|
|
240
|
+
if (behavior.cluster.name === m) return MappingRegistry.getMapping(device).mapping[m] as unknown as ClusterMapping<B, T>;
|
|
201
241
|
}
|
|
202
242
|
}
|
|
203
243
|
//@ts-ignore
|
|
204
|
-
public static register<const T extends Family.Insteon | Family.ZWave | Family.ZigBee>(
|
|
244
|
+
public static register<const T extends Family.Insteon | Family.ZWave | Family.ZigBee>(
|
|
245
|
+
map: Partial<FamilyToClusterMap<T>> | { [x in PathsWithLimit<typeof Devices, 1>]: DeviceToClusterMap<any, any> }
|
|
246
|
+
) {
|
|
205
247
|
if ('Family' in map) {
|
|
206
248
|
let regMap: Map<string, DeviceToClusterMap<any, any>>;
|
|
207
249
|
if (!MappingRegistry.map.has(map.Family)) {
|
|
@@ -256,16 +298,32 @@ var clusterMap = {
|
|
|
256
298
|
moveToColor: { command: DriverType.CustomControl1, parameters: { colorX: { parameter: 'colorX' }, colorY: { parameter: 'colorY' }, colorTemperature: { parameter: 'colorTemperature' } } }
|
|
257
299
|
}
|
|
258
300
|
};
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
interface SimplyEndpointMapping<T extends ISYNode<Family, any, any, any>,K extends MutableEndpoint> extends SimplifyDeep<ISYtoMatterMapping<T,K>> {}
|
|
304
|
+
|
|
305
|
+
/*
|
|
306
|
+
const map = {
|
|
307
|
+
deviceType: DimmableLightDevice,
|
|
308
|
+
mapping: {
|
|
309
|
+
|
|
310
|
+
onOff: {
|
|
311
|
+
attributes: {
|
|
312
|
+
onOff: { driver: 'ST', converter: 'Percent.Boolean' },
|
|
313
|
+
|
|
314
|
+
},
|
|
315
|
+
commands: {
|
|
316
|
+
onWithTimedOff: { command: 'DON' },
|
|
317
|
+
|
|
318
|
+
}
|
|
264
319
|
},
|
|
265
|
-
|
|
266
|
-
|
|
320
|
+
levelControl: {
|
|
321
|
+
attributes: {
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
}
|
|
267
325
|
}
|
|
268
326
|
}
|
|
269
|
-
}
|
|
270
|
-
|
|
327
|
+
} as Mapping<Insteon.RelayLampNode, DimmableLightDevice>;
|
|
328
|
+
*/
|
|
271
329
|
// #endregion Variables (3)
|
package/src/Utils.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
import * as log4js from '@log4js-node/log4js-api';
|
|
3
2
|
import winston, { Logger, format, type LeveledLogMethod, type LogMethod } from 'winston';
|
|
4
3
|
|
|
@@ -7,32 +6,26 @@ import { Category } from './Definitions/Global/Categories.js';
|
|
|
7
6
|
|
|
8
7
|
//import { get } from 'http';
|
|
9
8
|
import type { PackageJson } from '@npmcli/package-json';
|
|
9
|
+
import type { Axios, AxiosRequestConfig } from 'axios';
|
|
10
10
|
import { existsSync } from 'fs';
|
|
11
11
|
import { readFile } from 'fs/promises';
|
|
12
12
|
import path from 'path';
|
|
13
13
|
import { Family } from './Definitions/index.js';
|
|
14
14
|
import { EventType } from './Events/EventType.js';
|
|
15
|
-
import type { Axios, AxiosRequestConfig } from 'axios';
|
|
16
15
|
|
|
17
16
|
export type StringKeys<T> = Extract<keyof T, string>;
|
|
18
17
|
|
|
19
|
-
export type PickOfType<T, U> = {
|
|
18
|
+
export type PickOfType<T, U> = {
|
|
19
|
+
[K in keyof T]: T[K] extends U ?
|
|
20
|
+
any extends T[K] ?
|
|
21
|
+
never
|
|
22
|
+
: K
|
|
23
|
+
: undefined;
|
|
24
|
+
}[keyof T];
|
|
20
25
|
|
|
21
26
|
export type Paths<T> = T extends object ? { [K in keyof T]: `${Exclude<K, symbol>}${'' | `.${Paths<T[K]>}`}` }[keyof T] : never;
|
|
22
27
|
|
|
23
|
-
export type Prev = [never, 0,1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
export type RelaxTypes<V> =
|
|
27
|
-
V extends number ? number
|
|
28
|
-
: V extends bigint ? bigint
|
|
29
|
-
: V extends object ?
|
|
30
|
-
V extends (...args: any[]) => any ?
|
|
31
|
-
V
|
|
32
|
-
: {
|
|
33
|
-
[K in keyof V]: RelaxTypes<V[K]>;
|
|
34
|
-
}
|
|
35
|
-
: V;
|
|
28
|
+
export type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
36
29
|
|
|
37
30
|
|
|
38
31
|
export type Join<K, P> =
|
|
@@ -61,12 +54,12 @@ export type Remove<K extends string, T extends string> = K extends `${infer L}${
|
|
|
61
54
|
|
|
62
55
|
export type ReplaceAll<K extends string, T extends string, U extends string> = K extends `${infer L}${T}${infer R}` ? `${L}${U}${ReplaceAll<R, T, U>}` : K;
|
|
63
56
|
|
|
64
|
-
|
|
65
57
|
export function getEnumKeyByEnumValue<E extends { [index: string]: number }, T extends E[keyof E]>(enumType: E, enumValue: E[T]): T {
|
|
66
58
|
return Object.keys(enumType).find((key) => enumType[key] === enumValue) as unknown as T;
|
|
67
59
|
}
|
|
68
60
|
|
|
69
61
|
|
|
62
|
+
|
|
70
63
|
export type LogLevel = PickOfType<winston.Logger, LeveledLogMethod>;
|
|
71
64
|
export type ValuesOf<TEnum extends number | string | boolean | bigint> = `${TEnum}` extends `${infer R extends number}` ? R : `${TEnum}`;
|
|
72
65
|
|
|
@@ -96,7 +89,7 @@ export function fromArray<T>(...value: T[]): MaybeArray<T> {
|
|
|
96
89
|
|
|
97
90
|
export type BaseRequestConfig = Pick<AxiosRequestConfig, 'auth' | 'baseURL' | 'socketPath'>;
|
|
98
91
|
|
|
99
|
-
export type ISYRequestConfig = Omit<AxiosRequestConfig, keyof BaseRequestConfig | 'method'
|
|
92
|
+
export type ISYRequestConfig = Omit<AxiosRequestConfig, keyof BaseRequestConfig | 'method'>;
|
|
100
93
|
|
|
101
94
|
export function byteToPct(value) {
|
|
102
95
|
return Math.round((value * 100) / 255);
|
|
@@ -367,3 +360,13 @@ export function logStringify(obj: any, indent = 2) {
|
|
|
367
360
|
cache = null;
|
|
368
361
|
return retVal;
|
|
369
362
|
}
|
|
363
|
+
export type RelaxTypes<V> =
|
|
364
|
+
V extends number ? number
|
|
365
|
+
: V extends bigint ? bigint
|
|
366
|
+
: V extends object ?
|
|
367
|
+
V extends (...args: any[]) => any ?
|
|
368
|
+
V
|
|
369
|
+
: {
|
|
370
|
+
[K in keyof V]: RelaxTypes<V[K]>;
|
|
371
|
+
}
|
|
372
|
+
: V;
|