@switchbot/homebridge-switchbot 3.5.0-beta.9 → 3.5.1-beta.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 +164 -22
- package/dist/device/blindtilt.d.ts +21 -96
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +457 -866
- 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 +851 -913
- 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 +316 -742
- 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 +380 -833
- 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 +267 -602
- 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 +469 -897
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +76 -0
- package/dist/device/device.d.ts.map +1 -0
- package/dist/device/device.js +846 -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 +645 -0
- package/dist/device/fan.js.map +1 -0
- package/dist/device/hub.d.ts +19 -58
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +304 -640
- 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 +300 -710
- 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 +225 -643
- 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 +371 -742
- 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 +309 -642
- 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 +223 -638
- 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 +216 -644
- 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 +209 -588
- 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 +141 -532
- 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 +252 -609
- 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 +179 -521
- 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 +337 -482
- 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 +108 -333
- 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 +47 -299
- 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 +95 -364
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +46 -0
- package/dist/irdevice/irdevice.d.ts.map +1 -0
- package/dist/irdevice/irdevice.js +393 -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 +121 -376
- 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 +441 -584
- 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 +94 -353
- 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 +48 -299
- 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 +50 -305
- 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 +66 -18
- 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 +95 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +657 -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 +488 -937
- package/src/device/bot.ts +907 -1016
- package/src/device/ceilinglight.ts +330 -798
- package/src/device/colorbulb.ts +394 -904
- package/src/device/contact.ts +298 -637
- package/src/device/curtain.ts +496 -954
- package/src/device/device.ts +872 -0
- package/src/device/fan.ts +692 -0
- package/src/device/hub.ts +338 -671
- package/src/device/humidifier.ts +330 -777
- package/src/device/iosensor.ts +258 -671
- package/src/device/lightstrip.ts +394 -809
- package/src/device/lock.ts +345 -700
- package/src/device/meter.ts +256 -666
- package/src/device/meterplus.ts +248 -672
- package/src/device/motion.ts +234 -622
- package/src/device/plug.ts +152 -572
- package/src/device/robotvacuumcleaner.ts +273 -653
- package/src/device/waterdetector.ts +198 -549
- 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 +368 -540
- package/src/irdevice/airpurifier.ts +134 -369
- package/src/irdevice/camera.ts +60 -324
- package/src/irdevice/fan.ts +111 -392
- package/src/irdevice/irdevice.ts +406 -0
- package/src/irdevice/light.ts +159 -425
- package/src/irdevice/other.ts +509 -661
- package/src/irdevice/tv.ts +123 -388
- package/src/irdevice/vacuumcleaner.ts +61 -324
- package/src/irdevice/waterheater.ts +63 -333
- package/src/platform.ts +395 -259
- package/src/settings.ts +120 -610
- package/src/utils.ts +661 -1
- package/src/device/waterdetector.json +0 -11
package/src/irdevice/other.ts
CHANGED
|
@@ -1,67 +1,114 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* other.ts: @switchbot/homebridge-switchbot.
|
|
4
|
+
*/
|
|
5
|
+
import { irdeviceBase } from './irdevice.js';
|
|
6
|
+
|
|
7
|
+
import type { SwitchBotPlatform } from '../platform.js';
|
|
8
|
+
import type { irDevicesConfig, irdevice } from '../settings.js';
|
|
9
|
+
import type { 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
|
-
public readonly api: API;
|
|
13
|
-
public readonly log: Logging;
|
|
14
|
-
public readonly config!: SwitchBotPlatformConfig;
|
|
15
|
-
protected readonly hap: HAP;
|
|
16
|
+
export class Others extends irdeviceBase {
|
|
16
17
|
// Services
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
18
|
+
private Switch?: {
|
|
19
|
+
Name: CharacteristicValue;
|
|
20
|
+
Service: Service;
|
|
21
|
+
On: CharacteristicValue;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
private GarageDoor?: {
|
|
25
|
+
Name: CharacteristicValue;
|
|
26
|
+
Service: Service;
|
|
27
|
+
On: CharacteristicValue;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
private Door?: {
|
|
31
|
+
Name: CharacteristicValue;
|
|
32
|
+
Service: Service;
|
|
33
|
+
On: CharacteristicValue;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
private Window?: {
|
|
37
|
+
Name: CharacteristicValue;
|
|
38
|
+
Service: Service;
|
|
39
|
+
On: CharacteristicValue;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
private WindowCovering?: {
|
|
43
|
+
Name: CharacteristicValue;
|
|
44
|
+
Service: Service;
|
|
45
|
+
On: CharacteristicValue;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
private LockMechanism?: {
|
|
49
|
+
Name: CharacteristicValue;
|
|
50
|
+
Service: Service;
|
|
51
|
+
On: CharacteristicValue;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
private Faucet?: {
|
|
55
|
+
Name: CharacteristicValue;
|
|
56
|
+
Service: Service;
|
|
57
|
+
On: CharacteristicValue;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
private Fan?: {
|
|
61
|
+
Name: CharacteristicValue;
|
|
62
|
+
Service: Service;
|
|
63
|
+
On: CharacteristicValue;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
private StatefulProgrammableSwitch?: {
|
|
67
|
+
Name: CharacteristicValue;
|
|
68
|
+
Service: Service;
|
|
69
|
+
On: CharacteristicValue;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
private Outlet?: {
|
|
73
|
+
Name: CharacteristicValue;
|
|
74
|
+
Service: Service;
|
|
75
|
+
On: CharacteristicValue;
|
|
76
|
+
};
|
|
31
77
|
|
|
32
78
|
// Config
|
|
33
|
-
deviceLogging!: string;
|
|
34
|
-
disablePushOn?: boolean;
|
|
35
79
|
otherDeviceType?: string;
|
|
36
|
-
disablePushOff?: boolean;
|
|
37
80
|
|
|
38
81
|
constructor(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
82
|
+
readonly platform: SwitchBotPlatform,
|
|
83
|
+
accessory: PlatformAccessory,
|
|
84
|
+
device: irdevice & irDevicesConfig,
|
|
42
85
|
) {
|
|
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);
|
|
86
|
+
super(platform, accessory, device);
|
|
54
87
|
|
|
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);
|
|
88
|
+
// default placeholders
|
|
89
|
+
this.getOtherConfigSettings(device);
|
|
62
90
|
|
|
63
91
|
// deviceType
|
|
64
92
|
if (this.otherDeviceType === 'switch') {
|
|
93
|
+
// Initialize Switch Service
|
|
94
|
+
accessory.context.Switch = accessory.context.Switch ?? {};
|
|
95
|
+
this.Switch = {
|
|
96
|
+
Name: accessory.context.Switch.Name ?? `${accessory.displayName} Switch`,
|
|
97
|
+
Service: accessory.getService(this.hap.Service.Switch) ?? accessory.addService(this.hap.Service.Switch) as Service,
|
|
98
|
+
On: accessory.context.On ?? false,
|
|
99
|
+
};
|
|
100
|
+
accessory.context.Switch = this.Switch as object;
|
|
101
|
+
this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Switch`);
|
|
102
|
+
|
|
103
|
+
this.Switch.Service
|
|
104
|
+
.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
|
|
105
|
+
.getCharacteristic(this.hap.Characteristic.On)
|
|
106
|
+
.onGet(() => {
|
|
107
|
+
return this.Switch!.On;
|
|
108
|
+
})
|
|
109
|
+
.onSet(this.OnSet.bind(this));
|
|
110
|
+
|
|
111
|
+
// Remove other services
|
|
65
112
|
this.removeFanService(accessory);
|
|
66
113
|
this.removeLockService(accessory);
|
|
67
114
|
this.removeDoorService(accessory);
|
|
@@ -71,19 +118,27 @@ export class Others {
|
|
|
71
118
|
this.removeGarageDoorService(accessory);
|
|
72
119
|
this.removeWindowCoveringService(accessory);
|
|
73
120
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
121
|
+
} else if (this.otherDeviceType === 'garagedoor') {
|
|
122
|
+
// Initialize Garage Door Service
|
|
123
|
+
accessory.context.GarageDoor = accessory.context.GarageDoor ?? {};
|
|
124
|
+
this.GarageDoor = {
|
|
125
|
+
Name: accessory.context.GarageDoor.Name ?? `${accessory.displayName} Garage Door`,
|
|
126
|
+
Service: accessory.getService(this.hap.Service.GarageDoorOpener) ?? accessory.addService(this.hap.Service.GarageDoorOpener) as Service,
|
|
127
|
+
On: accessory.context.On ?? false,
|
|
128
|
+
};
|
|
129
|
+
accessory.context.GarageDoor = this.GarageDoor as object;
|
|
130
|
+
this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Garage Door Opener`);
|
|
74
131
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
132
|
+
this.GarageDoor.Service
|
|
133
|
+
.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
|
|
134
|
+
.setCharacteristic(this.hap.Characteristic.ObstructionDetected, false)
|
|
135
|
+
.getCharacteristic(this.hap.Characteristic.TargetDoorState)
|
|
136
|
+
.onGet(() => {
|
|
137
|
+
return this.GarageDoor!.On;
|
|
138
|
+
})
|
|
139
|
+
.onSet(this.OnSet.bind(this));
|
|
80
140
|
|
|
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') {
|
|
141
|
+
// Remove other services
|
|
87
142
|
this.removeFanService(accessory);
|
|
88
143
|
this.removeLockService(accessory);
|
|
89
144
|
this.removeDoorService(accessory);
|
|
@@ -93,20 +148,33 @@ export class Others {
|
|
|
93
148
|
this.removeWindowService(accessory);
|
|
94
149
|
this.removeWindowCoveringService(accessory);
|
|
95
150
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
151
|
+
} else if (this.otherDeviceType === 'door') {
|
|
152
|
+
// Initialize Door Service
|
|
153
|
+
accessory.context.Door = accessory.context.Door ?? {};
|
|
154
|
+
this.Door = {
|
|
155
|
+
Name: accessory.context.Door.Name ?? `${accessory.displayName} Door`,
|
|
156
|
+
Service: accessory.getService(this.hap.Service.Door) ?? accessory.addService(this.hap.Service.Door) as Service,
|
|
157
|
+
On: accessory.context.On ?? false,
|
|
158
|
+
};
|
|
159
|
+
accessory.context.Door = this.Door as object;
|
|
160
|
+
this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Door`);
|
|
96
161
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
162
|
+
this.Door!.Service
|
|
163
|
+
.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
|
|
164
|
+
.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
165
|
+
.getCharacteristic(this.hap.Characteristic.TargetPosition)
|
|
166
|
+
.setProps({
|
|
167
|
+
validValues: [0, 100],
|
|
168
|
+
minValue: 0,
|
|
169
|
+
maxValue: 100,
|
|
170
|
+
minStep: 100,
|
|
171
|
+
})
|
|
172
|
+
.onGet(() => {
|
|
173
|
+
return this.GarageDoor!.On;
|
|
174
|
+
})
|
|
175
|
+
.onSet(this.OnSet.bind(this));
|
|
102
176
|
|
|
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') {
|
|
177
|
+
// Remove other services
|
|
110
178
|
this.removeFanService(accessory);
|
|
111
179
|
this.removeLockService(accessory);
|
|
112
180
|
this.removeOutletService(accessory);
|
|
@@ -116,18 +184,19 @@ export class Others {
|
|
|
116
184
|
this.removeGarageDoorService(accessory);
|
|
117
185
|
this.removeWindowCoveringService(accessory);
|
|
118
186
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
187
|
+
} else if (this.otherDeviceType === 'window') {
|
|
188
|
+
// Initialize Window Service
|
|
189
|
+
accessory.context.Window = accessory.context.Window ?? {};
|
|
190
|
+
this.Window = {
|
|
191
|
+
Name: accessory.context.Window.Name ?? `${accessory.displayName} Window`,
|
|
192
|
+
Service: accessory.getService(this.hap.Service.Window) ?? accessory.addService(this.hap.Service.Window) as Service,
|
|
193
|
+
On: accessory.context.On ?? false,
|
|
194
|
+
};
|
|
195
|
+
accessory.context.Window = this.Window as object;
|
|
196
|
+
this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Window`);
|
|
119
197
|
|
|
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
|
|
198
|
+
this.Window!.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
|
|
199
|
+
.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
131
200
|
.getCharacteristic(this.hap.Characteristic.TargetPosition)
|
|
132
201
|
.setProps({
|
|
133
202
|
validValues: [0, 100],
|
|
@@ -135,9 +204,12 @@ export class Others {
|
|
|
135
204
|
maxValue: 100,
|
|
136
205
|
minStep: 100,
|
|
137
206
|
})
|
|
207
|
+
.onGet(() => {
|
|
208
|
+
return this.GarageDoor!.On;
|
|
209
|
+
})
|
|
138
210
|
.onSet(this.OnSet.bind(this));
|
|
139
|
-
|
|
140
|
-
|
|
211
|
+
|
|
212
|
+
// Remove other services
|
|
141
213
|
this.removeFanService(accessory);
|
|
142
214
|
this.removeLockService(accessory);
|
|
143
215
|
this.removeDoorService(accessory);
|
|
@@ -147,18 +219,20 @@ export class Others {
|
|
|
147
219
|
this.removeGarageDoorService(accessory);
|
|
148
220
|
this.removeWindowCoveringService(accessory);
|
|
149
221
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
222
|
+
} else if (this.otherDeviceType === 'windowcovering') {
|
|
223
|
+
// Initialize WindowCovering Service
|
|
224
|
+
accessory.context.WindowCovering = accessory.context.WindowCovering ?? {};
|
|
225
|
+
this.WindowCovering = {
|
|
226
|
+
Name: accessory.context.WindowCovering.Name ?? `${accessory.displayName} Window Covering`,
|
|
227
|
+
Service: accessory.getService(this.hap.Service.WindowCovering) ?? accessory.addService(this.hap.Service.WindowCovering) as Service,
|
|
228
|
+
On: accessory.context.On ?? false,
|
|
229
|
+
};
|
|
230
|
+
accessory.context.WindowCovering = this.WindowCovering as object;
|
|
231
|
+
this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Window Covering`);
|
|
150
232
|
|
|
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
|
|
233
|
+
this.WindowCovering.Service
|
|
234
|
+
.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
|
|
235
|
+
.setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
|
|
162
236
|
.getCharacteristic(this.hap.Characteristic.TargetPosition)
|
|
163
237
|
.setProps({
|
|
164
238
|
validValues: [0, 100],
|
|
@@ -166,9 +240,12 @@ export class Others {
|
|
|
166
240
|
maxValue: 100,
|
|
167
241
|
minStep: 100,
|
|
168
242
|
})
|
|
243
|
+
.onGet(() => {
|
|
244
|
+
return this.WindowCovering!.On;
|
|
245
|
+
})
|
|
169
246
|
.onSet(this.OnSet.bind(this));
|
|
170
|
-
|
|
171
|
-
|
|
247
|
+
|
|
248
|
+
// Remove other services
|
|
172
249
|
this.removeFanService(accessory);
|
|
173
250
|
this.removeLockService(accessory);
|
|
174
251
|
this.removeDoorService(accessory);
|
|
@@ -178,28 +255,26 @@ export class Others {
|
|
|
178
255
|
this.removeWindowService(accessory);
|
|
179
256
|
this.removeGarageDoorService(accessory);
|
|
180
257
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
258
|
+
} else if (this.otherDeviceType === 'lock') {
|
|
259
|
+
// Initialize LockMechanism Service
|
|
260
|
+
accessory.context.LockMechanism = accessory.context.LockMechanism ?? {};
|
|
261
|
+
this.LockMechanism = {
|
|
262
|
+
Name: accessory.context.LockMechanism.Name ?? `${accessory.displayName} Lock`,
|
|
263
|
+
Service: accessory.getService(this.hap.Service.LockMechanism) ?? accessory.addService(this.hap.Service.LockMechanism) as Service,
|
|
264
|
+
On: accessory.context.On ?? false,
|
|
265
|
+
};
|
|
266
|
+
accessory.context.LockMechanism = this.LockMechanism as object;
|
|
267
|
+
this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Lock`);
|
|
181
268
|
|
|
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,
|
|
269
|
+
this.LockMechanism.Service
|
|
270
|
+
.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
|
|
271
|
+
.getCharacteristic(this.hap.Characteristic.LockTargetState)
|
|
272
|
+
.onGet(() => {
|
|
273
|
+
return this.LockMechanism!.On;
|
|
199
274
|
})
|
|
200
275
|
.onSet(this.OnSet.bind(this));
|
|
201
|
-
|
|
202
|
-
|
|
276
|
+
|
|
277
|
+
// Remove other services
|
|
203
278
|
this.removeFanService(accessory);
|
|
204
279
|
this.removeDoorService(accessory);
|
|
205
280
|
this.removeOutletService(accessory);
|
|
@@ -209,19 +284,26 @@ export class Others {
|
|
|
209
284
|
this.removeGarageDoorService(accessory);
|
|
210
285
|
this.removeWindowCoveringService(accessory);
|
|
211
286
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
287
|
+
} else if (this.otherDeviceType === 'faucet') {
|
|
288
|
+
// Initialize Faucet Service
|
|
289
|
+
accessory.context.Faucet = accessory.context.Faucet ?? {};
|
|
290
|
+
this.Faucet = {
|
|
291
|
+
Name: accessory.context.Faucet.Name ?? `${accessory.displayName} Faucet`,
|
|
292
|
+
Service: accessory.getService(this.hap.Service.Faucet) ?? accessory.addService(this.hap.Service.Faucet) as Service,
|
|
293
|
+
On: accessory.context.On ?? false,
|
|
294
|
+
};
|
|
295
|
+
accessory.context.Faucet = this.Faucet as object;
|
|
296
|
+
this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Faucet`);
|
|
212
297
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
298
|
+
this.Faucet.Service
|
|
299
|
+
.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
|
|
300
|
+
.getCharacteristic(this.hap.Characteristic.Active)
|
|
301
|
+
.onGet(() => {
|
|
302
|
+
return this.Faucet!.On;
|
|
303
|
+
})
|
|
304
|
+
.onSet(this.OnSet.bind(this));
|
|
218
305
|
|
|
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') {
|
|
306
|
+
// Remove other services
|
|
225
307
|
this.removeFanService(accessory);
|
|
226
308
|
this.removeLockService(accessory);
|
|
227
309
|
this.removeDoorService(accessory);
|
|
@@ -231,19 +313,26 @@ export class Others {
|
|
|
231
313
|
this.removeGarageDoorService(accessory);
|
|
232
314
|
this.removeWindowCoveringService(accessory);
|
|
233
315
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
316
|
+
} else if (this.otherDeviceType === 'fan') {
|
|
317
|
+
// Initialize Fan Service
|
|
318
|
+
accessory.context.Fan = accessory.context.Fan ?? {};
|
|
319
|
+
this.Fan = {
|
|
320
|
+
Name: accessory.context.Fan.Name ?? `${accessory.displayName} Fan`,
|
|
321
|
+
Service: accessory.getService(this.hap.Service.Fanv2) ?? accessory.addService(this.hap.Service.Fanv2) as Service,
|
|
322
|
+
On: accessory.context.On ?? false,
|
|
323
|
+
};
|
|
324
|
+
accessory.context.Fan = this.Fan as object;
|
|
325
|
+
this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Fan`);
|
|
234
326
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
327
|
+
this.Fan.Service
|
|
328
|
+
.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
|
|
329
|
+
.getCharacteristic(this.hap.Characteristic.On)
|
|
330
|
+
.onGet(() => {
|
|
331
|
+
return this.Fan!.On;
|
|
332
|
+
})
|
|
333
|
+
.onSet(this.OnSet.bind(this));
|
|
240
334
|
|
|
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') {
|
|
335
|
+
// Remove other services
|
|
247
336
|
this.removeLockService(accessory);
|
|
248
337
|
this.removeDoorService(accessory);
|
|
249
338
|
this.removeFaucetService(accessory);
|
|
@@ -253,19 +342,27 @@ export class Others {
|
|
|
253
342
|
this.removeGarageDoorService(accessory);
|
|
254
343
|
this.removeWindowCoveringService(accessory);
|
|
255
344
|
this.removeStatefulProgrammableSwitchService(accessory);
|
|
345
|
+
} else if (this.otherDeviceType === 'stateful') {
|
|
346
|
+
// Initialize StatefulProgrammableSwitch Service
|
|
347
|
+
accessory.context.StatefulProgrammableSwitch = accessory.context.StatefulProgrammableSwitch ?? {};
|
|
348
|
+
this.StatefulProgrammableSwitch = {
|
|
349
|
+
Name: accessory.context.StatefulProgrammableSwitch.Name ?? `${accessory.displayName} Stateful Programmable Switch`,
|
|
350
|
+
Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
|
|
351
|
+
?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch) as Service,
|
|
352
|
+
On: accessory.context.On ?? false,
|
|
353
|
+
};
|
|
354
|
+
accessory.context.StatefulProgrammableSwitch = this.StatefulProgrammableSwitch as object;
|
|
355
|
+
this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Stateful Programmable Switch`);
|
|
256
356
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
357
|
+
this.StatefulProgrammableSwitch.Service
|
|
358
|
+
.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
|
|
359
|
+
.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
|
|
360
|
+
.onGet(() => {
|
|
361
|
+
return this.StatefulProgrammableSwitch!.On;
|
|
362
|
+
})
|
|
363
|
+
.onSet(this.OnSet.bind(this));
|
|
262
364
|
|
|
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') {
|
|
365
|
+
// Remove other services
|
|
269
366
|
this.removeFanService(accessory);
|
|
270
367
|
this.removeLockService(accessory);
|
|
271
368
|
this.removeDoorService(accessory);
|
|
@@ -275,21 +372,26 @@ export class Others {
|
|
|
275
372
|
this.removeWindowService(accessory);
|
|
276
373
|
this.removeGarageDoorService(accessory);
|
|
277
374
|
this.removeWindowCoveringService(accessory);
|
|
375
|
+
} else {
|
|
376
|
+
// Initialize Outlet Service
|
|
377
|
+
accessory.context.Outlet = accessory.context.Outlet ?? {};
|
|
378
|
+
this.Outlet = {
|
|
379
|
+
Name: accessory.context.Outlet.Name ?? `${accessory.displayName} Outlet`,
|
|
380
|
+
Service: accessory.getService(this.hap.Service.Outlet) ?? accessory.addService(this.hap.Service.Outlet) as Service,
|
|
381
|
+
On: accessory.context.On ?? false,
|
|
382
|
+
};
|
|
383
|
+
accessory.context.Outlet = this.Outlet as object;
|
|
384
|
+
this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Outlet`);
|
|
278
385
|
|
|
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)
|
|
386
|
+
this.Outlet.Service
|
|
387
|
+
.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
|
|
388
|
+
.getCharacteristic(this.hap.Characteristic.On)
|
|
389
|
+
.onGet(() => {
|
|
390
|
+
return this.Outlet!.On;
|
|
391
|
+
})
|
|
291
392
|
.onSet(this.OnSet.bind(this));
|
|
292
|
-
|
|
393
|
+
|
|
394
|
+
// Remove other services
|
|
293
395
|
this.removeFanService(accessory);
|
|
294
396
|
this.removeLockService(accessory);
|
|
295
397
|
this.removeDoorService(accessory);
|
|
@@ -299,18 +401,6 @@ export class Others {
|
|
|
299
401
|
this.removeGarageDoorService(accessory);
|
|
300
402
|
this.removeWindowCoveringService(accessory);
|
|
301
403
|
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
404
|
}
|
|
315
405
|
}
|
|
316
406
|
|
|
@@ -318,55 +408,75 @@ export class Others {
|
|
|
318
408
|
* Handle requests to set the "On" characteristic
|
|
319
409
|
*/
|
|
320
410
|
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
411
|
+
let On: boolean;
|
|
321
412
|
if (this.otherDeviceType === 'garagedoor') {
|
|
322
413
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set TargetDoorState: ${value}`);
|
|
323
414
|
if (value === this.hap.Characteristic.TargetDoorState.CLOSED) {
|
|
324
|
-
this.On = false;
|
|
415
|
+
this.GarageDoor!.On = false;
|
|
416
|
+
} else {
|
|
417
|
+
this.GarageDoor!.On = true;
|
|
418
|
+
}
|
|
419
|
+
On = this.GarageDoor!.On;
|
|
420
|
+
} else if (this.otherDeviceType === 'door') {
|
|
421
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set TargetPosition: ${value}`);
|
|
422
|
+
if (value === 0) {
|
|
423
|
+
this.Door!.On = false;
|
|
325
424
|
} else {
|
|
326
|
-
this.On = true;
|
|
425
|
+
this.Door!.On = true;
|
|
327
426
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
this.
|
|
331
|
-
|
|
332
|
-
|
|
427
|
+
On = this.Door!.On;
|
|
428
|
+
} else if (this.otherDeviceType === 'window') {
|
|
429
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set TargetPosition: ${value}`);
|
|
430
|
+
if (value === 0) {
|
|
431
|
+
this.Window!.On = false;
|
|
432
|
+
} else {
|
|
433
|
+
this.Window!.On = true;
|
|
434
|
+
}
|
|
435
|
+
On = this.Window!.On;
|
|
436
|
+
} else if (this.otherDeviceType === 'windowcovering') {
|
|
333
437
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set TargetPosition: ${value}`);
|
|
334
438
|
if (value === 0) {
|
|
335
|
-
this.On = false;
|
|
439
|
+
this.WindowCovering!.On = false;
|
|
336
440
|
} else {
|
|
337
|
-
this.On = true;
|
|
441
|
+
this.WindowCovering!.On = true;
|
|
338
442
|
}
|
|
443
|
+
On = this.WindowCovering!.On;
|
|
339
444
|
} else if (this.otherDeviceType === 'lock') {
|
|
340
445
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set LockTargetState: ${value}`);
|
|
341
446
|
if (value === this.hap.Characteristic.LockTargetState.SECURED) {
|
|
342
|
-
this.On = false;
|
|
447
|
+
this.LockMechanism!.On = false;
|
|
343
448
|
} else {
|
|
344
|
-
this.On = true;
|
|
449
|
+
this.LockMechanism!.On = true;
|
|
345
450
|
}
|
|
451
|
+
On = this.LockMechanism!.On;
|
|
346
452
|
} else if (this.otherDeviceType === 'faucet') {
|
|
347
453
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Active: ${value}`);
|
|
348
454
|
if (value === this.hap.Characteristic.Active.INACTIVE) {
|
|
349
|
-
this.On = false;
|
|
455
|
+
this.Faucet!.On = false;
|
|
350
456
|
} else {
|
|
351
|
-
this.On = true;
|
|
457
|
+
this.Faucet!.On = true;
|
|
352
458
|
}
|
|
459
|
+
On = this.Faucet!.On;
|
|
353
460
|
} else if (this.otherDeviceType === 'stateful') {
|
|
354
461
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set ProgrammableSwitchOutputState: ${value}`);
|
|
355
462
|
if (value === 0) {
|
|
356
|
-
this.On = false;
|
|
463
|
+
this.StatefulProgrammableSwitch!.On = false;
|
|
357
464
|
} else {
|
|
358
|
-
this.On = true;
|
|
465
|
+
this.StatefulProgrammableSwitch!.On = true;
|
|
359
466
|
}
|
|
467
|
+
|
|
468
|
+
On = this.StatefulProgrammableSwitch!.On;
|
|
360
469
|
} else {
|
|
361
470
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set On: ${value}`);
|
|
362
|
-
this.On = value;
|
|
471
|
+
this.Outlet!.On = value;
|
|
472
|
+
On = this.Outlet!.On ? true : false;
|
|
363
473
|
}
|
|
364
474
|
|
|
365
475
|
//pushChanges
|
|
366
|
-
if (
|
|
367
|
-
await this.pushOnChanges();
|
|
476
|
+
if (On === true) {
|
|
477
|
+
await this.pushOnChanges(On);
|
|
368
478
|
} else {
|
|
369
|
-
await this.pushOffChanges();
|
|
479
|
+
await this.pushOffChanges(On);
|
|
370
480
|
}
|
|
371
481
|
}
|
|
372
482
|
|
|
@@ -380,13 +490,11 @@ export class Others {
|
|
|
380
490
|
* Other - "command" "channelAdd" "default" = next channel
|
|
381
491
|
* Other - "command" "channelSub" "default" = previous channel
|
|
382
492
|
*/
|
|
383
|
-
async pushOnChanges(): Promise<void> {
|
|
384
|
-
this.debugLog(
|
|
385
|
-
|
|
386
|
-
` disablePushOn: ${this.disablePushOn}, customize: ${this.device.customize}, customOn: ${this.device.customOn}`,
|
|
387
|
-
);
|
|
493
|
+
async pushOnChanges(On: boolean): Promise<void> {
|
|
494
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOnChanges On: ${On},`
|
|
495
|
+
+ ` disablePushOn: ${this.disablePushOn}, customize: ${this.device.customize}, customOn: ${this.device.customOn}`);
|
|
388
496
|
if (this.device.customize) {
|
|
389
|
-
if (
|
|
497
|
+
if (On === true && !this.disablePushOn) {
|
|
390
498
|
const commandType: string = await this.commandType();
|
|
391
499
|
const command: string = await this.commandOn();
|
|
392
500
|
const bodyChange = JSON.stringify({
|
|
@@ -401,13 +509,11 @@ export class Others {
|
|
|
401
509
|
}
|
|
402
510
|
}
|
|
403
511
|
|
|
404
|
-
async pushOffChanges(): Promise<void> {
|
|
405
|
-
this.debugLog(
|
|
406
|
-
|
|
407
|
-
` disablePushOff: ${this.disablePushOff}, customize: ${this.device.customize}, customOff: ${this.device.customOff}`,
|
|
408
|
-
);
|
|
512
|
+
async pushOffChanges(On: boolean): Promise<void> {
|
|
513
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOffChanges On: ${On},`
|
|
514
|
+
+ ` disablePushOff: ${this.disablePushOff}, customize: ${this.device.customize}, customOff: ${this.device.customOff}`);
|
|
409
515
|
if (this.device.customize) {
|
|
410
|
-
if (
|
|
516
|
+
if (On === false && !this.disablePushOff) {
|
|
411
517
|
const commandType: string = await this.commandType();
|
|
412
518
|
const command: string = await this.commandOff();
|
|
413
519
|
const bodyChange = JSON.stringify({
|
|
@@ -427,475 +533,330 @@ export class Others {
|
|
|
427
533
|
if (this.device.connectionType === 'OpenAPI') {
|
|
428
534
|
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
429
535
|
try {
|
|
430
|
-
const { body, statusCode } = await
|
|
431
|
-
body: bodyChange,
|
|
432
|
-
method: 'POST',
|
|
433
|
-
headers: this.platform.generateHeaders(),
|
|
434
|
-
});
|
|
435
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
536
|
+
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
436
537
|
const deviceStatus: any = await body.json();
|
|
437
|
-
this.
|
|
438
|
-
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
538
|
+
await this.pushStatusCodes(statusCode, deviceStatus);
|
|
439
539
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
440
|
-
this.
|
|
441
|
-
|
|
442
|
-
this.updateHomeKitCharacteristics();
|
|
540
|
+
await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
|
|
541
|
+
await this.updateHomeKitCharacteristics();
|
|
443
542
|
} else {
|
|
444
|
-
this.statusCode(statusCode);
|
|
445
|
-
this.statusCode(deviceStatus.statusCode);
|
|
543
|
+
await this.statusCode(statusCode);
|
|
544
|
+
await this.statusCode(deviceStatus.statusCode);
|
|
446
545
|
}
|
|
447
546
|
} catch (e: any) {
|
|
448
547
|
this.apiError(e);
|
|
449
|
-
this.errorLog(
|
|
450
|
-
|
|
451
|
-
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
452
|
-
);
|
|
548
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType}`
|
|
549
|
+
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
453
550
|
}
|
|
454
551
|
} else {
|
|
455
|
-
this.warnLog(
|
|
456
|
-
|
|
457
|
-
` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`,
|
|
458
|
-
);
|
|
552
|
+
this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName}`
|
|
553
|
+
+ ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
|
|
459
554
|
}
|
|
460
555
|
}
|
|
461
556
|
|
|
462
557
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
463
558
|
if (this.otherDeviceType === 'garagedoor') {
|
|
464
|
-
if (this.On === undefined) {
|
|
465
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
559
|
+
if (this.GarageDoor!.On === undefined) {
|
|
560
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.GarageDoor!.On}`);
|
|
466
561
|
} 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
|
-
);
|
|
562
|
+
if (this.GarageDoor!.On) {
|
|
563
|
+
this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.OPEN);
|
|
564
|
+
this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.OPEN);
|
|
565
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
566
|
+
+ ` TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor!.On})`);
|
|
479
567
|
} 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
|
-
);
|
|
568
|
+
this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.CLOSED);
|
|
569
|
+
this.GarageDoor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.CLOSED);
|
|
570
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
571
|
+
+ ` TargetDoorState: Closed, CurrentDoorState: Closed (${this.GarageDoor!.On})`);
|
|
491
572
|
}
|
|
492
573
|
}
|
|
493
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Garage Door On: ${this.On}`);
|
|
574
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Garage Door On: ${this.GarageDoor!.On}`);
|
|
494
575
|
} else if (this.otherDeviceType === 'door') {
|
|
495
|
-
if (this.On === undefined) {
|
|
496
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
576
|
+
if (this.Door!.On === undefined) {
|
|
577
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Door!.On}`);
|
|
497
578
|
} else {
|
|
498
|
-
if (this.On) {
|
|
499
|
-
this.
|
|
500
|
-
this.
|
|
501
|
-
this.
|
|
502
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic
|
|
579
|
+
if (this.Door!.On) {
|
|
580
|
+
this.Door!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
581
|
+
this.Door!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
582
|
+
this.Door!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
583
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
584
|
+
+ ` TargetPosition: 100, CurrentPosition: 100 (${this.Door!.On})`);
|
|
503
585
|
} else {
|
|
504
|
-
this.
|
|
505
|
-
this.
|
|
506
|
-
this.
|
|
507
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic
|
|
586
|
+
this.Door!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
587
|
+
this.Door!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
588
|
+
this.Door!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
589
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
590
|
+
+ ` TargetPosition: 0, CurrentPosition: 0 (${this.Door!.On})`);
|
|
508
591
|
}
|
|
509
592
|
}
|
|
510
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Door On: ${this.On}`);
|
|
593
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Door On: ${this.Door!.On}`);
|
|
511
594
|
} else if (this.otherDeviceType === 'window') {
|
|
512
|
-
if (this.On === undefined) {
|
|
513
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
595
|
+
if (this.Window!.On === undefined) {
|
|
596
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Window!.On}`);
|
|
514
597
|
} else {
|
|
515
|
-
if (this.On) {
|
|
516
|
-
this.
|
|
517
|
-
this.
|
|
518
|
-
this.
|
|
519
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic
|
|
598
|
+
if (this.Window!.On) {
|
|
599
|
+
this.Window!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
600
|
+
this.Window!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
601
|
+
this.Window!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
602
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
603
|
+
+ ` TargetPosition: 100, CurrentPosition: 100 (${this.Window!.On})`);
|
|
520
604
|
} else {
|
|
521
|
-
this.
|
|
522
|
-
this.
|
|
523
|
-
this.
|
|
524
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic
|
|
605
|
+
this.Window!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
606
|
+
this.Window!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
607
|
+
this.Window!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
608
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
609
|
+
+ ` TargetPosition: 0, CurrentPosition: 0 (${this.Window!.On})`);
|
|
525
610
|
}
|
|
526
611
|
}
|
|
527
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Window On: ${this.On}`);
|
|
612
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Window On: ${this.Window!.On}`);
|
|
528
613
|
} else if (this.otherDeviceType === 'windowcovering') {
|
|
529
|
-
if (this.On === undefined) {
|
|
530
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
614
|
+
if (this.WindowCovering!.On === undefined) {
|
|
615
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.WindowCovering!.On}`);
|
|
531
616
|
} 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`);
|
|
617
|
+
if (this.WindowCovering!.On) {
|
|
618
|
+
this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
|
|
619
|
+
this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
|
|
620
|
+
this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
621
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
622
|
+
+ ` TargetPosition: 100, CurrentPosition: 100 (${this.WindowCovering!.On})`);
|
|
540
623
|
} 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`);
|
|
624
|
+
this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
|
|
625
|
+
this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
|
|
626
|
+
this.WindowCovering!.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
|
|
627
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
628
|
+
+ ` TargetPosition: 0, CurrentPosition: 0 (${this.WindowCovering!.On})`);
|
|
548
629
|
}
|
|
549
630
|
}
|
|
550
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Window Covering On: ${this.On}`);
|
|
631
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Window Covering On: ${this.WindowCovering!.On}`);
|
|
551
632
|
} else if (this.otherDeviceType === 'lock') {
|
|
552
|
-
if (this.On === undefined) {
|
|
553
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
633
|
+
if (this.LockMechanism?.On === undefined) {
|
|
634
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.LockMechanism?.On}`);
|
|
554
635
|
} 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
|
-
);
|
|
636
|
+
if (this.LockMechanism.On) {
|
|
637
|
+
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState,
|
|
638
|
+
this.hap.Characteristic.LockTargetState.UNSECURED);
|
|
639
|
+
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState,
|
|
640
|
+
this.hap.Characteristic.LockCurrentState.UNSECURED);
|
|
641
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
642
|
+
+ ` LockTargetState: UNSECURED, LockCurrentState: UNSECURE (${this.LockMechanism.On})`);
|
|
568
643
|
} 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
|
-
);
|
|
644
|
+
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState,
|
|
645
|
+
this.hap.Characteristic.LockTargetState.SECURED);
|
|
646
|
+
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState,
|
|
647
|
+
this.hap.Characteristic.LockCurrentState.SECURED);
|
|
648
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
649
|
+
+ ` LockTargetState: SECURED, LockCurrentState: SECURED (${this.LockMechanism.On})`);
|
|
577
650
|
}
|
|
578
651
|
}
|
|
579
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Lock On: ${this.On}`);
|
|
652
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Lock On: ${this.LockMechanism?.On}`);
|
|
580
653
|
} else if (this.otherDeviceType === 'faucet') {
|
|
581
|
-
if (this.On === undefined) {
|
|
582
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
654
|
+
if (this.Faucet!.On === undefined) {
|
|
655
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Faucet!.On}`);
|
|
583
656
|
} else {
|
|
584
|
-
if (this.On) {
|
|
585
|
-
this.
|
|
586
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.On}`);
|
|
657
|
+
if (this.Faucet!.On) {
|
|
658
|
+
this.Faucet!.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE);
|
|
659
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Faucet!.On}`);
|
|
587
660
|
} else {
|
|
588
|
-
this.
|
|
589
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.On}`);
|
|
661
|
+
this.Faucet!.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
|
|
662
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Faucet!.On}`);
|
|
590
663
|
}
|
|
591
664
|
}
|
|
592
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Faucet On: ${this.On}`);
|
|
665
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Faucet On: ${this.Faucet!.On}`);
|
|
593
666
|
} else if (this.otherDeviceType === 'fan') {
|
|
594
|
-
if (this.On === undefined) {
|
|
595
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
667
|
+
if (this.Fan!.On === undefined) {
|
|
668
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Fan!.On}`);
|
|
596
669
|
} else {
|
|
597
|
-
if (this.On) {
|
|
598
|
-
this.
|
|
599
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
670
|
+
if (this.Fan!.On) {
|
|
671
|
+
this.Fan!.Service.updateCharacteristic(this.hap.Characteristic.On, this.Fan!.On);
|
|
672
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Fan!.On}`);
|
|
600
673
|
} else {
|
|
601
|
-
this.
|
|
602
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
674
|
+
this.Fan!.Service.updateCharacteristic(this.hap.Characteristic.On, this.Fan!.On);
|
|
675
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Fan!.On}`);
|
|
603
676
|
}
|
|
604
677
|
}
|
|
605
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Fan On: ${this.On}`);
|
|
678
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Fan On: ${this.Fan!.On}`);
|
|
606
679
|
} else if (this.otherDeviceType === 'stateful') {
|
|
607
|
-
if (this.On === undefined) {
|
|
608
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
680
|
+
if (this.StatefulProgrammableSwitch!.On === undefined) {
|
|
681
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.StatefulProgrammableSwitch!.On}`);
|
|
609
682
|
} 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
|
-
);
|
|
683
|
+
if (this.StatefulProgrammableSwitch!.On) {
|
|
684
|
+
this.StatefulProgrammableSwitch!.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent,
|
|
685
|
+
this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
|
|
686
|
+
this.StatefulProgrammableSwitch!.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 1);
|
|
687
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
688
|
+
+ ` ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 1 (${this.StatefulProgrammableSwitch!.On})`);
|
|
620
689
|
} 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
|
-
);
|
|
690
|
+
this.StatefulProgrammableSwitch!.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent,
|
|
691
|
+
this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
|
|
692
|
+
this.StatefulProgrammableSwitch!.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 0);
|
|
693
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
694
|
+
+ ` ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 0 (${this.StatefulProgrammableSwitch!.On})`);
|
|
630
695
|
}
|
|
631
696
|
}
|
|
632
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} StatefulProgrammableSwitch On: ${this.On}`);
|
|
697
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} StatefulProgrammableSwitch On: ${this.StatefulProgrammableSwitch!.On}`);
|
|
633
698
|
} else if (this.otherDeviceType === 'switch') {
|
|
634
|
-
if (this.On === undefined) {
|
|
635
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
699
|
+
if (this.Switch!.On === undefined) {
|
|
700
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Switch!.On}`);
|
|
636
701
|
} else {
|
|
637
|
-
this.
|
|
638
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
702
|
+
this.Switch!.Service.updateCharacteristic(this.hap.Characteristic.On, this.Switch!.On);
|
|
703
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Switch!.On}`);
|
|
639
704
|
}
|
|
640
705
|
} else {
|
|
641
|
-
if (this.On === undefined) {
|
|
642
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
706
|
+
if (this.Outlet!.On === undefined) {
|
|
707
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.Outlet!.On}`);
|
|
643
708
|
} else {
|
|
644
|
-
this.
|
|
645
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
709
|
+
this.Outlet!.Service.updateCharacteristic(this.hap.Characteristic.On, this.Outlet!.On);
|
|
710
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Outlet!.On}`);
|
|
646
711
|
}
|
|
647
712
|
}
|
|
648
713
|
}
|
|
649
714
|
|
|
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
715
|
async apiError(e: any): Promise<void> {
|
|
775
716
|
if (this.otherDeviceType === 'garagedoor') {
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
717
|
+
if (this.GarageDoor) {
|
|
718
|
+
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, e);
|
|
719
|
+
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, e);
|
|
720
|
+
this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.ObstructionDetected, e);
|
|
721
|
+
}
|
|
779
722
|
} else if (this.otherDeviceType === 'door') {
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
723
|
+
if (this.Door) {
|
|
724
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
|
|
725
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
|
|
726
|
+
this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e);
|
|
727
|
+
}
|
|
783
728
|
} else if (this.otherDeviceType === 'window') {
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
729
|
+
if (this.Window) {
|
|
730
|
+
this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
|
|
731
|
+
this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
|
|
732
|
+
this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e);
|
|
733
|
+
}
|
|
787
734
|
} else if (this.otherDeviceType === 'windowcovering') {
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
735
|
+
if (this.WindowCovering) {
|
|
736
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
|
|
737
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
|
|
738
|
+
this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e);
|
|
739
|
+
}
|
|
791
740
|
} else if (this.otherDeviceType === 'lock') {
|
|
792
|
-
|
|
793
|
-
|
|
741
|
+
if (this.LockMechanism) {
|
|
742
|
+
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, e);
|
|
743
|
+
this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, e);
|
|
744
|
+
}
|
|
794
745
|
} else if (this.otherDeviceType === 'faucet') {
|
|
795
|
-
|
|
746
|
+
if (this.Faucet) {
|
|
747
|
+
this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
|
|
748
|
+
}
|
|
796
749
|
} else if (this.otherDeviceType === 'fan') {
|
|
797
|
-
|
|
750
|
+
if (this.Fan) {
|
|
751
|
+
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
752
|
+
}
|
|
798
753
|
} else if (this.otherDeviceType === 'stateful') {
|
|
799
|
-
|
|
800
|
-
|
|
754
|
+
if (this.StatefulProgrammableSwitch) {
|
|
755
|
+
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e);
|
|
756
|
+
this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e);
|
|
757
|
+
}
|
|
801
758
|
} else if (this.otherDeviceType === 'switch') {
|
|
802
|
-
|
|
759
|
+
if (this.Switch) {
|
|
760
|
+
this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
761
|
+
}
|
|
803
762
|
} else {
|
|
804
|
-
|
|
763
|
+
if (this.Outlet) {
|
|
764
|
+
this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
765
|
+
}
|
|
805
766
|
}
|
|
806
767
|
}
|
|
807
768
|
|
|
808
769
|
async removeOutletService(accessory: PlatformAccessory): Promise<void> {
|
|
809
|
-
// If
|
|
810
|
-
|
|
811
|
-
|
|
770
|
+
// If Outlet.Service still present, then remove first
|
|
771
|
+
if (this.Outlet?.Service) {
|
|
772
|
+
this.Outlet.Service = this.accessory.getService(this.hap.Service.Outlet) as Service;
|
|
812
773
|
this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Outlet Service`);
|
|
774
|
+
accessory.removeService(this.Outlet.Service);
|
|
813
775
|
}
|
|
814
|
-
accessory.removeService(this.outletService!);
|
|
815
776
|
}
|
|
816
777
|
|
|
817
778
|
async removeGarageDoorService(accessory: PlatformAccessory): Promise<void> {
|
|
818
|
-
// If
|
|
819
|
-
|
|
820
|
-
|
|
779
|
+
// If GarageDoor.Service still present, then remove first
|
|
780
|
+
if (this.GarageDoor?.Service) {
|
|
781
|
+
this.GarageDoor.Service = this.accessory.getService(this.hap.Service.GarageDoorOpener) as Service;
|
|
821
782
|
this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Garage Door Service`);
|
|
783
|
+
accessory.removeService(this.GarageDoor.Service);
|
|
822
784
|
}
|
|
823
|
-
accessory.removeService(this.garageDoorService!);
|
|
824
785
|
}
|
|
825
786
|
|
|
826
787
|
async removeDoorService(accessory: PlatformAccessory): Promise<void> {
|
|
827
|
-
// If
|
|
828
|
-
|
|
829
|
-
|
|
788
|
+
// If Door.Service still present, then remove first
|
|
789
|
+
if (this.Door?.Service) {
|
|
790
|
+
this.Door.Service = this.accessory.getService(this.hap.Service.Door) as Service;
|
|
830
791
|
this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Door Service`);
|
|
792
|
+
accessory.removeService(this.Door.Service);
|
|
831
793
|
}
|
|
832
|
-
accessory.removeService(this.doorService!);
|
|
833
794
|
}
|
|
834
795
|
|
|
835
796
|
async removeLockService(accessory: PlatformAccessory): Promise<void> {
|
|
836
|
-
// If
|
|
837
|
-
|
|
838
|
-
|
|
797
|
+
// If Lock.Service still present, then remove first
|
|
798
|
+
if (this.LockMechanism?.Service) {
|
|
799
|
+
this.LockMechanism.Service = this.accessory.getService(this.hap.Service.LockMechanism) as Service;
|
|
839
800
|
this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Lock Service`);
|
|
801
|
+
accessory.removeService(this.LockMechanism.Service);
|
|
840
802
|
}
|
|
841
|
-
accessory.removeService(this.lockService!);
|
|
842
803
|
}
|
|
843
804
|
|
|
844
805
|
async removeFaucetService(accessory: PlatformAccessory): Promise<void> {
|
|
845
|
-
// If
|
|
846
|
-
|
|
847
|
-
|
|
806
|
+
// If Faucet.Service still present, then remove first
|
|
807
|
+
if (this.Faucet?.Service) {
|
|
808
|
+
this.Faucet.Service = this.accessory.getService(this.hap.Service.Faucet) as Service;
|
|
848
809
|
this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Faucet Service`);
|
|
810
|
+
accessory.removeService(this.Faucet.Service);
|
|
849
811
|
}
|
|
850
|
-
accessory.removeService(this.faucetService!);
|
|
851
812
|
}
|
|
852
813
|
|
|
853
814
|
async removeFanService(accessory: PlatformAccessory): Promise<void> {
|
|
854
|
-
// If
|
|
855
|
-
|
|
856
|
-
|
|
815
|
+
// If Fan Service still present, then remove first
|
|
816
|
+
if (this.Fan?.Service) {
|
|
817
|
+
this.Fan.Service = this.accessory.getService(this.hap.Service.Fan) as Service;
|
|
857
818
|
this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Fan Service`);
|
|
819
|
+
accessory.removeService(this.Fan.Service);
|
|
858
820
|
}
|
|
859
|
-
accessory.removeService(this.fanService!);
|
|
860
821
|
}
|
|
861
822
|
|
|
862
823
|
async removeWindowService(accessory: PlatformAccessory): Promise<void> {
|
|
863
|
-
// If
|
|
864
|
-
|
|
865
|
-
|
|
824
|
+
// If Window.Service still present, then remove first
|
|
825
|
+
if (this.Window?.Service) {
|
|
826
|
+
this.Window.Service = this.accessory.getService(this.hap.Service.Window) as Service;
|
|
866
827
|
this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Window Service`);
|
|
828
|
+
accessory.removeService(this.Window.Service);
|
|
867
829
|
}
|
|
868
|
-
accessory.removeService(this.windowService!);
|
|
869
830
|
}
|
|
870
831
|
|
|
871
832
|
async removeWindowCoveringService(accessory: PlatformAccessory): Promise<void> {
|
|
872
|
-
// If
|
|
873
|
-
|
|
874
|
-
|
|
833
|
+
// If WindowCovering.Service still present, then remove first
|
|
834
|
+
if (this.WindowCovering?.Service) {
|
|
835
|
+
this.WindowCovering.Service = this.accessory.getService(this.hap.Service.WindowCovering) as Service;
|
|
875
836
|
this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Window Covering Service`);
|
|
837
|
+
accessory.removeService(this.WindowCovering.Service);
|
|
876
838
|
}
|
|
877
|
-
accessory.removeService(this.windowCoveringService!);
|
|
878
839
|
}
|
|
879
840
|
|
|
880
841
|
async removeStatefulProgrammableSwitchService(accessory: PlatformAccessory): Promise<void> {
|
|
881
|
-
// If
|
|
882
|
-
|
|
883
|
-
|
|
842
|
+
// If StatefulProgrammableSwitch.Service still present, then remove first
|
|
843
|
+
if (this.StatefulProgrammableSwitch?.Service) {
|
|
844
|
+
this.StatefulProgrammableSwitch.Service = this.accessory.getService(this.hap.Service.StatefulProgrammableSwitch) as Service;
|
|
884
845
|
this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Stateful Programmable Switch Service`);
|
|
846
|
+
accessory.removeService(this.StatefulProgrammableSwitch.Service);
|
|
885
847
|
}
|
|
886
|
-
accessory.removeService(this.statefulProgrammableSwitchService!);
|
|
887
848
|
}
|
|
888
849
|
|
|
889
850
|
async removeSwitchService(accessory: PlatformAccessory): Promise<void> {
|
|
890
|
-
// If
|
|
891
|
-
|
|
892
|
-
|
|
851
|
+
// If Switch.Service still present, then remove first
|
|
852
|
+
if (this.Switch?.Service) {
|
|
853
|
+
this.Switch.Service = this.accessory.getService(this.hap.Service.Switch) as Service;
|
|
893
854
|
this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Switch Service`);
|
|
855
|
+
accessory.removeService(this.Switch.Service);
|
|
894
856
|
}
|
|
895
|
-
accessory.removeService(this.switchService!);
|
|
896
857
|
}
|
|
897
858
|
|
|
898
|
-
async
|
|
859
|
+
async getOtherConfigSettings(device: irdevice & irDevicesConfig): Promise<void> {
|
|
899
860
|
if (!device.other?.deviceType && this.accessory.context.deviceType) {
|
|
900
861
|
this.otherDeviceType = this.accessory.context.deviceType;
|
|
901
862
|
this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Type: ${this.otherDeviceType}, from Accessory Cache.`);
|
|
@@ -909,117 +870,4 @@ export class Others {
|
|
|
909
870
|
this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} no deviceType set, using default deviceType: ${this.otherDeviceType}`);
|
|
910
871
|
}
|
|
911
872
|
}
|
|
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
873
|
}
|