@switchbot/homebridge-switchbot 1.11.0 → 1.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/config.schema.json +18 -3
- package/dist/device/bot.d.ts +8 -0
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +40 -21
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +22 -32
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +4 -10
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +13 -28
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +9 -30
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +4 -10
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +4 -10
- package/dist/device/meter.js.map +1 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +4 -10
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +4 -10
- package/dist/device/plug.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +22 -22
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +47 -50
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +12 -9
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +23 -26
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +10 -7
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +14 -17
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +12 -9
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +32 -35
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +10 -7
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +16 -19
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +12 -9
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +21 -24
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +13 -10
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +28 -31
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +10 -7
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +16 -19
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +10 -7
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +19 -22
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +5 -5
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +1 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +4 -4
- package/src/device/bot.ts +40 -20
- package/src/device/colorbulb.ts +22 -44
- package/src/device/contact.ts +4 -12
- package/src/device/curtain.ts +13 -28
- package/src/device/humidifier.ts +9 -30
- package/src/device/lock.ts +4 -10
- package/src/device/meter.ts +4 -10
- package/src/device/motion.ts +4 -12
- package/src/device/plug.ts +4 -10
- package/src/irdevice/airconditioner.ts +57 -60
- package/src/irdevice/airpurifier.ts +33 -36
- package/src/irdevice/camera.ts +22 -25
- package/src/irdevice/fan.ts +43 -46
- package/src/irdevice/light.ts +26 -29
- package/src/irdevice/other.ts +29 -32
- package/src/irdevice/tv.ts +45 -50
- package/src/irdevice/vacuumcleaner.ts +24 -27
- package/src/irdevice/waterheater.ts +27 -30
- package/src/platform.ts +9 -9
- package/src/settings.ts +1 -0
package/src/irdevice/camera.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
|
10
10
|
*/
|
|
11
11
|
export class Camera {
|
|
12
12
|
// Services
|
|
13
|
-
|
|
13
|
+
switchService!: Service;
|
|
14
14
|
|
|
15
15
|
// Characteristic Values
|
|
16
16
|
On!: CharacteristicValue;
|
|
@@ -38,7 +38,7 @@ export class Camera {
|
|
|
38
38
|
|
|
39
39
|
// get the Television service if it exists, otherwise create a new Television service
|
|
40
40
|
// you can create multiple services for each accessory
|
|
41
|
-
(this.
|
|
41
|
+
(this.switchService = accessory.getService(this.platform.Service.Switch) || accessory.addService(this.platform.Service.Switch)),
|
|
42
42
|
`${accessory.displayName} Camera`;
|
|
43
43
|
|
|
44
44
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
@@ -47,13 +47,13 @@ export class Camera {
|
|
|
47
47
|
|
|
48
48
|
// set the service name, this is what is displayed as the default name on the Home app
|
|
49
49
|
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
|
|
50
|
-
this.
|
|
50
|
+
this.switchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
51
51
|
|
|
52
52
|
// handle on / off events using the On characteristic
|
|
53
|
-
this.
|
|
53
|
+
this.switchService.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
57
57
|
this.debugLog(`Camera: ${this.accessory.displayName} On: ${value}`);
|
|
58
58
|
this.On = value;
|
|
59
59
|
if (this.On) {
|
|
@@ -63,11 +63,11 @@ export class Camera {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
async updateHomeKitCharacteristics(): Promise<void> {
|
|
67
67
|
if (this.On === undefined) {
|
|
68
68
|
this.debugLog(`Camera: ${this.accessory.displayName} On: ${this.On}`);
|
|
69
69
|
} else {
|
|
70
|
-
this.
|
|
70
|
+
this.switchService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
|
|
71
71
|
this.debugLog(`Camera: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
@@ -82,7 +82,7 @@ export class Camera {
|
|
|
82
82
|
* Light: "command" "channelAdd" "default" = next channel
|
|
83
83
|
* Light: "command" "channelSub" "default" = previous channel
|
|
84
84
|
*/
|
|
85
|
-
async pushOnChanges() {
|
|
85
|
+
async pushOnChanges(): Promise<void> {
|
|
86
86
|
if (this.On) {
|
|
87
87
|
const payload = {
|
|
88
88
|
commandType: 'command',
|
|
@@ -93,7 +93,7 @@ export class Camera {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
async pushOffChanges() {
|
|
96
|
+
async pushOffChanges(): Promise<void> {
|
|
97
97
|
if (!this.On) {
|
|
98
98
|
const payload = {
|
|
99
99
|
commandType: 'command',
|
|
@@ -104,7 +104,7 @@ export class Camera {
|
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
async pushChanges(payload: payload): Promise<void> {
|
|
108
108
|
try {
|
|
109
109
|
this.infoLog(
|
|
110
110
|
`Camera: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
@@ -120,19 +120,16 @@ export class Camera {
|
|
|
120
120
|
this.accessory.context.On = this.OnCached;
|
|
121
121
|
} catch (e: any) {
|
|
122
122
|
this.errorLog(`Camera: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
123
|
-
if (this.deviceLogging
|
|
123
|
+
if (this.deviceLogging.includes('debug')) {
|
|
124
124
|
this.errorLog(
|
|
125
125
|
`Camera: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
|
|
126
126
|
);
|
|
127
127
|
}
|
|
128
|
-
if (this.platform.debugMode) {
|
|
129
|
-
this.errorLog(`Camera: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
130
|
-
}
|
|
131
128
|
this.apiError(e);
|
|
132
129
|
}
|
|
133
130
|
}
|
|
134
131
|
|
|
135
|
-
|
|
132
|
+
async statusCode(push: AxiosResponse<{ statusCode: number }>): Promise<void> {
|
|
136
133
|
switch (push.data.statusCode) {
|
|
137
134
|
case 151:
|
|
138
135
|
this.errorLog(`Camera: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
@@ -163,12 +160,12 @@ export class Camera {
|
|
|
163
160
|
}
|
|
164
161
|
}
|
|
165
162
|
|
|
166
|
-
|
|
167
|
-
this.
|
|
163
|
+
async apiError(e: any): Promise<void> {
|
|
164
|
+
this.switchService.updateCharacteristic(this.platform.Characteristic.On, e);
|
|
168
165
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
169
166
|
}
|
|
170
167
|
|
|
171
|
-
config(device: irdevice & irDevicesConfig) {
|
|
168
|
+
async config(device: irdevice & irDevicesConfig): Promise<void> {
|
|
172
169
|
let config = {};
|
|
173
170
|
if (device.ircam) {
|
|
174
171
|
config = device.ircam;
|
|
@@ -177,11 +174,11 @@ export class Camera {
|
|
|
177
174
|
config['logging'] = device.logging;
|
|
178
175
|
}
|
|
179
176
|
if (Object.entries(config).length !== 0) {
|
|
180
|
-
this.
|
|
177
|
+
this.infoLog(`Camera: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
181
178
|
}
|
|
182
179
|
}
|
|
183
180
|
|
|
184
|
-
logs(device: irdevice & irDevicesConfig) {
|
|
181
|
+
async logs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
185
182
|
if (this.platform.debugMode) {
|
|
186
183
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
187
184
|
this.debugLog(`Camera: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
@@ -200,25 +197,25 @@ export class Camera {
|
|
|
200
197
|
/**
|
|
201
198
|
* Logging for Device
|
|
202
199
|
*/
|
|
203
|
-
infoLog(...log: any[]) {
|
|
200
|
+
infoLog(...log: any[]): void {
|
|
204
201
|
if (this.enablingDeviceLogging()) {
|
|
205
202
|
this.platform.log.info(String(...log));
|
|
206
203
|
}
|
|
207
204
|
}
|
|
208
205
|
|
|
209
|
-
warnLog(...log: any[]) {
|
|
206
|
+
warnLog(...log: any[]): void {
|
|
210
207
|
if (this.enablingDeviceLogging()) {
|
|
211
208
|
this.platform.log.warn(String(...log));
|
|
212
209
|
}
|
|
213
210
|
}
|
|
214
211
|
|
|
215
|
-
errorLog(...log: any[]) {
|
|
212
|
+
errorLog(...log: any[]): void {
|
|
216
213
|
if (this.enablingDeviceLogging()) {
|
|
217
214
|
this.platform.log.error(String(...log));
|
|
218
215
|
}
|
|
219
216
|
}
|
|
220
217
|
|
|
221
|
-
debugLog(...log: any[]) {
|
|
218
|
+
debugLog(...log: any[]): void {
|
|
222
219
|
if (this.enablingDeviceLogging()) {
|
|
223
220
|
if (this.deviceLogging === 'debug') {
|
|
224
221
|
this.platform.log.info('[DEBUG]', String(...log));
|
|
@@ -229,6 +226,6 @@ export class Camera {
|
|
|
229
226
|
}
|
|
230
227
|
|
|
231
228
|
enablingDeviceLogging(): boolean {
|
|
232
|
-
return this.deviceLogging
|
|
229
|
+
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
233
230
|
}
|
|
234
231
|
}
|
package/src/irdevice/fan.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { DeviceURL, irdevice, deviceStatusResponse, irDevicesConfig, payload } f
|
|
|
10
10
|
*/
|
|
11
11
|
export class Fan {
|
|
12
12
|
// Services
|
|
13
|
-
|
|
13
|
+
fanService!: Service;
|
|
14
14
|
|
|
15
15
|
// Characteristic Values
|
|
16
16
|
Active!: CharacteristicValue;
|
|
@@ -48,7 +48,7 @@ export class Fan {
|
|
|
48
48
|
|
|
49
49
|
// get the Television service if it exists, otherwise create a new Television service
|
|
50
50
|
// you can create multiple services for each accessory
|
|
51
|
-
(this.
|
|
51
|
+
(this.fanService = accessory.getService(this.platform.Service.Fanv2) || accessory.addService(this.platform.Service.Fanv2)),
|
|
52
52
|
`${accessory.displayName} Fan`;
|
|
53
53
|
|
|
54
54
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
@@ -57,10 +57,10 @@ export class Fan {
|
|
|
57
57
|
|
|
58
58
|
// set the service name, this is what is displayed as the default name on the Home app
|
|
59
59
|
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
|
|
60
|
-
this.
|
|
60
|
+
this.fanService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
61
61
|
|
|
62
62
|
// handle on / off events using the Active characteristic
|
|
63
|
-
this.
|
|
63
|
+
this.fanService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
|
|
64
64
|
|
|
65
65
|
if (device.irfan?.rotation_speed) {
|
|
66
66
|
if (device.irfan?.set_minStep) {
|
|
@@ -79,7 +79,7 @@ export class Fan {
|
|
|
79
79
|
this.maxValue = 100;
|
|
80
80
|
}
|
|
81
81
|
// handle Roation Speed events using the RotationSpeed characteristic
|
|
82
|
-
this.
|
|
82
|
+
this.fanService
|
|
83
83
|
.getCharacteristic(this.platform.Characteristic.RotationSpeed)
|
|
84
84
|
.setProps({
|
|
85
85
|
minStep: this.minStep,
|
|
@@ -87,9 +87,9 @@ export class Fan {
|
|
|
87
87
|
maxValue: this.maxValue,
|
|
88
88
|
})
|
|
89
89
|
.onSet(this.RotationSpeedSet.bind(this));
|
|
90
|
-
} else if (this.
|
|
91
|
-
const characteristic = this.
|
|
92
|
-
this.
|
|
90
|
+
} else if (this.fanService.testCharacteristic(this.platform.Characteristic.RotationSpeed) && !device.irfan?.swing_mode) {
|
|
91
|
+
const characteristic = this.fanService.getCharacteristic(this.platform.Characteristic.RotationSpeed);
|
|
92
|
+
this.fanService.removeCharacteristic(characteristic);
|
|
93
93
|
this.debugLog(`Fan: ${this.accessory.displayName} Rotation Speed Characteristic was removed.`);
|
|
94
94
|
} else {
|
|
95
95
|
// eslint-disable-next-line max-len
|
|
@@ -101,10 +101,10 @@ export class Fan {
|
|
|
101
101
|
|
|
102
102
|
if (device.irfan?.swing_mode) {
|
|
103
103
|
// handle Osolcation events using the SwingMode characteristic
|
|
104
|
-
this.
|
|
105
|
-
} else if (this.
|
|
106
|
-
const characteristic = this.
|
|
107
|
-
this.
|
|
104
|
+
this.fanService.getCharacteristic(this.platform.Characteristic.SwingMode).onSet(this.SwingModeSet.bind(this));
|
|
105
|
+
} else if (this.fanService.testCharacteristic(this.platform.Characteristic.SwingMode) && !device.irfan?.swing_mode) {
|
|
106
|
+
const characteristic = this.fanService.getCharacteristic(this.platform.Characteristic.SwingMode);
|
|
107
|
+
this.fanService.removeCharacteristic(characteristic);
|
|
108
108
|
this.debugLog(`Fan: ${this.accessory.displayName} Swing Mode Characteristic was removed.`);
|
|
109
109
|
} else {
|
|
110
110
|
// eslint-disable-next-line max-len
|
|
@@ -115,42 +115,42 @@ export class Fan {
|
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
|
|
118
|
+
async SwingModeSet(value: CharacteristicValue): Promise<void> {
|
|
119
119
|
this.debugLog(`Fan: ${this.accessory.displayName} SwingMode: ${value}`);
|
|
120
120
|
if (value > this.SwingMode) {
|
|
121
121
|
this.SwingMode = 1;
|
|
122
|
-
this.pushFanOnChanges();
|
|
123
|
-
this.pushFanSwingChanges();
|
|
122
|
+
await this.pushFanOnChanges();
|
|
123
|
+
await this.pushFanSwingChanges();
|
|
124
124
|
} else {
|
|
125
125
|
this.SwingMode = 0;
|
|
126
|
-
this.pushFanOnChanges();
|
|
127
|
-
this.pushFanSwingChanges();
|
|
126
|
+
await this.pushFanOnChanges();
|
|
127
|
+
await this.pushFanSwingChanges();
|
|
128
128
|
}
|
|
129
129
|
this.SwingMode = value;
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
|
|
132
|
+
async updateHomeKitCharacteristics(): Promise<void> {
|
|
133
133
|
if (this.Active === undefined) {
|
|
134
134
|
this.debugLog(`Fan: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
135
135
|
} else {
|
|
136
|
-
this.
|
|
136
|
+
this.fanService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
|
|
137
137
|
this.debugLog(`Fan: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
138
138
|
}
|
|
139
139
|
if (this.SwingMode === undefined) {
|
|
140
140
|
this.debugLog(`Fan: ${this.accessory.displayName} SwingMode: ${this.SwingMode}`);
|
|
141
141
|
} else {
|
|
142
|
-
this.
|
|
142
|
+
this.fanService?.updateCharacteristic(this.platform.Characteristic.SwingMode, this.SwingMode);
|
|
143
143
|
this.debugLog(`Fan: ${this.accessory.displayName} updateCharacteristic SwingMode: ${this.SwingMode}`);
|
|
144
144
|
}
|
|
145
145
|
if (this.RotationSpeed === undefined) {
|
|
146
146
|
this.debugLog(`Fan: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
|
|
147
147
|
} else {
|
|
148
|
-
this.
|
|
148
|
+
this.fanService?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
|
|
149
149
|
this.debugLog(`Fan: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
|
|
153
|
+
async RotationSpeedSet(value: CharacteristicValue): Promise<void> {
|
|
154
154
|
this.debugLog(`Fan: ${this.accessory.displayName} RotationSpeed: ${value}`);
|
|
155
155
|
if (value > this.RotationSpeed) {
|
|
156
156
|
this.RotationSpeed = 1;
|
|
@@ -163,7 +163,7 @@ export class Fan {
|
|
|
163
163
|
this.RotationSpeed = value;
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
|
|
166
|
+
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
167
167
|
this.debugLog(`Fan: ${this.accessory.displayName} Active: ${value}`);
|
|
168
168
|
if (value === this.platform.Characteristic.Active.INACTIVE) {
|
|
169
169
|
this.pushFanOffChanges();
|
|
@@ -184,7 +184,7 @@ export class Fan {
|
|
|
184
184
|
* Fan: "command" "middleSpeed" "default" = fan speed to medium
|
|
185
185
|
* Fan: "command" "highSpeed" "default" = fan speed to high
|
|
186
186
|
*/
|
|
187
|
-
async pushFanOnChanges() {
|
|
187
|
+
async pushFanOnChanges(): Promise<void> {
|
|
188
188
|
if (this.Active !== 1) {
|
|
189
189
|
const payload = {
|
|
190
190
|
commandType: 'command',
|
|
@@ -195,7 +195,7 @@ export class Fan {
|
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
-
async pushFanOffChanges() {
|
|
198
|
+
async pushFanOffChanges(): Promise<void> {
|
|
199
199
|
const payload = {
|
|
200
200
|
commandType: 'command',
|
|
201
201
|
parameter: 'default',
|
|
@@ -204,7 +204,7 @@ export class Fan {
|
|
|
204
204
|
await this.pushTVChanges(payload);
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
-
async pushFanSpeedUpChanges() {
|
|
207
|
+
async pushFanSpeedUpChanges(): Promise<void> {
|
|
208
208
|
const payload = {
|
|
209
209
|
commandType: 'command',
|
|
210
210
|
parameter: 'default',
|
|
@@ -213,7 +213,7 @@ export class Fan {
|
|
|
213
213
|
await this.pushTVChanges(payload);
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
-
async pushFanSpeedDownChanges() {
|
|
216
|
+
async pushFanSpeedDownChanges(): Promise<void> {
|
|
217
217
|
const payload = {
|
|
218
218
|
commandType: 'command',
|
|
219
219
|
parameter: 'default',
|
|
@@ -222,7 +222,7 @@ export class Fan {
|
|
|
222
222
|
await this.pushTVChanges(payload);
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
-
async pushFanSwingChanges() {
|
|
225
|
+
async pushFanSwingChanges(): Promise<void> {
|
|
226
226
|
const payload = {
|
|
227
227
|
commandType: 'command',
|
|
228
228
|
parameter: 'default',
|
|
@@ -231,7 +231,7 @@ export class Fan {
|
|
|
231
231
|
await this.pushTVChanges(payload);
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
-
|
|
234
|
+
async pushTVChanges(payload: payload): Promise<void> {
|
|
235
235
|
try {
|
|
236
236
|
this.infoLog(
|
|
237
237
|
`Fan: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
@@ -245,19 +245,16 @@ export class Fan {
|
|
|
245
245
|
this.updateHomeKitCharacteristics();
|
|
246
246
|
} catch (e: any) {
|
|
247
247
|
this.errorLog(`Fan: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
248
|
-
if (this.deviceLogging
|
|
248
|
+
if (this.deviceLogging.includes('debug')) {
|
|
249
249
|
this.errorLog(
|
|
250
250
|
`Fan: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
|
|
251
251
|
);
|
|
252
252
|
}
|
|
253
|
-
if (this.platform.debugMode) {
|
|
254
|
-
this.errorLog(`Fan: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
255
|
-
}
|
|
256
253
|
this.apiError(e);
|
|
257
254
|
}
|
|
258
255
|
}
|
|
259
256
|
|
|
260
|
-
|
|
257
|
+
async statusCode(push: AxiosResponse<{ statusCode: number }>): Promise<void> {
|
|
261
258
|
switch (push.data.statusCode) {
|
|
262
259
|
case 151:
|
|
263
260
|
this.errorLog(`Fan: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
@@ -288,14 +285,14 @@ export class Fan {
|
|
|
288
285
|
}
|
|
289
286
|
}
|
|
290
287
|
|
|
291
|
-
|
|
292
|
-
this.
|
|
293
|
-
this.
|
|
294
|
-
this.
|
|
288
|
+
async apiError(e: any): Promise<void> {
|
|
289
|
+
this.fanService.updateCharacteristic(this.platform.Characteristic.Active, e);
|
|
290
|
+
this.fanService.updateCharacteristic(this.platform.Characteristic.RotationSpeed, e);
|
|
291
|
+
this.fanService.updateCharacteristic(this.platform.Characteristic.SwingMode, e);
|
|
295
292
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
296
293
|
}
|
|
297
294
|
|
|
298
|
-
config(device: irdevice & irDevicesConfig) {
|
|
295
|
+
async config(device: irdevice & irDevicesConfig): Promise<void> {
|
|
299
296
|
let config = {};
|
|
300
297
|
if (device.irfan) {
|
|
301
298
|
config = device.irfan;
|
|
@@ -304,11 +301,11 @@ export class Fan {
|
|
|
304
301
|
config['logging'] = device.logging;
|
|
305
302
|
}
|
|
306
303
|
if (Object.entries(config).length !== 0) {
|
|
307
|
-
this.
|
|
304
|
+
this.infoLog(`Fan: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
308
305
|
}
|
|
309
306
|
}
|
|
310
307
|
|
|
311
|
-
logs(device: irdevice & irDevicesConfig) {
|
|
308
|
+
async logs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
312
309
|
if (this.platform.debugMode) {
|
|
313
310
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
314
311
|
this.debugLog(`Fan: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
@@ -327,25 +324,25 @@ export class Fan {
|
|
|
327
324
|
/**
|
|
328
325
|
* Logging for Device
|
|
329
326
|
*/
|
|
330
|
-
infoLog(...log: any[]) {
|
|
327
|
+
infoLog(...log: any[]): void {
|
|
331
328
|
if (this.enablingDeviceLogging()) {
|
|
332
329
|
this.platform.log.info(String(...log));
|
|
333
330
|
}
|
|
334
331
|
}
|
|
335
332
|
|
|
336
|
-
warnLog(...log: any[]) {
|
|
333
|
+
warnLog(...log: any[]): void {
|
|
337
334
|
if (this.enablingDeviceLogging()) {
|
|
338
335
|
this.platform.log.warn(String(...log));
|
|
339
336
|
}
|
|
340
337
|
}
|
|
341
338
|
|
|
342
|
-
errorLog(...log: any[]) {
|
|
339
|
+
errorLog(...log: any[]): void {
|
|
343
340
|
if (this.enablingDeviceLogging()) {
|
|
344
341
|
this.platform.log.error(String(...log));
|
|
345
342
|
}
|
|
346
343
|
}
|
|
347
344
|
|
|
348
|
-
debugLog(...log: any[]) {
|
|
345
|
+
debugLog(...log: any[]): void {
|
|
349
346
|
if (this.enablingDeviceLogging()) {
|
|
350
347
|
if (this.deviceLogging === 'debug') {
|
|
351
348
|
this.platform.log.info('[DEBUG]', String(...log));
|
|
@@ -356,6 +353,6 @@ export class Fan {
|
|
|
356
353
|
}
|
|
357
354
|
|
|
358
355
|
enablingDeviceLogging(): boolean {
|
|
359
|
-
return this.deviceLogging
|
|
356
|
+
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
360
357
|
}
|
|
361
358
|
}
|
package/src/irdevice/light.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
|
10
10
|
*/
|
|
11
11
|
export class Light {
|
|
12
12
|
// Services
|
|
13
|
-
|
|
13
|
+
lightBulbService!: Service;
|
|
14
14
|
|
|
15
15
|
// Characteristic Values
|
|
16
16
|
On!: CharacteristicValue;
|
|
@@ -38,7 +38,7 @@ export class Light {
|
|
|
38
38
|
|
|
39
39
|
// get the Television service if it exists, otherwise create a new Television service
|
|
40
40
|
// you can create multiple services for each accessory
|
|
41
|
-
(this.
|
|
41
|
+
(this.lightBulbService = accessory.getService(this.platform.Service.Lightbulb) || accessory.addService(this.platform.Service.Lightbulb)),
|
|
42
42
|
`${accessory.displayName} Light Bulb`;
|
|
43
43
|
|
|
44
44
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
@@ -47,10 +47,10 @@ export class Light {
|
|
|
47
47
|
|
|
48
48
|
// set the service name, this is what is displayed as the default name on the Home app
|
|
49
49
|
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
|
|
50
|
-
this.
|
|
50
|
+
this.lightBulbService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
51
51
|
|
|
52
52
|
// handle on / off events using the On characteristic
|
|
53
|
-
this.
|
|
53
|
+
this.lightBulbService.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
54
54
|
|
|
55
55
|
// handle Brightness events using the Brightness characteristic
|
|
56
56
|
/* this.service
|
|
@@ -68,21 +68,21 @@ export class Light {
|
|
|
68
68
|
});*/
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
72
72
|
this.debugLog(`Light: ${this.accessory.displayName} On: ${value}`);
|
|
73
73
|
this.On = value;
|
|
74
74
|
if (this.On) {
|
|
75
|
-
this.pushLightOnChanges();
|
|
75
|
+
await this.pushLightOnChanges();
|
|
76
76
|
} else {
|
|
77
|
-
this.pushLightOffChanges();
|
|
77
|
+
await this.pushLightOffChanges();
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
async updateHomeKitCharacteristics(): Promise<void> {
|
|
82
82
|
if (this.On === undefined) {
|
|
83
83
|
this.debugLog(`Light: ${this.accessory.displayName} On: ${this.On}`);
|
|
84
84
|
} else {
|
|
85
|
-
this.
|
|
85
|
+
this.lightBulbService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
|
|
86
86
|
this.debugLog(`Light: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
@@ -97,7 +97,7 @@ export class Light {
|
|
|
97
97
|
* Light: "command" "channelAdd" "default" = next channel
|
|
98
98
|
* Light: "command" "channelSub" "default" = previous channel
|
|
99
99
|
*/
|
|
100
|
-
async pushLightOnChanges() {
|
|
100
|
+
async pushLightOnChanges(): Promise<void> {
|
|
101
101
|
if (this.On) {
|
|
102
102
|
const payload = {
|
|
103
103
|
commandType: 'command',
|
|
@@ -108,7 +108,7 @@ export class Light {
|
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
async pushLightOffChanges() {
|
|
111
|
+
async pushLightOffChanges(): Promise<void> {
|
|
112
112
|
if (!this.On) {
|
|
113
113
|
const payload = {
|
|
114
114
|
commandType: 'command',
|
|
@@ -119,7 +119,7 @@ export class Light {
|
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
async pushLightBrightnessUpChanges() {
|
|
122
|
+
async pushLightBrightnessUpChanges(): Promise<void> {
|
|
123
123
|
const payload = {
|
|
124
124
|
commandType: 'command',
|
|
125
125
|
parameter: 'default',
|
|
@@ -128,7 +128,7 @@ export class Light {
|
|
|
128
128
|
await this.pushChanges(payload);
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
async pushLightBrightnessDownChanges() {
|
|
131
|
+
async pushLightBrightnessDownChanges(): Promise<void> {
|
|
132
132
|
const payload = {
|
|
133
133
|
commandType: 'command',
|
|
134
134
|
parameter: 'default',
|
|
@@ -137,7 +137,7 @@ export class Light {
|
|
|
137
137
|
await this.pushChanges(payload);
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
|
|
140
|
+
async pushChanges(payload: payload): Promise<void> {
|
|
141
141
|
try {
|
|
142
142
|
this.infoLog(
|
|
143
143
|
`Light: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
@@ -153,19 +153,16 @@ export class Light {
|
|
|
153
153
|
this.updateHomeKitCharacteristics();
|
|
154
154
|
} catch (e: any) {
|
|
155
155
|
this.errorLog(`Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
156
|
-
if (this.deviceLogging
|
|
156
|
+
if (this.deviceLogging.includes('debug')) {
|
|
157
157
|
this.errorLog(
|
|
158
158
|
`Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
|
|
159
159
|
);
|
|
160
160
|
}
|
|
161
|
-
if (this.platform.debugMode) {
|
|
162
|
-
this.errorLog(`Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
163
|
-
}
|
|
164
161
|
this.apiError(e);
|
|
165
162
|
}
|
|
166
163
|
}
|
|
167
164
|
|
|
168
|
-
|
|
165
|
+
async statusCode(push: AxiosResponse<{ statusCode: number }>): Promise<void>{
|
|
169
166
|
switch (push.data.statusCode) {
|
|
170
167
|
case 151:
|
|
171
168
|
this.errorLog(`Light: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
@@ -196,12 +193,12 @@ export class Light {
|
|
|
196
193
|
}
|
|
197
194
|
}
|
|
198
195
|
|
|
199
|
-
|
|
200
|
-
this.
|
|
196
|
+
async apiError(e: any): Promise<void> {
|
|
197
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.On, e);
|
|
201
198
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
202
199
|
}
|
|
203
200
|
|
|
204
|
-
config(device: irdevice & irDevicesConfig) {
|
|
201
|
+
async config(device: irdevice & irDevicesConfig): Promise<void> {
|
|
205
202
|
let config = {};
|
|
206
203
|
if (device.irlight) {
|
|
207
204
|
config = device.irlight;
|
|
@@ -210,11 +207,11 @@ export class Light {
|
|
|
210
207
|
config['logging'] = device.logging;
|
|
211
208
|
}
|
|
212
209
|
if (Object.entries(config).length !== 0) {
|
|
213
|
-
this.
|
|
210
|
+
this.infoLog(`Light: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
214
211
|
}
|
|
215
212
|
}
|
|
216
213
|
|
|
217
|
-
logs(device: irdevice & irDevicesConfig) {
|
|
214
|
+
async logs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
218
215
|
if (this.platform.debugMode) {
|
|
219
216
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
220
217
|
this.debugLog(`Light: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
@@ -233,25 +230,25 @@ export class Light {
|
|
|
233
230
|
/**
|
|
234
231
|
* Logging for Device
|
|
235
232
|
*/
|
|
236
|
-
infoLog(...log: any[]) {
|
|
233
|
+
infoLog(...log: any[]): void {
|
|
237
234
|
if (this.enablingDeviceLogging()) {
|
|
238
235
|
this.platform.log.info(String(...log));
|
|
239
236
|
}
|
|
240
237
|
}
|
|
241
238
|
|
|
242
|
-
warnLog(...log: any[]) {
|
|
239
|
+
warnLog(...log: any[]): void {
|
|
243
240
|
if (this.enablingDeviceLogging()) {
|
|
244
241
|
this.platform.log.warn(String(...log));
|
|
245
242
|
}
|
|
246
243
|
}
|
|
247
244
|
|
|
248
|
-
errorLog(...log: any[]) {
|
|
245
|
+
errorLog(...log: any[]): void {
|
|
249
246
|
if (this.enablingDeviceLogging()) {
|
|
250
247
|
this.platform.log.error(String(...log));
|
|
251
248
|
}
|
|
252
249
|
}
|
|
253
250
|
|
|
254
|
-
debugLog(...log: any[]) {
|
|
251
|
+
debugLog(...log: any[]): void {
|
|
255
252
|
if (this.enablingDeviceLogging()) {
|
|
256
253
|
if (this.deviceLogging === 'debug') {
|
|
257
254
|
this.platform.log.info('[DEBUG]', String(...log));
|
|
@@ -262,6 +259,6 @@ export class Light {
|
|
|
262
259
|
}
|
|
263
260
|
|
|
264
261
|
enablingDeviceLogging(): boolean {
|
|
265
|
-
return this.deviceLogging
|
|
262
|
+
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
266
263
|
}
|
|
267
264
|
}
|