@switchbot/homebridge-switchbot 2.14.0 → 3.0.0-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/.github/npm-version-script.cjs +81 -0
- package/.github/workflows/dependabot.yml +10 -11
- package/CHANGELOG.md +11 -2
- package/LICENSE +1 -1
- package/config.schema.json +1 -0
- package/dist/device/blindtilt.d.ts +9 -5
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +151 -91
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +9 -5
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +234 -184
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +9 -5
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +110 -64
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +9 -5
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +121 -69
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +9 -5
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +111 -66
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +9 -5
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +164 -107
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +9 -5
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +87 -51
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +9 -5
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +133 -90
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +9 -5
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +108 -66
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +9 -5
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +110 -65
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +10 -6
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +125 -84
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +9 -5
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +102 -63
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +9 -5
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +102 -63
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +9 -5
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +95 -54
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -5
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +68 -40
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +9 -5
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +86 -52
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/homebridge-ui/server.d.ts +2 -0
- package/dist/homebridge-ui/server.d.ts.map +1 -0
- package/dist/homebridge-ui/server.js +44 -0
- package/dist/homebridge-ui/server.js.map +1 -0
- package/dist/index.d.ts +1 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -5
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +8 -4
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +105 -71
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +8 -4
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +78 -46
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +8 -4
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +41 -25
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +8 -4
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +62 -39
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +8 -4
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +67 -45
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +8 -4
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +176 -150
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +8 -4
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +81 -62
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +8 -4
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +41 -25
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +8 -4
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +48 -32
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +8 -9
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +147 -162
- package/dist/platform.js.map +1 -1
- package/dist/settings.js +7 -14
- package/dist/settings.js.map +1 -1
- package/dist/utils.js +1 -5
- package/dist/utils.js.map +1 -1
- package/package.json +28 -16
- package/src/device/blindtilt.ts +80 -69
- package/src/device/bot.ts +189 -178
- package/src/device/ceilinglight.ts +55 -42
- package/src/device/colorbulb.ts +51 -38
- package/src/device/contact.ts +69 -58
- package/src/device/curtain.ts +94 -83
- package/src/device/hub.ts +54 -43
- package/src/device/humidifier.ts +86 -75
- package/src/device/iosensor.ts +63 -52
- package/src/device/lightstrip.ts +54 -41
- package/src/device/lock.ts +89 -79
- package/src/device/meter.ts +59 -48
- package/src/device/meterplus.ts +63 -52
- package/src/device/motion.ts +56 -45
- package/src/device/plug.ts +36 -25
- package/src/device/robotvacuumcleaner.ts +47 -36
- package/src/homebridge-ui/public/index.html +240 -0
- package/src/homebridge-ui/server.ts +48 -0
- package/src/index.ts +10 -7
- package/src/irdevice/airconditioner.ts +70 -62
- package/src/irdevice/airpurifier.ts +47 -39
- package/src/irdevice/camera.ts +27 -19
- package/src/irdevice/fan.ts +41 -33
- package/src/irdevice/light.ts +47 -39
- package/src/irdevice/other.ts +163 -155
- package/src/irdevice/tv.ts +65 -57
- package/src/irdevice/vacuumcleaner.ts +27 -19
- package/src/irdevice/waterheater.ts +34 -26
- package/src/platform.ts +35 -21
- package/tsconfig.json +11 -13
- package/homebridge-ui/server.js +0 -50
- /package/{homebridge-ui → dist/homebridge-ui}/public/index.html +0 -0
package/src/irdevice/camera.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
1
|
+
import { CharacteristicValue, PlatformAccessory, Service, API, Logging, HAP } from 'homebridge';
|
|
2
2
|
import { request } from 'undici';
|
|
3
3
|
import { SwitchBotPlatform } from '../platform';
|
|
4
|
-
import { Devices, irDevicesConfig, irdevice } from '../settings';
|
|
4
|
+
import { Devices, irDevicesConfig, irdevice, SwitchBotPlatformConfig } from '../settings';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Platform Accessory
|
|
@@ -9,6 +9,10 @@ import { Devices, irDevicesConfig, irdevice } from '../settings';
|
|
|
9
9
|
* Each accessory may expose multiple services of different service types.
|
|
10
10
|
*/
|
|
11
11
|
export class Camera {
|
|
12
|
+
public readonly api: API;
|
|
13
|
+
public readonly log: Logging;
|
|
14
|
+
public readonly config!: SwitchBotPlatformConfig;
|
|
15
|
+
protected readonly hap: HAP;
|
|
12
16
|
// Services
|
|
13
17
|
switchService!: Service;
|
|
14
18
|
|
|
@@ -26,34 +30,38 @@ export class Camera {
|
|
|
26
30
|
private accessory: PlatformAccessory,
|
|
27
31
|
public device: irdevice & irDevicesConfig,
|
|
28
32
|
) {
|
|
33
|
+
this.api = this.platform.api;
|
|
34
|
+
this.log = this.platform.log;
|
|
35
|
+
this.config = this.platform.config;
|
|
36
|
+
this.hap = this.api.hap;
|
|
29
37
|
// default placeholders
|
|
30
|
-
this.
|
|
38
|
+
this.deviceLogs(device);
|
|
31
39
|
this.context();
|
|
32
40
|
this.disablePushOnChanges(device);
|
|
33
41
|
this.disablePushOffChanges(device);
|
|
34
|
-
this.
|
|
42
|
+
this.deviceConfig(device);
|
|
35
43
|
|
|
36
44
|
// set accessory information
|
|
37
45
|
accessory
|
|
38
|
-
.getService(this.
|
|
39
|
-
.setCharacteristic(this.
|
|
40
|
-
.setCharacteristic(this.
|
|
41
|
-
.setCharacteristic(this.
|
|
42
|
-
.setCharacteristic(this.
|
|
46
|
+
.getService(this.hap.Service.AccessoryInformation)!
|
|
47
|
+
.setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
|
|
48
|
+
.setCharacteristic(this.hap.Characteristic.Model, device.remoteType)
|
|
49
|
+
.setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
|
|
50
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
|
|
43
51
|
|
|
44
52
|
// get the Television service if it exists, otherwise create a new Television service
|
|
45
53
|
// you can create multiple services for each accessory
|
|
46
54
|
const switchService = `${accessory.displayName} Camera`;
|
|
47
|
-
(this.switchService = accessory.getService(this.
|
|
48
|
-
|| accessory.addService(this.
|
|
55
|
+
(this.switchService = accessory.getService(this.hap.Service.Switch)
|
|
56
|
+
|| accessory.addService(this.hap.Service.Switch)), switchService;
|
|
49
57
|
|
|
50
|
-
this.switchService.setCharacteristic(this.
|
|
51
|
-
if (!this.switchService.testCharacteristic(this.
|
|
52
|
-
this.switchService.addCharacteristic(this.
|
|
58
|
+
this.switchService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
59
|
+
if (!this.switchService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
60
|
+
this.switchService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
53
61
|
}
|
|
54
62
|
|
|
55
63
|
// handle on / off events using the On characteristic
|
|
56
|
-
this.switchService.getCharacteristic(this.
|
|
64
|
+
this.switchService.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
57
65
|
}
|
|
58
66
|
|
|
59
67
|
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
@@ -153,7 +161,7 @@ export class Camera {
|
|
|
153
161
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
154
162
|
} else {
|
|
155
163
|
this.accessory.context.On = this.On;
|
|
156
|
-
this.switchService?.updateCharacteristic(this.
|
|
164
|
+
this.switchService?.updateCharacteristic(this.hap.Characteristic.On, this.On);
|
|
157
165
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
158
166
|
}
|
|
159
167
|
}
|
|
@@ -245,7 +253,7 @@ export class Camera {
|
|
|
245
253
|
}
|
|
246
254
|
|
|
247
255
|
async apiError(e: any): Promise<void> {
|
|
248
|
-
this.switchService.updateCharacteristic(this.
|
|
256
|
+
this.switchService.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
249
257
|
}
|
|
250
258
|
|
|
251
259
|
async context() {
|
|
@@ -260,7 +268,7 @@ export class Camera {
|
|
|
260
268
|
}
|
|
261
269
|
}
|
|
262
270
|
|
|
263
|
-
async
|
|
271
|
+
async deviceConfig(device: irdevice & irDevicesConfig): Promise<void> {
|
|
264
272
|
let config = {};
|
|
265
273
|
if (device.ircam) {
|
|
266
274
|
config = device.ircam;
|
|
@@ -294,7 +302,7 @@ export class Camera {
|
|
|
294
302
|
}
|
|
295
303
|
}
|
|
296
304
|
|
|
297
|
-
async
|
|
305
|
+
async deviceLogs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
298
306
|
if (this.platform.debugMode) {
|
|
299
307
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
300
308
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
package/src/irdevice/fan.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
1
|
+
import { CharacteristicValue, PlatformAccessory, Service, API, Logging, HAP } from 'homebridge';
|
|
2
2
|
import { request } from 'undici';
|
|
3
3
|
import { SwitchBotPlatform } from '../platform';
|
|
4
|
-
import { Devices, irDevicesConfig, irdevice } from '../settings';
|
|
4
|
+
import { Devices, irDevicesConfig, irdevice, SwitchBotPlatformConfig } from '../settings';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Platform Accessory
|
|
@@ -9,6 +9,10 @@ import { Devices, irDevicesConfig, irdevice } from '../settings';
|
|
|
9
9
|
* Each accessory may expose multiple services of different service types.
|
|
10
10
|
*/
|
|
11
11
|
export class Fan {
|
|
12
|
+
public readonly api: API;
|
|
13
|
+
public readonly log: Logging;
|
|
14
|
+
public readonly config!: SwitchBotPlatformConfig;
|
|
15
|
+
protected readonly hap: HAP;
|
|
12
16
|
// Services
|
|
13
17
|
fanService!: Service;
|
|
14
18
|
|
|
@@ -33,34 +37,38 @@ export class Fan {
|
|
|
33
37
|
private accessory: PlatformAccessory,
|
|
34
38
|
public device: irdevice & irDevicesConfig,
|
|
35
39
|
) {
|
|
40
|
+
this.api = this.platform.api;
|
|
41
|
+
this.log = this.platform.log;
|
|
42
|
+
this.config = this.platform.config;
|
|
43
|
+
this.hap = this.api.hap;
|
|
36
44
|
// default placeholders
|
|
37
|
-
this.
|
|
45
|
+
this.deviceLogs(device);
|
|
38
46
|
this.context();
|
|
39
47
|
this.disablePushOnChanges(device);
|
|
40
48
|
this.disablePushOffChanges(device);
|
|
41
|
-
this.
|
|
49
|
+
this.deviceConfig(device);
|
|
42
50
|
|
|
43
51
|
// set accessory information
|
|
44
52
|
accessory
|
|
45
|
-
.getService(this.
|
|
46
|
-
.setCharacteristic(this.
|
|
47
|
-
.setCharacteristic(this.
|
|
48
|
-
.setCharacteristic(this.
|
|
49
|
-
.setCharacteristic(this.
|
|
53
|
+
.getService(this.hap.Service.AccessoryInformation)!
|
|
54
|
+
.setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
|
|
55
|
+
.setCharacteristic(this.hap.Characteristic.Model, device.remoteType)
|
|
56
|
+
.setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
|
|
57
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
|
|
50
58
|
|
|
51
59
|
// get the Television service if it exists, otherwise create a new Television service
|
|
52
60
|
// you can create multiple services for each accessory
|
|
53
61
|
const fanService = `${accessory.displayName} Fan`;
|
|
54
|
-
(this.fanService = accessory.getService(this.
|
|
55
|
-
|| accessory.addService(this.
|
|
62
|
+
(this.fanService = accessory.getService(this.hap.Service.Fanv2)
|
|
63
|
+
|| accessory.addService(this.hap.Service.Fanv2)), fanService;
|
|
56
64
|
|
|
57
|
-
this.fanService.setCharacteristic(this.
|
|
58
|
-
if (!this.fanService.testCharacteristic(this.
|
|
59
|
-
this.fanService.addCharacteristic(this.
|
|
65
|
+
this.fanService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
66
|
+
if (!this.fanService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
67
|
+
this.fanService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
60
68
|
}
|
|
61
69
|
|
|
62
70
|
// handle on / off events using the Active characteristic
|
|
63
|
-
this.fanService.getCharacteristic(this.
|
|
71
|
+
this.fanService.getCharacteristic(this.hap.Characteristic.Active).onSet(this.ActiveSet.bind(this));
|
|
64
72
|
|
|
65
73
|
if (device.irfan?.rotation_speed) {
|
|
66
74
|
if (device.irfan?.set_minStep) {
|
|
@@ -80,15 +88,15 @@ export class Fan {
|
|
|
80
88
|
}
|
|
81
89
|
// handle Roation Speed events using the RotationSpeed characteristic
|
|
82
90
|
this.fanService
|
|
83
|
-
.getCharacteristic(this.
|
|
91
|
+
.getCharacteristic(this.hap.Characteristic.RotationSpeed)
|
|
84
92
|
.setProps({
|
|
85
93
|
minStep: this.minStep,
|
|
86
94
|
minValue: this.minValue,
|
|
87
95
|
maxValue: this.maxValue,
|
|
88
96
|
})
|
|
89
97
|
.onSet(this.RotationSpeedSet.bind(this));
|
|
90
|
-
} else if (this.fanService.testCharacteristic(this.
|
|
91
|
-
const characteristic = this.fanService.getCharacteristic(this.
|
|
98
|
+
} else if (this.fanService.testCharacteristic(this.hap.Characteristic.RotationSpeed) && !device.irfan?.swing_mode) {
|
|
99
|
+
const characteristic = this.fanService.getCharacteristic(this.hap.Characteristic.RotationSpeed);
|
|
92
100
|
this.fanService.removeCharacteristic(characteristic);
|
|
93
101
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Rotation Speed Characteristic was removed.`);
|
|
94
102
|
} else {
|
|
@@ -101,9 +109,9 @@ export class Fan {
|
|
|
101
109
|
|
|
102
110
|
if (device.irfan?.swing_mode) {
|
|
103
111
|
// handle Osolcation events using the SwingMode characteristic
|
|
104
|
-
this.fanService.getCharacteristic(this.
|
|
105
|
-
} else if (this.fanService.testCharacteristic(this.
|
|
106
|
-
const characteristic = this.fanService.getCharacteristic(this.
|
|
112
|
+
this.fanService.getCharacteristic(this.hap.Characteristic.SwingMode).onSet(this.SwingModeSet.bind(this));
|
|
113
|
+
} else if (this.fanService.testCharacteristic(this.hap.Characteristic.SwingMode) && !device.irfan?.swing_mode) {
|
|
114
|
+
const characteristic = this.fanService.getCharacteristic(this.hap.Characteristic.SwingMode);
|
|
107
115
|
this.fanService.removeCharacteristic(characteristic);
|
|
108
116
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Swing Mode Characteristic was removed.`);
|
|
109
117
|
} else {
|
|
@@ -148,7 +156,7 @@ export class Fan {
|
|
|
148
156
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${value}`);
|
|
149
157
|
|
|
150
158
|
this.Active = value;
|
|
151
|
-
if (this.Active === this.
|
|
159
|
+
if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
152
160
|
this.pushFanOnChanges();
|
|
153
161
|
} else {
|
|
154
162
|
this.pushFanOffChanges();
|
|
@@ -168,7 +176,7 @@ export class Fan {
|
|
|
168
176
|
this.debugLog(
|
|
169
177
|
`${this.device.remoteType}: ${this.accessory.displayName} pushFanOnChanges Active: ${this.Active},` + ` disablePushOn: ${this.disablePushOn}`,
|
|
170
178
|
);
|
|
171
|
-
if (this.Active === this.
|
|
179
|
+
if (this.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
|
|
172
180
|
const commandType: string = await this.commandType();
|
|
173
181
|
const command: string = await this.commandOn();
|
|
174
182
|
const bodyChange = JSON.stringify({
|
|
@@ -185,7 +193,7 @@ export class Fan {
|
|
|
185
193
|
`${this.device.remoteType}: ${this.accessory.displayName} pushLightOffChanges Active: ${this.Active},` +
|
|
186
194
|
` disablePushOff: ${this.disablePushOff}`,
|
|
187
195
|
);
|
|
188
|
-
if (this.Active === this.
|
|
196
|
+
if (this.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOff) {
|
|
189
197
|
const commandType: string = await this.commandType();
|
|
190
198
|
const command: string = await this.commandOff();
|
|
191
199
|
const bodyChange = JSON.stringify({
|
|
@@ -269,21 +277,21 @@ export class Fan {
|
|
|
269
277
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
270
278
|
} else {
|
|
271
279
|
this.accessory.context.Active = this.Active;
|
|
272
|
-
this.fanService?.updateCharacteristic(this.
|
|
280
|
+
this.fanService?.updateCharacteristic(this.hap.Characteristic.Active, this.Active);
|
|
273
281
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
274
282
|
}
|
|
275
283
|
if (this.SwingMode === undefined) {
|
|
276
284
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} SwingMode: ${this.SwingMode}`);
|
|
277
285
|
} else {
|
|
278
286
|
this.accessory.context.SwingMode = this.SwingMode;
|
|
279
|
-
this.fanService?.updateCharacteristic(this.
|
|
287
|
+
this.fanService?.updateCharacteristic(this.hap.Characteristic.SwingMode, this.SwingMode);
|
|
280
288
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic SwingMode: ${this.SwingMode}`);
|
|
281
289
|
}
|
|
282
290
|
if (this.RotationSpeed === undefined) {
|
|
283
291
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
|
|
284
292
|
} else {
|
|
285
293
|
this.accessory.context.RotationSpeed = this.RotationSpeed;
|
|
286
|
-
this.fanService?.updateCharacteristic(this.
|
|
294
|
+
this.fanService?.updateCharacteristic(this.hap.Characteristic.RotationSpeed, this.RotationSpeed);
|
|
287
295
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
|
|
288
296
|
}
|
|
289
297
|
}
|
|
@@ -375,14 +383,14 @@ export class Fan {
|
|
|
375
383
|
}
|
|
376
384
|
|
|
377
385
|
async apiError(e: any): Promise<void> {
|
|
378
|
-
this.fanService.updateCharacteristic(this.
|
|
379
|
-
this.fanService.updateCharacteristic(this.
|
|
380
|
-
this.fanService.updateCharacteristic(this.
|
|
386
|
+
this.fanService.updateCharacteristic(this.hap.Characteristic.Active, e);
|
|
387
|
+
this.fanService.updateCharacteristic(this.hap.Characteristic.RotationSpeed, e);
|
|
388
|
+
this.fanService.updateCharacteristic(this.hap.Characteristic.SwingMode, e);
|
|
381
389
|
}
|
|
382
390
|
|
|
383
391
|
async context() {
|
|
384
392
|
if (this.Active === undefined) {
|
|
385
|
-
this.Active = this.
|
|
393
|
+
this.Active = this.hap.Characteristic.Active.INACTIVE;
|
|
386
394
|
} else {
|
|
387
395
|
this.Active = this.accessory.context.Active;
|
|
388
396
|
}
|
|
@@ -392,7 +400,7 @@ export class Fan {
|
|
|
392
400
|
}
|
|
393
401
|
}
|
|
394
402
|
|
|
395
|
-
async
|
|
403
|
+
async deviceConfig(device: irdevice & irDevicesConfig): Promise<void> {
|
|
396
404
|
let config = {};
|
|
397
405
|
if (device.irfan) {
|
|
398
406
|
config = device.irfan;
|
|
@@ -426,7 +434,7 @@ export class Fan {
|
|
|
426
434
|
}
|
|
427
435
|
}
|
|
428
436
|
|
|
429
|
-
async
|
|
437
|
+
async deviceLogs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
430
438
|
if (this.platform.debugMode) {
|
|
431
439
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
432
440
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
package/src/irdevice/light.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
1
|
+
import { CharacteristicValue, PlatformAccessory, Service, API, Logging, HAP } from 'homebridge';
|
|
2
2
|
import { request } from 'undici';
|
|
3
3
|
import { SwitchBotPlatform } from '../platform';
|
|
4
|
-
import { Devices, irDevicesConfig, irdevice } from '../settings';
|
|
4
|
+
import { Devices, irDevicesConfig, irdevice, SwitchBotPlatformConfig } from '../settings';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Platform Accessory
|
|
@@ -9,6 +9,10 @@ import { Devices, irDevicesConfig, irdevice } from '../settings';
|
|
|
9
9
|
* Each accessory may expose multiple services of different service types.
|
|
10
10
|
*/
|
|
11
11
|
export class Light {
|
|
12
|
+
public readonly api: API;
|
|
13
|
+
public readonly log: Logging;
|
|
14
|
+
public readonly config!: SwitchBotPlatformConfig;
|
|
15
|
+
protected readonly hap: HAP;
|
|
12
16
|
// Services
|
|
13
17
|
lightBulbService?: Service;
|
|
14
18
|
ProgrammableSwitchServiceOn?: Service;
|
|
@@ -32,50 +36,54 @@ export class Light {
|
|
|
32
36
|
private accessory: PlatformAccessory,
|
|
33
37
|
public device: irdevice & irDevicesConfig,
|
|
34
38
|
) {
|
|
39
|
+
this.api = this.platform.api;
|
|
40
|
+
this.log = this.platform.log;
|
|
41
|
+
this.config = this.platform.config;
|
|
42
|
+
this.hap = this.api.hap;
|
|
35
43
|
// default placeholders
|
|
36
|
-
this.
|
|
44
|
+
this.deviceLogs(device);
|
|
37
45
|
this.context();
|
|
38
46
|
this.disablePushOnChanges(device);
|
|
39
47
|
this.disablePushOffChanges(device);
|
|
40
|
-
this.
|
|
48
|
+
this.deviceConfig(device);
|
|
41
49
|
|
|
42
50
|
// set accessory information
|
|
43
51
|
accessory
|
|
44
|
-
.getService(this.
|
|
45
|
-
.setCharacteristic(this.
|
|
46
|
-
.setCharacteristic(this.
|
|
47
|
-
.setCharacteristic(this.
|
|
48
|
-
.setCharacteristic(this.
|
|
52
|
+
.getService(this.hap.Service.AccessoryInformation)!
|
|
53
|
+
.setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
|
|
54
|
+
.setCharacteristic(this.hap.Characteristic.Model, device.remoteType)
|
|
55
|
+
.setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
|
|
56
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
|
|
49
57
|
|
|
50
58
|
if (!device.irlight?.stateless) {
|
|
51
59
|
// get the Light service if it exists, otherwise create a new Light service
|
|
52
60
|
// you can create multiple services for each accessory
|
|
53
61
|
const lightBulbService = `${accessory.displayName} ${device.remoteType}`;
|
|
54
|
-
(this.lightBulbService = accessory.getService(this.
|
|
55
|
-
|| accessory.addService(this.
|
|
62
|
+
(this.lightBulbService = accessory.getService(this.hap.Service.Lightbulb)
|
|
63
|
+
|| accessory.addService(this.hap.Service.Lightbulb)), lightBulbService;
|
|
56
64
|
|
|
57
65
|
|
|
58
|
-
this.lightBulbService.setCharacteristic(this.
|
|
59
|
-
if (!this.lightBulbService.testCharacteristic(this.
|
|
60
|
-
this.lightBulbService.addCharacteristic(this.
|
|
66
|
+
this.lightBulbService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
67
|
+
if (!this.lightBulbService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
68
|
+
this.lightBulbService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
61
69
|
}
|
|
62
70
|
|
|
63
71
|
// handle on / off events using the On characteristic
|
|
64
|
-
this.lightBulbService.getCharacteristic(this.
|
|
72
|
+
this.lightBulbService.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
65
73
|
} else {
|
|
66
74
|
|
|
67
75
|
// create a new Stateful Programmable Switch On service
|
|
68
76
|
const ProgrammableSwitchServiceOn = `${accessory.displayName} ${device.remoteType} On`;
|
|
69
|
-
(this.ProgrammableSwitchServiceOn = accessory.getService(this.
|
|
70
|
-
|| accessory.addService(this.
|
|
77
|
+
(this.ProgrammableSwitchServiceOn = accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
|
|
78
|
+
|| accessory.addService(this.hap.Service.StatefulProgrammableSwitch)), ProgrammableSwitchServiceOn;
|
|
71
79
|
|
|
72
80
|
|
|
73
|
-
this.ProgrammableSwitchServiceOn.setCharacteristic(this.
|
|
74
|
-
if (!this.ProgrammableSwitchServiceOn.testCharacteristic(this.
|
|
75
|
-
this.ProgrammableSwitchServiceOn.addCharacteristic(this.
|
|
81
|
+
this.ProgrammableSwitchServiceOn.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} On`);
|
|
82
|
+
if (!this.ProgrammableSwitchServiceOn.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
83
|
+
this.ProgrammableSwitchServiceOn.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} On`);
|
|
76
84
|
}
|
|
77
85
|
|
|
78
|
-
this.ProgrammableSwitchServiceOn.getCharacteristic(this.
|
|
86
|
+
this.ProgrammableSwitchServiceOn.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent).setProps({
|
|
79
87
|
validValueRanges: [0, 0],
|
|
80
88
|
minValue: 0,
|
|
81
89
|
maxValue: 0,
|
|
@@ -85,23 +93,23 @@ export class Light {
|
|
|
85
93
|
return this.ProgrammableSwitchEventOn!;
|
|
86
94
|
});
|
|
87
95
|
|
|
88
|
-
this.ProgrammableSwitchServiceOn.getCharacteristic(this.
|
|
96
|
+
this.ProgrammableSwitchServiceOn.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
|
|
89
97
|
.onSet(this.ProgrammableSwitchOutputStateSetOn.bind(this));
|
|
90
98
|
|
|
91
99
|
|
|
92
100
|
|
|
93
101
|
// create a new Stateful Programmable Switch Off service
|
|
94
102
|
const ProgrammableSwitchServiceOff = `${accessory.displayName} ${device.remoteType} Off`;
|
|
95
|
-
(this.ProgrammableSwitchServiceOff = accessory.getService(this.
|
|
96
|
-
|| accessory.addService(this.
|
|
103
|
+
(this.ProgrammableSwitchServiceOff = accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
|
|
104
|
+
|| accessory.addService(this.hap.Service.StatefulProgrammableSwitch)), ProgrammableSwitchServiceOff;
|
|
97
105
|
|
|
98
106
|
|
|
99
|
-
this.ProgrammableSwitchServiceOff.setCharacteristic(this.
|
|
100
|
-
if (!this.ProgrammableSwitchServiceOff.testCharacteristic(this.
|
|
101
|
-
this.ProgrammableSwitchServiceOff.addCharacteristic(this.
|
|
107
|
+
this.ProgrammableSwitchServiceOff.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Off`);
|
|
108
|
+
if (!this.ProgrammableSwitchServiceOff.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
109
|
+
this.ProgrammableSwitchServiceOff.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Off`);
|
|
102
110
|
}
|
|
103
111
|
|
|
104
|
-
this.ProgrammableSwitchServiceOff.getCharacteristic(this.
|
|
112
|
+
this.ProgrammableSwitchServiceOff.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent).setProps({
|
|
105
113
|
validValueRanges: [0, 0],
|
|
106
114
|
minValue: 0,
|
|
107
115
|
maxValue: 0,
|
|
@@ -111,7 +119,7 @@ export class Light {
|
|
|
111
119
|
return this.ProgrammableSwitchEventOff!;
|
|
112
120
|
});
|
|
113
121
|
|
|
114
|
-
this.ProgrammableSwitchServiceOff.getCharacteristic(this.
|
|
122
|
+
this.ProgrammableSwitchServiceOff.getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
|
|
115
123
|
.onSet(this.ProgrammableSwitchOutputStateSetOff.bind(this));
|
|
116
124
|
}
|
|
117
125
|
|
|
@@ -270,7 +278,7 @@ export class Light {
|
|
|
270
278
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
271
279
|
} else {
|
|
272
280
|
this.accessory.context.On = this.On;
|
|
273
|
-
this.lightBulbService?.updateCharacteristic(this.
|
|
281
|
+
this.lightBulbService?.updateCharacteristic(this.hap.Characteristic.On, this.On);
|
|
274
282
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
275
283
|
}
|
|
276
284
|
} else {
|
|
@@ -280,7 +288,7 @@ export class Light {
|
|
|
280
288
|
+ ` ProgrammableSwitchOutputStateOn: ${this.ProgrammableSwitchOutputStateOn}`);
|
|
281
289
|
} else {
|
|
282
290
|
this.accessory.context.ProgrammableSwitchOutputStateOn = this.ProgrammableSwitchOutputStateOn;
|
|
283
|
-
this.ProgrammableSwitchServiceOn?.updateCharacteristic(this.
|
|
291
|
+
this.ProgrammableSwitchServiceOn?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState,
|
|
284
292
|
this.ProgrammableSwitchOutputStateOn);
|
|
285
293
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
286
294
|
+ ` ProgrammableSwitchOutputStateOn: ${this.ProgrammableSwitchOutputStateOn}`);
|
|
@@ -291,7 +299,7 @@ export class Light {
|
|
|
291
299
|
+ ` ProgrammableSwitchOutputStateOff: ${this.ProgrammableSwitchOutputStateOff}`);
|
|
292
300
|
} else {
|
|
293
301
|
this.accessory.context.ProgrammableSwitchOutputStateOff = this.ProgrammableSwitchOutputStateOff;
|
|
294
|
-
this.ProgrammableSwitchServiceOff?.updateCharacteristic(this.
|
|
302
|
+
this.ProgrammableSwitchServiceOff?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState,
|
|
295
303
|
this.ProgrammableSwitchOutputStateOff);
|
|
296
304
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
|
|
297
305
|
+ ` ProgrammableSwitchOutputStateOff: ${this.ProgrammableSwitchOutputStateOff}`);
|
|
@@ -387,12 +395,12 @@ export class Light {
|
|
|
387
395
|
|
|
388
396
|
async apiError(e: any): Promise<void> {
|
|
389
397
|
if (this.device.irlight?.stateless) {
|
|
390
|
-
this.lightBulbService?.updateCharacteristic(this.
|
|
398
|
+
this.lightBulbService?.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
391
399
|
} else {
|
|
392
|
-
this.ProgrammableSwitchServiceOn?.updateCharacteristic(this.
|
|
393
|
-
this.ProgrammableSwitchServiceOn?.updateCharacteristic(this.
|
|
394
|
-
this.ProgrammableSwitchServiceOff?.updateCharacteristic(this.
|
|
395
|
-
this.ProgrammableSwitchServiceOff?.updateCharacteristic(this.
|
|
400
|
+
this.ProgrammableSwitchServiceOn?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e);
|
|
401
|
+
this.ProgrammableSwitchServiceOn?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e);
|
|
402
|
+
this.ProgrammableSwitchServiceOff?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e);
|
|
403
|
+
this.ProgrammableSwitchServiceOff?.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e);
|
|
396
404
|
}
|
|
397
405
|
}
|
|
398
406
|
|
|
@@ -408,7 +416,7 @@ export class Light {
|
|
|
408
416
|
}
|
|
409
417
|
}
|
|
410
418
|
|
|
411
|
-
async
|
|
419
|
+
async deviceConfig(device: irdevice & irDevicesConfig): Promise<void> {
|
|
412
420
|
let config = {};
|
|
413
421
|
if (device.irlight) {
|
|
414
422
|
config = device.irlight;
|
|
@@ -442,7 +450,7 @@ export class Light {
|
|
|
442
450
|
}
|
|
443
451
|
}
|
|
444
452
|
|
|
445
|
-
async
|
|
453
|
+
async deviceLogs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
446
454
|
if (this.platform.debugMode) {
|
|
447
455
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
448
456
|
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|