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