@switchbot/homebridge-switchbot 3.5.0-beta.22 → 3.5.0-beta.24
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/config.schema.json +23 -2
- package/dist/device/blindtilt.d.ts +21 -98
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +332 -785
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +25 -75
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +566 -778
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +13 -71
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +168 -606
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +13 -78
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +218 -655
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +14 -69
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +196 -553
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +17 -90
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +324 -810
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +58 -0
- package/dist/device/device.d.ts.map +1 -0
- package/dist/device/device.js +629 -0
- package/dist/device/device.js.map +1 -0
- package/dist/device/hub.d.ts +15 -63
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +223 -610
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +10 -69
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +192 -595
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +11 -68
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +156 -599
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +10 -72
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +204 -591
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +15 -66
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +199 -566
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +13 -67
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +152 -592
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +13 -68
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +151 -599
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +13 -73
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +129 -540
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -61
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +71 -476
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +11 -66
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +122 -471
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +9 -66
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +105 -478
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +5 -36
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +228 -337
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +5 -34
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +19 -267
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +5 -34
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +13 -261
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +5 -34
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +13 -260
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +39 -0
- package/dist/irdevice/irdevice.d.ts.map +1 -0
- package/dist/irdevice/irdevice.js +502 -0
- package/dist/irdevice/irdevice.js.map +1 -0
- package/dist/irdevice/light.d.ts +5 -34
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +13 -267
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +18 -48
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +349 -551
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +7 -40
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +79 -325
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +6 -36
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +38 -288
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +6 -36
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +39 -291
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/settings.d.ts +15 -2
- package/dist/settings.d.ts.map +1 -1
- package/dist/utils.d.ts +68 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +71 -0
- package/dist/utils.js.map +1 -1
- package/package.json +8 -8
- package/src/device/blindtilt.ts +356 -809
- package/src/device/bot.ts +601 -865
- package/src/device/ceilinglight.ts +182 -628
- package/src/device/colorbulb.ts +235 -683
- package/src/device/contact.ts +220 -575
- package/src/device/curtain.ts +344 -836
- package/src/device/device.ts +655 -0
- package/src/device/hub.ts +246 -636
- package/src/device/humidifier.ts +224 -645
- package/src/device/iosensor.ts +181 -625
- package/src/device/lightstrip.ts +230 -622
- package/src/device/lock.ts +236 -607
- package/src/device/meter.ts +177 -616
- package/src/device/meterplus.ts +175 -624
- package/src/device/motion.ts +147 -563
- package/src/device/plug.ts +81 -505
- package/src/device/robotvacuumcleaner.ts +139 -494
- package/src/device/waterdetector.ts +126 -506
- package/src/irdevice/airconditioner.ts +228 -353
- package/src/irdevice/airpurifier.ts +23 -282
- package/src/irdevice/camera.ts +18 -277
- package/src/irdevice/fan.ts +18 -275
- package/src/irdevice/irdevice.ts +518 -0
- package/src/irdevice/light.ts +18 -283
- package/src/irdevice/other.ts +394 -621
- package/src/irdevice/tv.ts +97 -344
- package/src/irdevice/vacuumcleaner.ts +46 -310
- package/src/irdevice/waterheater.ts +47 -315
- package/src/settings.ts +20 -3
- package/src/utils.ts +71 -0
package/src/irdevice/other.ts
CHANGED
|
@@ -1,67 +1,90 @@
|
|
|
1
|
-
|
|
1
|
+
/* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* other.ts: @switchbot/homebridge-switchbot.
|
|
4
|
+
*/
|
|
2
5
|
import { request } from 'undici';
|
|
6
|
+
import { irdeviceBase } from './irdevice.js';
|
|
3
7
|
import { SwitchBotPlatform } from '../platform.js';
|
|
4
|
-
import { Devices, irDevicesConfig, irdevice
|
|
8
|
+
import { Devices, irDevicesConfig, irdevice } from '../settings.js';
|
|
9
|
+
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
5
10
|
|
|
6
11
|
/**
|
|
7
12
|
* Platform Accessory
|
|
8
13
|
* An instance of this class is created for each accessory your platform registers
|
|
9
14
|
* Each accessory may expose multiple services of different service types.
|
|
10
15
|
*/
|
|
11
|
-
export class Others {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
16
|
+
export class Others extends irdeviceBase {
|
|
17
|
+
|
|
18
|
+
private Switch?: {
|
|
19
|
+
Service: Service;
|
|
20
|
+
On: CharacteristicValue;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
private GarageDoor?: {
|
|
24
|
+
Service: Service;
|
|
25
|
+
On: CharacteristicValue;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
private Door?: {
|
|
29
|
+
Service: Service;
|
|
30
|
+
On: CharacteristicValue;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
private Window?: {
|
|
34
|
+
Service: Service;
|
|
35
|
+
On: CharacteristicValue;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
private WindowCovering?: {
|
|
39
|
+
Service: Service;
|
|
40
|
+
On: CharacteristicValue;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
private Lock?: {
|
|
44
|
+
Service: Service;
|
|
45
|
+
On: CharacteristicValue;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
private Faucet?: {
|
|
49
|
+
Service: Service;
|
|
50
|
+
On: CharacteristicValue;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
private Fan?: {
|
|
54
|
+
Service: Service;
|
|
55
|
+
On: CharacteristicValue;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
private StatefulProgrammableSwitch?: {
|
|
59
|
+
Service: Service;
|
|
60
|
+
On: CharacteristicValue;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
private Outlet?: {
|
|
64
|
+
Service: Service;
|
|
65
|
+
On: CharacteristicValue;
|
|
66
|
+
};
|
|
31
67
|
|
|
32
68
|
// Config
|
|
33
|
-
deviceLogging!: string;
|
|
34
|
-
disablePushOn?: boolean;
|
|
35
69
|
otherDeviceType?: string;
|
|
36
|
-
disablePushOff?: boolean;
|
|
37
70
|
|
|
38
71
|
constructor(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
72
|
+
readonly platform: SwitchBotPlatform,
|
|
73
|
+
accessory: PlatformAccessory,
|
|
74
|
+
device: irdevice & irDevicesConfig,
|
|
42
75
|
) {
|
|
43
|
-
|
|
44
|
-
this.log = this.platform.log;
|
|
45
|
-
this.config = this.platform.config;
|
|
46
|
-
this.hap = this.api.hap;
|
|
47
|
-
// default placeholders
|
|
48
|
-
this.deviceLogs(device);
|
|
49
|
-
this.deviceType(device);
|
|
50
|
-
this.deviceContext();
|
|
51
|
-
this.disablePushOnChanges(device);
|
|
52
|
-
this.disablePushOffChanges(device);
|
|
53
|
-
this.deviceConfig(device);
|
|
76
|
+
super(platform, accessory, device);
|
|
54
77
|
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
-
.getService(this.hap.Service.AccessoryInformation)!
|
|
58
|
-
.setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
|
|
59
|
-
.setCharacteristic(this.hap.Characteristic.Model, device.remoteType)
|
|
60
|
-
.setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
|
|
61
|
-
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
|
|
78
|
+
// default placeholders
|
|
79
|
+
this.getOtherConfigSettings(device);
|
|
62
80
|
|
|
63
81
|
// deviceType
|
|
64
82
|
if (this.otherDeviceType === 'switch') {
|
|
83
|
+
// Initialize Switch property
|
|
84
|
+
this.Switch = {
|
|
85
|
+
Service: accessory.addService(this.hap.Service.Switch),
|
|
86
|
+
On: accessory.context.On || true,
|
|
87
|
+
};
|
|
65
88
|
this.removeFanService(accessory);
|
|
66
89
|
this.removeLockService(accessory);
|
|
67
90
|
this.removeDoorService(accessory);
|
|
@@ -72,18 +95,20 @@ export class Others {
|
|
|
72
95
|
this.removeWindowCoveringService(accessory);
|
|
73
96
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
74
97
|
|
|
75
|
-
// Add
|
|
76
|
-
const
|
|
77
|
-
(this.
|
|
78
|
-
|| accessory.addService(this.hap.Service.Switch)),
|
|
98
|
+
// Add Switch Service
|
|
99
|
+
const SwitchService = `${accessory.displayName} Switch`;
|
|
100
|
+
(this.Switch!.Service = accessory.getService(this.hap.Service.Switch) as Service
|
|
101
|
+
|| accessory.addService(this.hap.Service.Switch)), SwitchService;
|
|
79
102
|
this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Switch`);
|
|
80
103
|
|
|
81
|
-
this.
|
|
82
|
-
|
|
83
|
-
this.switchService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
84
|
-
}
|
|
85
|
-
this.switchService.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
104
|
+
this.Switch!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
105
|
+
this.Switch!.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
86
106
|
} else if (this.otherDeviceType === 'garagedoor') {
|
|
107
|
+
// Initialize Garage Door property
|
|
108
|
+
this.GarageDoor = {
|
|
109
|
+
Service: accessory.addService(this.hap.Service.GarageDoorOpener),
|
|
110
|
+
On: accessory.context.On || true,
|
|
111
|
+
};
|
|
87
112
|
this.removeFanService(accessory);
|
|
88
113
|
this.removeLockService(accessory);
|
|
89
114
|
this.removeDoorService(accessory);
|
|
@@ -94,19 +119,21 @@ export class Others {
|
|
|
94
119
|
this.removeWindowCoveringService(accessory);
|
|
95
120
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
96
121
|
|
|
97
|
-
// Add
|
|
98
|
-
const
|
|
99
|
-
(this.
|
|
100
|
-
|| accessory.addService(this.hap.Service.GarageDoorOpener)),
|
|
122
|
+
// Add GarageDoor Service
|
|
123
|
+
const GarageDoorService = `${accessory.displayName} Garage Door Opener`;
|
|
124
|
+
(this.GarageDoor!.Service = accessory.getService(this.hap.Service.GarageDoorOpener) as Service
|
|
125
|
+
|| accessory.addService(this.hap.Service.GarageDoorOpener)), GarageDoorService;
|
|
101
126
|
this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Garage Door Opener`);
|
|
102
127
|
|
|
103
|
-
this.
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
this.garageDoorService.getCharacteristic(this.hap.Characteristic.TargetDoorState).onSet(this.OnSet.bind(this));
|
|
108
|
-
this.garageDoorService.setCharacteristic(this.hap.Characteristic.ObstructionDetected, false);
|
|
128
|
+
this.GarageDoor!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
129
|
+
this.GarageDoor!.Service.getCharacteristic(this.hap.Characteristic.TargetDoorState).onSet(this.OnSet.bind(this));
|
|
130
|
+
this.GarageDoor!.Service.setCharacteristic(this.hap.Characteristic.ObstructionDetected, false);
|
|
109
131
|
} else if (this.otherDeviceType === 'door') {
|
|
132
|
+
// Initialize Door property
|
|
133
|
+
this.Door = {
|
|
134
|
+
Service: accessory.addService(this.hap.Service.Door),
|
|
135
|
+
On: accessory.context.On || true,
|
|
136
|
+
};
|
|
110
137
|
this.removeFanService(accessory);
|
|
111
138
|
this.removeLockService(accessory);
|
|
112
139
|
this.removeOutletService(accessory);
|
|
@@ -117,17 +144,14 @@ export class Others {
|
|
|
117
144
|
this.removeWindowCoveringService(accessory);
|
|
118
145
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
119
146
|
|
|
120
|
-
// Add
|
|
121
|
-
const
|
|
122
|
-
(this.
|
|
123
|
-
|| accessory.addService(this.hap.Service.Door)),
|
|
147
|
+
// Add Door Service
|
|
148
|
+
const DoorService = `${accessory.displayName} Door`;
|
|
149
|
+
(this.Door!.Service = accessory.getService(this.hap.Service.Door) as Service
|
|
150
|
+
|| accessory.addService(this.hap.Service.Door)), DoorService;
|
|
124
151
|
this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Door`);
|
|
125
152
|
|
|
126
|
-
this.
|
|
127
|
-
|
|
128
|
-
this.doorService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
129
|
-
}
|
|
130
|
-
this.doorService
|
|
153
|
+
this.Door!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
154
|
+
this.Door!.Service
|
|
131
155
|
.getCharacteristic(this.hap.Characteristic.TargetPosition)
|
|
132
156
|
.setProps({
|
|
133
157
|
validValues: [0, 100],
|
|
@@ -136,8 +160,13 @@ export class Others {
|
|
|
136
160
|
minStep: 100,
|
|
137
161
|
})
|
|
138
162
|
.onSet(this.OnSet.bind(this));
|
|
139
|
-
this.
|
|
163
|
+
this.Door!.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
140
164
|
} else if (this.otherDeviceType === 'window') {
|
|
165
|
+
// Initialize Window property
|
|
166
|
+
this.Window = {
|
|
167
|
+
Service: accessory.addService(this.hap.Service.Window),
|
|
168
|
+
On: accessory.context.On || true,
|
|
169
|
+
};
|
|
141
170
|
this.removeFanService(accessory);
|
|
142
171
|
this.removeLockService(accessory);
|
|
143
172
|
this.removeDoorService(accessory);
|
|
@@ -148,17 +177,14 @@ export class Others {
|
|
|
148
177
|
this.removeWindowCoveringService(accessory);
|
|
149
178
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
150
179
|
|
|
151
|
-
// Add
|
|
152
|
-
const
|
|
153
|
-
(this.
|
|
154
|
-
|| accessory.addService(this.hap.Service.Window)),
|
|
180
|
+
// Add Window Service
|
|
181
|
+
const WindowService = `${accessory.displayName} Window`;
|
|
182
|
+
(this.Window!.Service = accessory.getService(this.hap.Service.Window) as Service
|
|
183
|
+
|| accessory.addService(this.hap.Service.Window)), WindowService;
|
|
155
184
|
this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Window`);
|
|
156
185
|
|
|
157
|
-
this.
|
|
158
|
-
|
|
159
|
-
this.windowService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
160
|
-
}
|
|
161
|
-
this.windowService
|
|
186
|
+
this.Window!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
187
|
+
this.Window!.Service
|
|
162
188
|
.getCharacteristic(this.hap.Characteristic.TargetPosition)
|
|
163
189
|
.setProps({
|
|
164
190
|
validValues: [0, 100],
|
|
@@ -167,8 +193,13 @@ export class Others {
|
|
|
167
193
|
minStep: 100,
|
|
168
194
|
})
|
|
169
195
|
.onSet(this.OnSet.bind(this));
|
|
170
|
-
this.
|
|
196
|
+
this.Window!.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
171
197
|
} else if (this.otherDeviceType === 'windowcovering') {
|
|
198
|
+
// Initialize WindowCovering property
|
|
199
|
+
this.WindowCovering = {
|
|
200
|
+
Service: accessory.addService(this.hap.Service.WindowCovering),
|
|
201
|
+
On: accessory.context.On || true,
|
|
202
|
+
};
|
|
172
203
|
this.removeFanService(accessory);
|
|
173
204
|
this.removeLockService(accessory);
|
|
174
205
|
this.removeDoorService(accessory);
|
|
@@ -179,17 +210,14 @@ export class Others {
|
|
|
179
210
|
this.removeGarageDoorService(accessory);
|
|
180
211
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
181
212
|
|
|
182
|
-
// Add
|
|
183
|
-
const
|
|
184
|
-
(this.
|
|
185
|
-
|| accessory.addService(this.hap.Service.WindowCovering)),
|
|
213
|
+
// Add WindowCovering Service
|
|
214
|
+
const WindowCoveringService = `${accessory.displayName} Window Covering`;
|
|
215
|
+
(this.WindowCovering!.Service = accessory.getService(this.hap.Service.WindowCovering) as Service
|
|
216
|
+
|| accessory.addService(this.hap.Service.WindowCovering)), WindowCoveringService;
|
|
186
217
|
this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Window Covering`);
|
|
187
218
|
|
|
188
|
-
this.
|
|
189
|
-
|
|
190
|
-
this.windowCoveringService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
191
|
-
}
|
|
192
|
-
this.windowCoveringService
|
|
219
|
+
this.WindowCovering!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
220
|
+
this.WindowCovering!.Service
|
|
193
221
|
.getCharacteristic(this.hap.Characteristic.TargetPosition)
|
|
194
222
|
.setProps({
|
|
195
223
|
validValues: [0, 100],
|
|
@@ -198,8 +226,13 @@ export class Others {
|
|
|
198
226
|
minStep: 100,
|
|
199
227
|
})
|
|
200
228
|
.onSet(this.OnSet.bind(this));
|
|
201
|
-
this.
|
|
229
|
+
this.WindowCovering!.Service.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
202
230
|
} else if (this.otherDeviceType === 'lock') {
|
|
231
|
+
// Initialize Lock property
|
|
232
|
+
this.Lock = {
|
|
233
|
+
Service: accessory.addService(this.hap.Service.LockMechanism),
|
|
234
|
+
On: accessory.context.On || true,
|
|
235
|
+
};
|
|
203
236
|
this.removeFanService(accessory);
|
|
204
237
|
this.removeDoorService(accessory);
|
|
205
238
|
this.removeOutletService(accessory);
|
|
@@ -210,18 +243,20 @@ export class Others {
|
|
|
210
243
|
this.removeWindowCoveringService(accessory);
|
|
211
244
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
212
245
|
|
|
213
|
-
// Add
|
|
214
|
-
const
|
|
215
|
-
(this.
|
|
216
|
-
|| accessory.addService(this.hap.Service.LockMechanism)),
|
|
246
|
+
// Add Lock Service
|
|
247
|
+
const LockService = `${accessory.displayName} Lock`;
|
|
248
|
+
(this.Lock!.Service = accessory.getService(this.hap.Service.LockMechanism) as Service
|
|
249
|
+
|| accessory.addService(this.hap.Service.LockMechanism)), LockService;
|
|
217
250
|
this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Lock`);
|
|
218
251
|
|
|
219
|
-
this.
|
|
220
|
-
|
|
221
|
-
this.lockService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
222
|
-
}
|
|
223
|
-
this.lockService.getCharacteristic(this.hap.Characteristic.LockTargetState).onSet(this.OnSet.bind(this));
|
|
252
|
+
this.Lock!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
253
|
+
this.Lock!.Service.getCharacteristic(this.hap.Characteristic.LockTargetState).onSet(this.OnSet.bind(this));
|
|
224
254
|
} else if (this.otherDeviceType === 'faucet') {
|
|
255
|
+
// Initialize Faucet property
|
|
256
|
+
this.Faucet = {
|
|
257
|
+
Service: accessory.addService(this.hap.Service.Faucet),
|
|
258
|
+
On: accessory.context.On || true,
|
|
259
|
+
};
|
|
225
260
|
this.removeFanService(accessory);
|
|
226
261
|
this.removeLockService(accessory);
|
|
227
262
|
this.removeDoorService(accessory);
|
|
@@ -232,18 +267,20 @@ export class Others {
|
|
|
232
267
|
this.removeWindowCoveringService(accessory);
|
|
233
268
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
234
269
|
|
|
235
|
-
// Add
|
|
236
|
-
const
|
|
237
|
-
(this.
|
|
238
|
-
|| accessory.addService(this.hap.Service.Faucet)),
|
|
270
|
+
// Add Faucet Service
|
|
271
|
+
const FaucetService = `${accessory.displayName} Faucet`;
|
|
272
|
+
(this.Faucet!.Service = accessory.getService(this.hap.Service.Faucet) as Service
|
|
273
|
+
|| accessory.addService(this.hap.Service.Faucet)), FaucetService;
|
|
239
274
|
this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Faucet`);
|
|
240
275
|
|
|
241
|
-
this.
|
|
242
|
-
|
|
243
|
-
this.faucetService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
244
|
-
}
|
|
245
|
-
this.faucetService.getCharacteristic(this.hap.Characteristic.Active).onSet(this.OnSet.bind(this));
|
|
276
|
+
this.Faucet!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
277
|
+
this.Faucet!.Service.getCharacteristic(this.hap.Characteristic.Active).onSet(this.OnSet.bind(this));
|
|
246
278
|
} else if (this.otherDeviceType === 'fan') {
|
|
279
|
+
// Initialize Fan property
|
|
280
|
+
this.Fan = {
|
|
281
|
+
Service: accessory.addService(this.hap.Service.Fanv2),
|
|
282
|
+
On: accessory.context.On || true,
|
|
283
|
+
};
|
|
247
284
|
this.removeLockService(accessory);
|
|
248
285
|
this.removeDoorService(accessory);
|
|
249
286
|
this.removeFaucetService(accessory);
|
|
@@ -254,18 +291,20 @@ export class Others {
|
|
|
254
291
|
this.removeWindowCoveringService(accessory);
|
|
255
292
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
256
293
|
|
|
257
|
-
// Add
|
|
258
|
-
const
|
|
259
|
-
(this.
|
|
260
|
-
|| accessory.addService(this.hap.Service.
|
|
294
|
+
// Add Fan Service
|
|
295
|
+
const FanService = `${accessory.displayName} Fan`;
|
|
296
|
+
(this.Fan!.Service = accessory.getService(this.hap.Service.Fanv2) as Service
|
|
297
|
+
|| accessory.addService(this.hap.Service.Fanv2)), FanService;
|
|
261
298
|
this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Fan`);
|
|
262
299
|
|
|
263
|
-
this.
|
|
264
|
-
|
|
265
|
-
this.fanService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
266
|
-
}
|
|
267
|
-
this.fanService.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
300
|
+
this.Fan!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
301
|
+
this.Fan!.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
268
302
|
} else if (this.otherDeviceType === 'stateful') {
|
|
303
|
+
// Initialize StatefulProgrammableSwitch property
|
|
304
|
+
this.StatefulProgrammableSwitch = {
|
|
305
|
+
Service: accessory.addService(this.hap.Service.StatefulProgrammableSwitch),
|
|
306
|
+
On: accessory.context.On || true,
|
|
307
|
+
};
|
|
269
308
|
this.removeFanService(accessory);
|
|
270
309
|
this.removeLockService(accessory);
|
|
271
310
|
this.removeDoorService(accessory);
|
|
@@ -276,20 +315,22 @@ export class Others {
|
|
|
276
315
|
this.removeGarageDoorService(accessory);
|
|
277
316
|
this.removeWindowCoveringService(accessory);
|
|
278
317
|
|
|
279
|
-
// Add
|
|
280
|
-
const
|
|
281
|
-
(this.
|
|
282
|
-
|| accessory.addService(this.hap.Service.StatefulProgrammableSwitch)),
|
|
318
|
+
// Add StatefulProgrammableSwitch.Service
|
|
319
|
+
const StatefulProgrammableSwitchService = `${accessory.displayName} Stateful Programmable Switch`;
|
|
320
|
+
(this.StatefulProgrammableSwitch!.Service = accessory.getService(this.hap.Service.StatefulProgrammableSwitch) as Service
|
|
321
|
+
|| accessory.addService(this.hap.Service.StatefulProgrammableSwitch)), StatefulProgrammableSwitchService;
|
|
283
322
|
this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Stateful Programmable Switch`);
|
|
284
323
|
|
|
285
|
-
this.
|
|
286
|
-
|
|
287
|
-
this.statefulProgrammableSwitchService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
288
|
-
}
|
|
289
|
-
this.statefulProgrammableSwitchService
|
|
324
|
+
this.StatefulProgrammableSwitch!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
325
|
+
this.StatefulProgrammableSwitch!.Service
|
|
290
326
|
.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
|
|
291
327
|
.onSet(this.OnSet.bind(this));
|
|
292
328
|
} else {
|
|
329
|
+
// Initialize Outlet property
|
|
330
|
+
this.Outlet = {
|
|
331
|
+
Service: accessory.addService(this.hap.Service.Outlet),
|
|
332
|
+
On: accessory.context.On || true,
|
|
333
|
+
};
|
|
293
334
|
this.removeFanService(accessory);
|
|
294
335
|
this.removeLockService(accessory);
|
|
295
336
|
this.removeDoorService(accessory);
|
|
@@ -300,17 +341,14 @@ export class Others {
|
|
|
300
341
|
this.removeWindowCoveringService(accessory);
|
|
301
342
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
302
343
|
|
|
303
|
-
// Add
|
|
304
|
-
const
|
|
305
|
-
(this.
|
|
306
|
-
|| accessory.addService(this.hap.Service.Outlet)),
|
|
344
|
+
// Add Outlet.Service
|
|
345
|
+
const OutletService = `${accessory.displayName} Outlet`;
|
|
346
|
+
(this.Outlet!.Service = accessory.getService(this.hap.Service.Outlet) as Service
|
|
347
|
+
|| accessory.addService(this.hap.Service.Outlet)), OutletService;
|
|
307
348
|
this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Outlet`);
|
|
308
349
|
|
|
309
|
-
this.
|
|
310
|
-
|
|
311
|
-
this.outletService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
312
|
-
}
|
|
313
|
-
this.outletService.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
350
|
+
this.Outlet!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
351
|
+
this.Outlet!.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
314
352
|
}
|
|
315
353
|
}
|
|
316
354
|
|
|
@@ -318,55 +356,75 @@ export class Others {
|
|
|
318
356
|
* Handle requests to set the "On" characteristic
|
|
319
357
|
*/
|
|
320
358
|
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
359
|
+
let On: boolean;
|
|
321
360
|
if (this.otherDeviceType === 'garagedoor') {
|
|
322
361
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set TargetDoorState: ${value}`);
|
|
323
362
|
if (value === this.hap.Characteristic.TargetDoorState.CLOSED) {
|
|
324
|
-
this.On = false;
|
|
363
|
+
this.GarageDoor!.On = false;
|
|
364
|
+
} else {
|
|
365
|
+
this.GarageDoor!.On = true;
|
|
366
|
+
}
|
|
367
|
+
On = this.GarageDoor!.On;
|
|
368
|
+
} else if (this.otherDeviceType === 'door') {
|
|
369
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set TargetPosition: ${value}`);
|
|
370
|
+
if (value === 0) {
|
|
371
|
+
this.Door!.On = false;
|
|
325
372
|
} else {
|
|
326
|
-
this.On = true;
|
|
373
|
+
this.Door!.On = true;
|
|
327
374
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
this.
|
|
331
|
-
|
|
332
|
-
|
|
375
|
+
On = this.Door!.On;
|
|
376
|
+
} else if (this.otherDeviceType === 'window') {
|
|
377
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set TargetPosition: ${value}`);
|
|
378
|
+
if (value === 0) {
|
|
379
|
+
this.Window!.On = false;
|
|
380
|
+
} else {
|
|
381
|
+
this.Window!.On = true;
|
|
382
|
+
}
|
|
383
|
+
On = this.Window!.On;
|
|
384
|
+
} else if (this.otherDeviceType === 'windowcovering') {
|
|
333
385
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set TargetPosition: ${value}`);
|
|
334
386
|
if (value === 0) {
|
|
335
|
-
this.On = false;
|
|
387
|
+
this.WindowCovering!.On = false;
|
|
336
388
|
} else {
|
|
337
|
-
this.On = true;
|
|
389
|
+
this.WindowCovering!.On = true;
|
|
338
390
|
}
|
|
391
|
+
On = this.WindowCovering!.On;
|
|
339
392
|
} else if (this.otherDeviceType === 'lock') {
|
|
340
393
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set LockTargetState: ${value}`);
|
|
341
394
|
if (value === this.hap.Characteristic.LockTargetState.SECURED) {
|
|
342
|
-
this.On = false;
|
|
395
|
+
this.Lock!.On = false;
|
|
343
396
|
} else {
|
|
344
|
-
this.On = true;
|
|
397
|
+
this.Lock!.On = true;
|
|
345
398
|
}
|
|
399
|
+
On = this.Lock!.On;
|
|
346
400
|
} else if (this.otherDeviceType === 'faucet') {
|
|
347
401
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Active: ${value}`);
|
|
348
402
|
if (value === this.hap.Characteristic.Active.INACTIVE) {
|
|
349
|
-
this.On = false;
|
|
403
|
+
this.Faucet!.On = false;
|
|
350
404
|
} else {
|
|
351
|
-
this.On = true;
|
|
405
|
+
this.Faucet!.On = true;
|
|
352
406
|
}
|
|
407
|
+
On = this.Faucet!.On;
|
|
353
408
|
} else if (this.otherDeviceType === 'stateful') {
|
|
354
409
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set ProgrammableSwitchOutputState: ${value}`);
|
|
355
410
|
if (value === 0) {
|
|
356
|
-
this.On = false;
|
|
411
|
+
this.StatefulProgrammableSwitch!.On = false;
|
|
357
412
|
} else {
|
|
358
|
-
this.On = true;
|
|
413
|
+
this.StatefulProgrammableSwitch!.On = true;
|
|
359
414
|
}
|
|
415
|
+
|
|
416
|
+
On = this.StatefulProgrammableSwitch!.On;
|
|
360
417
|
} else {
|
|
361
418
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set On: ${value}`);
|
|
362
|
-
this.On = value;
|
|
419
|
+
this.Outlet!.On = value;
|
|
420
|
+
On = this.Outlet!.On ? true : false;
|
|
363
421
|
}
|
|
364
422
|
|
|
365
423
|
//pushChanges
|
|
366
|
-
if (
|
|
367
|
-
await this.pushOnChanges();
|
|
424
|
+
if (On === true) {
|
|
425
|
+
await this.pushOnChanges(On);
|
|
368
426
|
} else {
|
|
369
|
-
await this.pushOffChanges();
|
|
427
|
+
await this.pushOffChanges(On);
|
|
370
428
|
}
|
|
371
429
|
}
|
|
372
430
|
|
|
@@ -380,13 +438,11 @@ export class Others {
|
|
|
380
438
|
* Other - "command" "channelAdd" "default" = next channel
|
|
381
439
|
* Other - "command" "channelSub" "default" = previous channel
|
|
382
440
|
*/
|
|
383
|
-
async pushOnChanges(): Promise<void> {
|
|
384
|
-
this.debugLog(
|
|
385
|
-
|
|
386
|
-
` disablePushOn: ${this.disablePushOn}, customize: ${this.device.customize}, customOn: ${this.device.customOn}`,
|
|
387
|
-
);
|
|
441
|
+
async pushOnChanges(On: boolean): Promise<void> {
|
|
442
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOnChanges On: ${On},`
|
|
443
|
+
+` disablePushOn: ${this.disablePushOn}, customize: ${this.device.customize}, customOn: ${this.device.customOn}`);
|
|
388
444
|
if (this.device.customize) {
|
|
389
|
-
if (
|
|
445
|
+
if (On === true && !this.disablePushOn) {
|
|
390
446
|
const commandType: string = await this.commandType();
|
|
391
447
|
const command: string = await this.commandOn();
|
|
392
448
|
const bodyChange = JSON.stringify({
|
|
@@ -401,13 +457,11 @@ export class Others {
|
|
|
401
457
|
}
|
|
402
458
|
}
|
|
403
459
|
|
|
404
|
-
async pushOffChanges(): Promise<void> {
|
|
405
|
-
this.debugLog(
|
|
406
|
-
|
|
407
|
-
` disablePushOff: ${this.disablePushOff}, customize: ${this.device.customize}, customOff: ${this.device.customOff}`,
|
|
408
|
-
);
|
|
460
|
+
async pushOffChanges(On: boolean): Promise<void> {
|
|
461
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOffChanges On: ${On},`
|
|
462
|
+
+ ` disablePushOff: ${this.disablePushOff}, customize: ${this.device.customize}, customOff: ${this.device.customOff}`);
|
|
409
463
|
if (this.device.customize) {
|
|
410
|
-
if (
|
|
464
|
+
if (On === false && !this.disablePushOff) {
|
|
411
465
|
const commandType: string = await this.commandType();
|
|
412
466
|
const command: string = await this.commandOff();
|
|
413
467
|
const bodyChange = JSON.stringify({
|
|
@@ -447,456 +501,294 @@ export class Others {
|
|
|
447
501
|
}
|
|
448
502
|
} catch (e: any) {
|
|
449
503
|
this.apiError(e);
|
|
450
|
-
this.errorLog(
|
|
451
|
-
|
|
452
|
-
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
453
|
-
);
|
|
504
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}`
|
|
505
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
454
506
|
}
|
|
455
507
|
} else {
|
|
456
|
-
this.warnLog(
|
|
457
|
-
|
|
458
|
-
` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`,
|
|
459
|
-
);
|
|
508
|
+
this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
509
|
+
+ ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
|
|
460
510
|
}
|
|
461
511
|
}
|
|
462
512
|
|
|
463
513
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
464
514
|
if (this.otherDeviceType === 'garagedoor') {
|
|
465
|
-
if (this.On === undefined) {
|
|
466
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
515
|
+
if (this.GarageDoor!.On === undefined) {
|
|
516
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.GarageDoor!.On}`);
|
|
467
517
|
} else {
|
|
468
|
-
if (this.On) {
|
|
469
|
-
this.
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
);
|
|
473
|
-
this.garageDoorService?.updateCharacteristic(
|
|
474
|
-
this.hap.Characteristic.CurrentDoorState,
|
|
475
|
-
this.hap.Characteristic.CurrentDoorState.OPEN,
|
|
476
|
-
);
|
|
477
|
-
this.debugLog(
|
|
478
|
-
`${this.device.remoteType}: ` + `${this.accessory.displayName} updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open`,
|
|
479
|
-
);
|
|
518
|
+
if (this.GarageDoor!.On) {
|
|
519
|
+
this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.OPEN);
|
|
520
|
+
this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.OPEN);
|
|
521
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
522
|
+
+ ` TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor!.On})`);
|
|
480
523
|
} else {
|
|
481
|
-
this.
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
);
|
|
485
|
-
this.garageDoorService?.updateCharacteristic(
|
|
486
|
-
this.hap.Characteristic.CurrentDoorState,
|
|
487
|
-
this.hap.Characteristic.CurrentDoorState.CLOSED,
|
|
488
|
-
);
|
|
489
|
-
this.debugLog(
|
|
490
|
-
`${this.device.remoteType}: ` + `${this.accessory.displayName} updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open`,
|
|
491
|
-
);
|
|
524
|
+
this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.CLOSED);
|
|
525
|
+
this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.CLOSED);
|
|
526
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
527
|
+
+ ` TargetDoorState: Closed, CurrentDoorState: Closed (${this.GarageDoor!.On})`);
|
|
492
528
|
}
|
|
493
529
|
}
|
|
494
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Garage Door On: ${this.On}`);
|
|
530
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Garage Door On: ${this.GarageDoor!.On}`);
|
|
495
531
|
} else if (this.otherDeviceType === 'door') {
|
|
496
|
-
if (this.On === undefined) {
|
|
497
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
532
|
+
if (this.Door!.On === undefined) {
|
|
533
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Door!.On}`);
|
|
498
534
|
} else {
|
|
499
|
-
if (this.On) {
|
|
500
|
-
this.
|
|
501
|
-
this.
|
|
502
|
-
this.
|
|
503
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic
|
|
535
|
+
if (this.Door!.On) {
|
|
536
|
+
this.Door!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
537
|
+
this.Door!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
538
|
+
this.Door!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
539
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
540
|
+
+ ` TargetPosition: 100, CurrentPosition: 100 (${this.Door!.On})`);
|
|
504
541
|
} else {
|
|
505
|
-
this.
|
|
506
|
-
this.
|
|
507
|
-
this.
|
|
508
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic
|
|
542
|
+
this.Door!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
543
|
+
this.Door!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
544
|
+
this.Door!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
545
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
546
|
+
+ ` TargetPosition: 0, CurrentPosition: 0 (${this.Door!.On})`);
|
|
509
547
|
}
|
|
510
548
|
}
|
|
511
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Door On: ${this.On}`);
|
|
549
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Door On: ${this.Door!.On}`);
|
|
512
550
|
} else if (this.otherDeviceType === 'window') {
|
|
513
|
-
if (this.On === undefined) {
|
|
514
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
551
|
+
if (this.Window!.On === undefined) {
|
|
552
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Window!.On}`);
|
|
515
553
|
} else {
|
|
516
|
-
if (this.On) {
|
|
517
|
-
this.
|
|
518
|
-
this.
|
|
519
|
-
this.
|
|
520
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic
|
|
554
|
+
if (this.Window!.On) {
|
|
555
|
+
this.Window!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
556
|
+
this.Window!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
557
|
+
this.Window!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
558
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
559
|
+
+ ` TargetPosition: 100, CurrentPosition: 100 (${this.Window!.On})`);
|
|
521
560
|
} else {
|
|
522
|
-
this.
|
|
523
|
-
this.
|
|
524
|
-
this.
|
|
525
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic
|
|
561
|
+
this.Window!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
562
|
+
this.Window!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
563
|
+
this.Window!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
564
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
565
|
+
+ ` TargetPosition: 0, CurrentPosition: 0 (${this.Window!.On})`);
|
|
526
566
|
}
|
|
527
567
|
}
|
|
528
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Window On: ${this.On}`);
|
|
568
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Window On: ${this.Window!.On}`);
|
|
529
569
|
} else if (this.otherDeviceType === 'windowcovering') {
|
|
530
|
-
if (this.On === undefined) {
|
|
531
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
570
|
+
if (this.WindowCovering!.On === undefined) {
|
|
571
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.WindowCovering!.On}`);
|
|
532
572
|
} else {
|
|
533
|
-
if (this.On) {
|
|
534
|
-
this.
|
|
535
|
-
this.
|
|
536
|
-
this.
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
);
|
|
540
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: 100, CurrentPosition: 100`);
|
|
573
|
+
if (this.WindowCovering!.On) {
|
|
574
|
+
this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
575
|
+
this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
576
|
+
this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
577
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
578
|
+
+ ` TargetPosition: 100, CurrentPosition: 100 (${this.WindowCovering!.On})`);
|
|
541
579
|
} else {
|
|
542
|
-
this.
|
|
543
|
-
this.
|
|
544
|
-
this.
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
);
|
|
548
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: 0, CurrentPosition: 0`);
|
|
580
|
+
this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
581
|
+
this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
582
|
+
this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
583
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
584
|
+
+ ` TargetPosition: 0, CurrentPosition: 0 (${this.WindowCovering!.On})`);
|
|
549
585
|
}
|
|
550
586
|
}
|
|
551
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Window Covering On: ${this.On}`);
|
|
587
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Window Covering On: ${this.WindowCovering!.On}`);
|
|
552
588
|
} else if (this.otherDeviceType === 'lock') {
|
|
553
|
-
if (this.On === undefined) {
|
|
554
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
589
|
+
if (this.Lock!.On === undefined) {
|
|
590
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Lock!.On}`);
|
|
555
591
|
} else {
|
|
556
|
-
if (this.On) {
|
|
557
|
-
this.
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
);
|
|
561
|
-
this.lockService?.updateCharacteristic(
|
|
562
|
-
this.hap.Characteristic.LockCurrentState,
|
|
563
|
-
this.hap.Characteristic.LockCurrentState.UNSECURED,
|
|
564
|
-
);
|
|
565
|
-
this.debugLog(
|
|
566
|
-
`${this.device.remoteType}: ` +
|
|
567
|
-
`${this.accessory.displayName} updateCharacteristic LockTargetState: UNSECURED, LockCurrentState: UNSECURED`,
|
|
568
|
-
);
|
|
592
|
+
if (this.Lock!.On) {
|
|
593
|
+
this.Lock!.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.UNSECURED);
|
|
594
|
+
this.Lock!.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.UNSECURED);
|
|
595
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
596
|
+
+ ` LockTargetState: UNSECURED, LockCurrentState: UNSECURE (${this.Lock!.On})`);
|
|
569
597
|
} else {
|
|
570
|
-
this.
|
|
571
|
-
this.
|
|
572
|
-
|
|
573
|
-
this.
|
|
574
|
-
);
|
|
575
|
-
this.debugLog(
|
|
576
|
-
`${this.device.remoteType}: ` + `${this.accessory.displayName} updateCharacteristic LockTargetState: SECURED, LockCurrentState: SECURED`,
|
|
577
|
-
);
|
|
598
|
+
this.Lock!.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.SECURED);
|
|
599
|
+
this.Lock!.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.SECURED);
|
|
600
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
601
|
+
+ ` LockTargetState: SECURED, LockCurrentState: SECURED (${this.Lock!.On})`);
|
|
578
602
|
}
|
|
579
603
|
}
|
|
580
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Lock On: ${this.On}`);
|
|
604
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Lock On: ${this.Lock!.On}`);
|
|
581
605
|
} else if (this.otherDeviceType === 'faucet') {
|
|
582
|
-
if (this.On === undefined) {
|
|
583
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
606
|
+
if (this.Faucet!.On === undefined) {
|
|
607
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Faucet!.On}`);
|
|
584
608
|
} else {
|
|
585
|
-
if (this.On) {
|
|
586
|
-
this.
|
|
587
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.On}`);
|
|
609
|
+
if (this.Faucet!.On) {
|
|
610
|
+
this.Faucet!.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE);
|
|
611
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Faucet!.On}`);
|
|
588
612
|
} else {
|
|
589
|
-
this.
|
|
590
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.On}`);
|
|
613
|
+
this.Faucet!.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
|
|
614
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Faucet!.On}`);
|
|
591
615
|
}
|
|
592
616
|
}
|
|
593
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Faucet On: ${this.On}`);
|
|
617
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Faucet On: ${this.Faucet!.On}`);
|
|
594
618
|
} else if (this.otherDeviceType === 'fan') {
|
|
595
|
-
if (this.On === undefined) {
|
|
596
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
619
|
+
if (this.Fan!.On === undefined) {
|
|
620
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Fan!.On}`);
|
|
597
621
|
} else {
|
|
598
|
-
if (this.On) {
|
|
599
|
-
this.
|
|
600
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
622
|
+
if (this.Fan!.On) {
|
|
623
|
+
this.Fan!.Service.updateCharacteristic(this.hap.Characteristic.On, this.Fan!.On);
|
|
624
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Fan!.On}`);
|
|
601
625
|
} else {
|
|
602
|
-
this.
|
|
603
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
626
|
+
this.Fan!.Service.updateCharacteristic(this.hap.Characteristic.On, this.Fan!.On);
|
|
627
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Fan!.On}`);
|
|
604
628
|
}
|
|
605
629
|
}
|
|
606
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Fan On: ${this.On}`);
|
|
630
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Fan On: ${this.Fan!.On}`);
|
|
607
631
|
} else if (this.otherDeviceType === 'stateful') {
|
|
608
|
-
if (this.On === undefined) {
|
|
609
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
632
|
+
if (this.StatefulProgrammableSwitch!.On === undefined) {
|
|
633
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.StatefulProgrammableSwitch!.On}`);
|
|
610
634
|
} else {
|
|
611
|
-
if (this.On) {
|
|
612
|
-
this.
|
|
613
|
-
this.hap.Characteristic.ProgrammableSwitchEvent
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
this.debugLog(
|
|
618
|
-
`${this.device.remoteType}: ` +
|
|
619
|
-
`${this.accessory.displayName} updateCharacteristic ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 1`,
|
|
620
|
-
);
|
|
635
|
+
if (this.StatefulProgrammableSwitch!.On) {
|
|
636
|
+
this.StatefulProgrammableSwitch!.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent,
|
|
637
|
+
this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
|
|
638
|
+
this.StatefulProgrammableSwitch!.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 1);
|
|
639
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
640
|
+
+ ` ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 1 (${this.StatefulProgrammableSwitch!.On})`);
|
|
621
641
|
} else {
|
|
622
|
-
this.
|
|
623
|
-
this.hap.Characteristic.ProgrammableSwitchEvent
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
this.debugLog(
|
|
628
|
-
`${this.device.remoteType}: ` +
|
|
629
|
-
`${this.accessory.displayName} updateCharacteristic ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 0`,
|
|
630
|
-
);
|
|
642
|
+
this.StatefulProgrammableSwitch!.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent,
|
|
643
|
+
this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
|
|
644
|
+
this.StatefulProgrammableSwitch!.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 0);
|
|
645
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
646
|
+
+ ` ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 0 (${this.StatefulProgrammableSwitch!.On})`);
|
|
631
647
|
}
|
|
632
648
|
}
|
|
633
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} StatefulProgrammableSwitch On: ${this.On}`);
|
|
649
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} StatefulProgrammableSwitch On: ${this.StatefulProgrammableSwitch!.On}`);
|
|
634
650
|
} else if (this.otherDeviceType === 'switch') {
|
|
635
|
-
if (this.On === undefined) {
|
|
636
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
651
|
+
if (this.Switch!.On === undefined) {
|
|
652
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Switch!.On}`);
|
|
637
653
|
} else {
|
|
638
|
-
this.
|
|
639
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
654
|
+
this.Switch!.Service.updateCharacteristic(this.hap.Characteristic.On, this.Switch!.On);
|
|
655
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Switch!.On}`);
|
|
640
656
|
}
|
|
641
657
|
} else {
|
|
642
|
-
if (this.On === undefined) {
|
|
643
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
658
|
+
if (this.Outlet!.On === undefined) {
|
|
659
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Outlet!.On}`);
|
|
644
660
|
} else {
|
|
645
|
-
this.
|
|
646
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
661
|
+
this.Outlet!.Service.updateCharacteristic(this.hap.Characteristic.On, this.Outlet!.On);
|
|
662
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Outlet!.On}`);
|
|
647
663
|
}
|
|
648
664
|
}
|
|
649
665
|
}
|
|
650
666
|
|
|
651
|
-
async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise<void> {
|
|
652
|
-
if (device.disablePushOn === undefined) {
|
|
653
|
-
this.disablePushOn = false;
|
|
654
|
-
} else {
|
|
655
|
-
this.disablePushOn = device.disablePushOn;
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
async disablePushOffChanges(device: irdevice & irDevicesConfig): Promise<void> {
|
|
660
|
-
if (device.disablePushOff === undefined) {
|
|
661
|
-
this.disablePushOff = false;
|
|
662
|
-
} else {
|
|
663
|
-
this.disablePushOff = device.disablePushOff;
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
async commandType(): Promise<string> {
|
|
668
|
-
let commandType: string;
|
|
669
|
-
if (this.device.commandType && this.device.customize) {
|
|
670
|
-
commandType = this.device.commandType;
|
|
671
|
-
} else if (this.device.customize) {
|
|
672
|
-
commandType = 'customize';
|
|
673
|
-
} else {
|
|
674
|
-
commandType = 'command';
|
|
675
|
-
}
|
|
676
|
-
return commandType;
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
async commandOn(): Promise<string> {
|
|
680
|
-
let command: string;
|
|
681
|
-
if (this.device.customize && this.device.customOn) {
|
|
682
|
-
command = this.device.customOn;
|
|
683
|
-
} else {
|
|
684
|
-
command = 'turnOn';
|
|
685
|
-
}
|
|
686
|
-
return command;
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
async commandOff(): Promise<string> {
|
|
690
|
-
let command: string;
|
|
691
|
-
if (this.device.customize && this.device.customOff) {
|
|
692
|
-
command = this.device.customOff;
|
|
693
|
-
} else {
|
|
694
|
-
command = 'turnOff';
|
|
695
|
-
}
|
|
696
|
-
return command;
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
async statusCode(statusCode: number): Promise<void> {
|
|
700
|
-
switch (statusCode) {
|
|
701
|
-
case 151:
|
|
702
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
703
|
-
break;
|
|
704
|
-
case 152:
|
|
705
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
706
|
-
break;
|
|
707
|
-
case 160:
|
|
708
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
709
|
-
break;
|
|
710
|
-
case 161:
|
|
711
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
712
|
-
break;
|
|
713
|
-
case 171:
|
|
714
|
-
this.errorLog(
|
|
715
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
716
|
-
`Hub: ${this.device.hubDeviceId}`,
|
|
717
|
-
);
|
|
718
|
-
break;
|
|
719
|
-
case 190:
|
|
720
|
-
this.errorLog(
|
|
721
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
722
|
-
` Or command format is invalid, statusCode: ${statusCode}`,
|
|
723
|
-
);
|
|
724
|
-
break;
|
|
725
|
-
case 100:
|
|
726
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
727
|
-
break;
|
|
728
|
-
case 200:
|
|
729
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
730
|
-
break;
|
|
731
|
-
case 400:
|
|
732
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
|
|
733
|
-
+ `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
|
|
734
|
-
break;
|
|
735
|
-
case 401:
|
|
736
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
|
|
737
|
-
+ `but the request has not been authenticated, statusCode: ${statusCode}`);
|
|
738
|
-
break;
|
|
739
|
-
case 403:
|
|
740
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
|
|
741
|
-
+ `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
|
|
742
|
-
break;
|
|
743
|
-
case 404:
|
|
744
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
|
|
745
|
-
+ `statusCode: ${statusCode}`);
|
|
746
|
-
break;
|
|
747
|
-
case 406:
|
|
748
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
|
|
749
|
-
+ `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
|
|
750
|
-
break;
|
|
751
|
-
case 415:
|
|
752
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
|
|
753
|
-
+ `header that is not supported by the server, statusCode: ${statusCode}`);
|
|
754
|
-
break;
|
|
755
|
-
case 422:
|
|
756
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, but `
|
|
757
|
-
+ `the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
758
|
-
break;
|
|
759
|
-
case 429:
|
|
760
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
|
|
761
|
-
+ `requests allowed for a given time window, statusCode: ${statusCode}`);
|
|
762
|
-
break;
|
|
763
|
-
case 500:
|
|
764
|
-
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
|
|
765
|
-
+ `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
|
|
766
|
-
break;
|
|
767
|
-
default:
|
|
768
|
-
this.infoLog(
|
|
769
|
-
`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
770
|
-
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
771
|
-
);
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
|
|
775
667
|
async apiError(e: any): Promise<void> {
|
|
776
668
|
if (this.otherDeviceType === 'garagedoor') {
|
|
777
|
-
this.
|
|
778
|
-
this.
|
|
779
|
-
this.
|
|
669
|
+
this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, e);
|
|
670
|
+
this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, e);
|
|
671
|
+
this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.ObstructionDetected, e);
|
|
780
672
|
} else if (this.otherDeviceType === 'door') {
|
|
781
|
-
this.
|
|
782
|
-
this.
|
|
783
|
-
this.
|
|
673
|
+
this.Door!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
|
|
674
|
+
this.Door!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
|
|
675
|
+
this.Door!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e);
|
|
784
676
|
} else if (this.otherDeviceType === 'window') {
|
|
785
|
-
this.
|
|
786
|
-
this.
|
|
787
|
-
this.
|
|
677
|
+
this.Window!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
|
|
678
|
+
this.Window!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
|
|
679
|
+
this.Window!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e);
|
|
788
680
|
} else if (this.otherDeviceType === 'windowcovering') {
|
|
789
|
-
this.
|
|
790
|
-
this.
|
|
791
|
-
this.
|
|
681
|
+
this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
|
|
682
|
+
this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
|
|
683
|
+
this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e);
|
|
792
684
|
} else if (this.otherDeviceType === 'lock') {
|
|
793
|
-
this.
|
|
794
|
-
this.
|
|
685
|
+
this.Door!.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, e);
|
|
686
|
+
this.Door!.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, e);
|
|
795
687
|
} else if (this.otherDeviceType === 'faucet') {
|
|
796
|
-
this.
|
|
688
|
+
this.Faucet!.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
|
|
797
689
|
} else if (this.otherDeviceType === 'fan') {
|
|
798
|
-
this.
|
|
690
|
+
this.Fan!.Service.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
799
691
|
} else if (this.otherDeviceType === 'stateful') {
|
|
800
|
-
this.
|
|
801
|
-
this.
|
|
692
|
+
this.StatefulProgrammableSwitch!.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e);
|
|
693
|
+
this.StatefulProgrammableSwitch!.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e);
|
|
802
694
|
} else if (this.otherDeviceType === 'switch') {
|
|
803
|
-
this.
|
|
695
|
+
this.Switch!.Service.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
804
696
|
} else {
|
|
805
|
-
this.
|
|
697
|
+
this.Outlet!.Service.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
806
698
|
}
|
|
807
699
|
}
|
|
808
700
|
|
|
809
701
|
async removeOutletService(accessory: PlatformAccessory): Promise<void> {
|
|
810
|
-
// If
|
|
811
|
-
this.
|
|
812
|
-
if (this.
|
|
702
|
+
// If Outlet.Service still present, then remove first
|
|
703
|
+
this.Outlet!.Service = this.accessory.getService(this.hap.Service.Outlet) as Service;
|
|
704
|
+
if (this.Outlet!.Service) {
|
|
813
705
|
this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Outlet Service`);
|
|
814
706
|
}
|
|
815
|
-
accessory.removeService(this.
|
|
707
|
+
accessory.removeService(this.Outlet!.Service);
|
|
816
708
|
}
|
|
817
709
|
|
|
818
710
|
async removeGarageDoorService(accessory: PlatformAccessory): Promise<void> {
|
|
819
|
-
// If
|
|
820
|
-
this.
|
|
821
|
-
if (this.
|
|
711
|
+
// If GarageDoor.Service still present, then remove first
|
|
712
|
+
this.GarageDoor!.Service = this.accessory.getService(this.hap.Service.GarageDoorOpener) as Service;
|
|
713
|
+
if (this.GarageDoor!.Service) {
|
|
822
714
|
this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Garage Door Service`);
|
|
823
715
|
}
|
|
824
|
-
accessory.removeService(this.
|
|
716
|
+
accessory.removeService(this.GarageDoor!.Service);
|
|
825
717
|
}
|
|
826
718
|
|
|
827
719
|
async removeDoorService(accessory: PlatformAccessory): Promise<void> {
|
|
828
|
-
// If
|
|
829
|
-
this.
|
|
830
|
-
if (this.
|
|
720
|
+
// If Door.Service still present, then remove first
|
|
721
|
+
this.Door!.Service = this.accessory.getService(this.hap.Service.Door) as Service;
|
|
722
|
+
if (this.Door!.Service) {
|
|
831
723
|
this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Door Service`);
|
|
832
724
|
}
|
|
833
|
-
accessory.removeService(this.
|
|
725
|
+
accessory.removeService(this.Door!.Service);
|
|
834
726
|
}
|
|
835
727
|
|
|
836
728
|
async removeLockService(accessory: PlatformAccessory): Promise<void> {
|
|
837
|
-
// If
|
|
838
|
-
this.
|
|
839
|
-
if (this.
|
|
729
|
+
// If Lock.Service still present, then remove first
|
|
730
|
+
this.Lock!.Service = this.accessory.getService(this.hap.Service.LockMechanism) as Service;
|
|
731
|
+
if (this.Lock!.Service) {
|
|
840
732
|
this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Lock Service`);
|
|
841
733
|
}
|
|
842
|
-
accessory.removeService(this.
|
|
734
|
+
accessory.removeService(this.Lock!.Service);
|
|
843
735
|
}
|
|
844
736
|
|
|
845
737
|
async removeFaucetService(accessory: PlatformAccessory): Promise<void> {
|
|
846
|
-
// If
|
|
847
|
-
this.
|
|
848
|
-
if (this.
|
|
738
|
+
// If Faucet.Service still present, then remove first
|
|
739
|
+
this.Faucet!.Service = this.accessory.getService(this.hap.Service.Faucet) as Service;
|
|
740
|
+
if (this.Faucet!.Service) {
|
|
849
741
|
this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Faucet Service`);
|
|
850
742
|
}
|
|
851
|
-
accessory.removeService(this.
|
|
743
|
+
accessory.removeService(this.Faucet!.Service);
|
|
852
744
|
}
|
|
853
745
|
|
|
854
746
|
async removeFanService(accessory: PlatformAccessory): Promise<void> {
|
|
855
|
-
// If
|
|
856
|
-
this.
|
|
857
|
-
if (this.
|
|
747
|
+
// If Fan Service still present, then remove first
|
|
748
|
+
this.Fan!.Service = this.accessory.getService(this.hap.Service.Fan) as Service;
|
|
749
|
+
if (this.Fan!.Service) {
|
|
858
750
|
this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Fan Service`);
|
|
859
751
|
}
|
|
860
|
-
accessory.removeService(this.
|
|
752
|
+
accessory.removeService(this.Fan!.Service);
|
|
861
753
|
}
|
|
862
754
|
|
|
863
755
|
async removeWindowService(accessory: PlatformAccessory): Promise<void> {
|
|
864
|
-
// If
|
|
865
|
-
this.
|
|
866
|
-
if (this.
|
|
756
|
+
// If Window.Service still present, then remove first
|
|
757
|
+
this.Window!.Service = this.accessory.getService(this.hap.Service.Window) as Service;
|
|
758
|
+
if (this.Window!.Service) {
|
|
867
759
|
this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Window Service`);
|
|
868
760
|
}
|
|
869
|
-
accessory.removeService(this.
|
|
761
|
+
accessory.removeService(this.Window!.Service);
|
|
870
762
|
}
|
|
871
763
|
|
|
872
764
|
async removeWindowCoveringService(accessory: PlatformAccessory): Promise<void> {
|
|
873
|
-
// If
|
|
874
|
-
this.
|
|
875
|
-
if (this.
|
|
765
|
+
// If WindowCovering.Service still present, then remove first
|
|
766
|
+
this.WindowCovering!.Service = this.accessory.getService(this.hap.Service.WindowCovering) as Service;
|
|
767
|
+
if (this.WindowCovering!.Service) {
|
|
876
768
|
this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Window Covering Service`);
|
|
877
769
|
}
|
|
878
|
-
accessory.removeService(this.
|
|
770
|
+
accessory.removeService(this.WindowCovering!.Service);
|
|
879
771
|
}
|
|
880
772
|
|
|
881
773
|
async removeStatefulProgrammableSwitchService(accessory: PlatformAccessory): Promise<void> {
|
|
882
|
-
// If
|
|
883
|
-
this.
|
|
884
|
-
if (this.
|
|
774
|
+
// If StatefulProgrammableSwitch.Service still present, then remove first
|
|
775
|
+
this.StatefulProgrammableSwitch!.Service = this.accessory.getService(this.hap.Service.StatefulProgrammableSwitch) as Service;
|
|
776
|
+
if (this.StatefulProgrammableSwitch!.Service) {
|
|
885
777
|
this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Stateful Programmable Switch Service`);
|
|
886
778
|
}
|
|
887
|
-
accessory.removeService(this.
|
|
779
|
+
accessory.removeService(this.StatefulProgrammableSwitch!.Service);
|
|
888
780
|
}
|
|
889
781
|
|
|
890
782
|
async removeSwitchService(accessory: PlatformAccessory): Promise<void> {
|
|
891
|
-
// If
|
|
892
|
-
this.
|
|
893
|
-
if (this.
|
|
783
|
+
// If Switch.Service still present, then remove first
|
|
784
|
+
this.Switch!.Service = this.accessory.getService(this.hap.Service.Switch) as Service;
|
|
785
|
+
if (this.Switch!.Service) {
|
|
894
786
|
this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Switch Service`);
|
|
895
787
|
}
|
|
896
|
-
accessory.removeService(this.
|
|
788
|
+
accessory.removeService(this.Switch!.Service);
|
|
897
789
|
}
|
|
898
790
|
|
|
899
|
-
async
|
|
791
|
+
async getOtherConfigSettings(device: irdevice & irDevicesConfig): Promise<void> {
|
|
900
792
|
if (!device.other?.deviceType && this.accessory.context.deviceType) {
|
|
901
793
|
this.otherDeviceType = this.accessory.context.deviceType;
|
|
902
794
|
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Type: ${this.otherDeviceType}, from Accessory Cache.`);
|
|
@@ -910,123 +802,4 @@ export class Others {
|
|
|
910
802
|
this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} no deviceType set, using default deviceType: ${this.otherDeviceType}`);
|
|
911
803
|
}
|
|
912
804
|
}
|
|
913
|
-
|
|
914
|
-
async deviceContext() {
|
|
915
|
-
if (this.On === undefined) {
|
|
916
|
-
this.On = true;
|
|
917
|
-
} else {
|
|
918
|
-
this.On = this.accessory.context.On;
|
|
919
|
-
}
|
|
920
|
-
if (this.FirmwareRevision === undefined) {
|
|
921
|
-
this.FirmwareRevision = this.platform.version;
|
|
922
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
|
|
926
|
-
async deviceConfig(device: irdevice & irDevicesConfig): Promise<void> {
|
|
927
|
-
let config = {};
|
|
928
|
-
if (device.other) {
|
|
929
|
-
config = device.other;
|
|
930
|
-
}
|
|
931
|
-
if (device.logging !== undefined) {
|
|
932
|
-
config['logging'] = device.logging;
|
|
933
|
-
}
|
|
934
|
-
if (device.connectionType !== undefined) {
|
|
935
|
-
config['connectionType'] = device.connectionType;
|
|
936
|
-
}
|
|
937
|
-
if (device.external !== undefined) {
|
|
938
|
-
config['external'] = device.external;
|
|
939
|
-
}
|
|
940
|
-
if (device.customOn !== undefined) {
|
|
941
|
-
config['customOn'] = device.customOn;
|
|
942
|
-
}
|
|
943
|
-
if (device.customOff !== undefined) {
|
|
944
|
-
config['customOff'] = device.customOff;
|
|
945
|
-
}
|
|
946
|
-
if (device.customize !== undefined) {
|
|
947
|
-
config['customize'] = device.customize;
|
|
948
|
-
}
|
|
949
|
-
if (device.disablePushOn !== undefined) {
|
|
950
|
-
config['disablePushOn'] = device.disablePushOn;
|
|
951
|
-
}
|
|
952
|
-
if (device.disablePushOff !== undefined) {
|
|
953
|
-
config['disablePushOff'] = device.disablePushOff;
|
|
954
|
-
}
|
|
955
|
-
if (Object.entries(config).length !== 0) {
|
|
956
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
957
|
-
}
|
|
958
|
-
}
|
|
959
|
-
|
|
960
|
-
async deviceLogs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
961
|
-
if (this.platform.debugMode) {
|
|
962
|
-
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
963
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
964
|
-
} else if (device.logging) {
|
|
965
|
-
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
966
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
967
|
-
} else if (this.platform.config.options?.logging) {
|
|
968
|
-
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
969
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
970
|
-
} else {
|
|
971
|
-
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
972
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
973
|
-
}
|
|
974
|
-
}
|
|
975
|
-
|
|
976
|
-
/**
|
|
977
|
-
* Logging for Device
|
|
978
|
-
*/
|
|
979
|
-
successLog(...log: any[]): void {
|
|
980
|
-
if (this.enablingDeviceLogging()) {
|
|
981
|
-
this.platform.log.success(String(...log));
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
|
|
985
|
-
infoLog(...log: any[]): void {
|
|
986
|
-
if (this.enablingDeviceLogging()) {
|
|
987
|
-
this.platform.log.info(String(...log));
|
|
988
|
-
}
|
|
989
|
-
}
|
|
990
|
-
|
|
991
|
-
warnLog(...log: any[]): void {
|
|
992
|
-
if (this.enablingDeviceLogging()) {
|
|
993
|
-
this.platform.log.warn(String(...log));
|
|
994
|
-
}
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
debugWarnLog(...log: any[]): void {
|
|
998
|
-
if (this.enablingDeviceLogging()) {
|
|
999
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
1000
|
-
this.platform.log.warn('[DEBUG]', String(...log));
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
errorLog(...log: any[]): void {
|
|
1006
|
-
if (this.enablingDeviceLogging()) {
|
|
1007
|
-
this.platform.log.error(String(...log));
|
|
1008
|
-
}
|
|
1009
|
-
}
|
|
1010
|
-
|
|
1011
|
-
debugErrorLog(...log: any[]): void {
|
|
1012
|
-
if (this.enablingDeviceLogging()) {
|
|
1013
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
1014
|
-
this.platform.log.error('[DEBUG]', String(...log));
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
|
|
1019
|
-
debugLog(...log: any[]): void {
|
|
1020
|
-
if (this.enablingDeviceLogging()) {
|
|
1021
|
-
if (this.deviceLogging === 'debug') {
|
|
1022
|
-
this.platform.log.info('[DEBUG]', String(...log));
|
|
1023
|
-
} else {
|
|
1024
|
-
this.platform.log.debug(String(...log));
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
|
-
|
|
1029
|
-
enablingDeviceLogging(): boolean {
|
|
1030
|
-
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
1031
|
-
}
|
|
1032
805
|
}
|