@switchbot/homebridge-switchbot 3.5.1-beta.9 → 3.5.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 +7 -0
- package/config.schema.json +19 -3
- package/dist/device/blindtilt.d.ts +6 -4
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +60 -46
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +6 -3
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +59 -25
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +6 -3
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +47 -29
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +6 -3
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +53 -36
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +6 -3
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +45 -31
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +6 -4
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +41 -27
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +6 -3
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +59 -152
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +6 -3
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +53 -32
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +6 -3
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +49 -30
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +6 -3
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +47 -28
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +6 -3
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +44 -27
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +6 -3
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +46 -28
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +6 -3
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +38 -25
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +6 -3
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +43 -27
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +6 -3
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +42 -27
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +6 -3
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +37 -24
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +6 -3
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +30 -17
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +6 -3
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +37 -22
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +6 -3
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +43 -26
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/public/index.html +2 -2
- package/dist/irdevice/airconditioner.d.ts +1 -3
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +67 -177
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +0 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +24 -53
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +12 -17
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +22 -38
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +22 -10
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +94 -100
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +20 -38
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +79 -77
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +38 -53
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +11 -16
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +11 -16
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +4 -6
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +564 -665
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +10 -8
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +2 -1
- package/dist/types/bledevicestatus.d.ts.map +1 -1
- package/dist/types/devicestatus.d.ts +1 -1
- package/dist/types/devicestatus.d.ts.map +1 -1
- package/package.json +11 -11
- package/src/device/blindtilt.ts +64 -48
- package/src/device/bot.ts +79 -26
- package/src/device/ceilinglight.ts +57 -31
- package/src/device/colorbulb.ts +57 -43
- package/src/device/contact.ts +49 -31
- package/src/device/curtain.ts +51 -28
- package/src/device/device.ts +61 -135
- package/src/device/fan.ts +67 -33
- package/src/device/hub.ts +62 -33
- package/src/device/humidifier.ts +60 -33
- package/src/device/iosensor.ts +51 -30
- package/src/device/lightstrip.ts +52 -29
- package/src/device/lock.ts +55 -26
- package/src/device/meter.ts +60 -29
- package/src/device/meterplus.ts +56 -29
- package/src/device/motion.ts +50 -26
- package/src/device/plug.ts +38 -18
- package/src/device/robotvacuumcleaner.ts +53 -24
- package/src/device/waterdetector.ts +62 -28
- package/src/homebridge-ui/public/index.html +2 -2
- package/src/irdevice/airconditioner.ts +76 -165
- package/src/irdevice/airpurifier.ts +29 -49
- package/src/irdevice/camera.ts +13 -16
- package/src/irdevice/fan.ts +25 -35
- package/src/irdevice/irdevice.ts +97 -96
- package/src/irdevice/light.ts +21 -35
- package/src/irdevice/other.ts +79 -77
- package/src/irdevice/tv.ts +40 -51
- package/src/irdevice/vacuumcleaner.ts +12 -15
- package/src/irdevice/waterheater.ts +12 -15
- package/src/platform.ts +566 -696
- package/src/settings.ts +11 -8
- package/src/types/bledevicestatus.ts +4 -2
- package/src/types/devicestatus.ts +1 -1
- package/.github/npm-version-script.cjs +0 -81
package/src/irdevice/camera.ts
CHANGED
|
@@ -28,6 +28,8 @@ export class Camera extends irdeviceBase {
|
|
|
28
28
|
device: irdevice & irDevicesConfig,
|
|
29
29
|
) {
|
|
30
30
|
super(platform, accessory, device);
|
|
31
|
+
// Set category
|
|
32
|
+
accessory.category = this.hap.Categories.CAMERA;
|
|
31
33
|
|
|
32
34
|
// Initialize Switch Service
|
|
33
35
|
accessory.context.Switch = accessory.context.Switch ?? {};
|
|
@@ -48,7 +50,7 @@ export class Camera extends irdeviceBase {
|
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
51
|
-
this.debugLog(
|
|
53
|
+
await this.debugLog(`On: ${value}`);
|
|
52
54
|
|
|
53
55
|
this.Switch.On = value;
|
|
54
56
|
if (this.Switch.On) {
|
|
@@ -69,7 +71,7 @@ export class Camera extends irdeviceBase {
|
|
|
69
71
|
* Camera - "command" "channelSub" "default" = previous channel
|
|
70
72
|
*/
|
|
71
73
|
async pushOnChanges(): Promise<void> {
|
|
72
|
-
this.debugLog(
|
|
74
|
+
await this.debugLog(`pushOnChanges On: ${this.Switch.On},`
|
|
73
75
|
+ ` disablePushOn: ${this.disablePushOn}`);
|
|
74
76
|
if (this.Switch.On && !this.disablePushOn) {
|
|
75
77
|
const commandType: string = await this.commandType();
|
|
@@ -84,7 +86,7 @@ export class Camera extends irdeviceBase {
|
|
|
84
86
|
}
|
|
85
87
|
|
|
86
88
|
async pushOffChanges(): Promise<void> {
|
|
87
|
-
this.debugLog(
|
|
89
|
+
await this.debugLog(`pushOffChanges On: ${this.Switch.On},`
|
|
88
90
|
+ ` disablePushOff: ${this.disablePushOff}`);
|
|
89
91
|
if (!this.Switch.On && !this.disablePushOff) {
|
|
90
92
|
const commandType: string = await this.commandType();
|
|
@@ -99,14 +101,14 @@ export class Camera extends irdeviceBase {
|
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
async pushChanges(bodyChange: any): Promise<void> {
|
|
102
|
-
this.debugLog(
|
|
104
|
+
await this.debugLog('pushChanges');
|
|
103
105
|
if (this.device.connectionType === 'OpenAPI') {
|
|
104
|
-
this.infoLog(
|
|
106
|
+
this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
105
107
|
try {
|
|
106
108
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
107
109
|
const deviceStatus: any = await body.json();
|
|
108
110
|
await this.pushStatusCodes(statusCode, deviceStatus);
|
|
109
|
-
if (
|
|
111
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
110
112
|
await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
|
|
111
113
|
await this.updateHomeKitCharacteristics();
|
|
112
114
|
} else {
|
|
@@ -118,20 +120,15 @@ export class Camera extends irdeviceBase {
|
|
|
118
120
|
await this.pushChangeError(e);
|
|
119
121
|
}
|
|
120
122
|
} else {
|
|
121
|
-
this.warnLog(
|
|
122
|
-
+ ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
|
|
123
|
+
await this.warnLog(`Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
|
|
123
124
|
}
|
|
124
125
|
}
|
|
125
126
|
|
|
126
127
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
this.accessory.context.On = this.Switch.On;
|
|
132
|
-
this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, this.Switch.On);
|
|
133
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.Switch.On}`);
|
|
134
|
-
}
|
|
128
|
+
await this.debugLog('updateHomeKitCharacteristics');
|
|
129
|
+
// Active
|
|
130
|
+
await this.updateCharacteristic(this.Switch.Service, this.hap.Characteristic.On,
|
|
131
|
+
this.Switch.On, 'On');
|
|
135
132
|
}
|
|
136
133
|
|
|
137
134
|
async apiError(e: any): Promise<void> {
|
package/src/irdevice/fan.ts
CHANGED
|
@@ -31,6 +31,8 @@ export class IRFan extends irdeviceBase {
|
|
|
31
31
|
device: irdevice & irDevicesConfig,
|
|
32
32
|
) {
|
|
33
33
|
super(platform, accessory, device);
|
|
34
|
+
// Set category
|
|
35
|
+
accessory.category = this.hap.Categories.FAN;
|
|
34
36
|
|
|
35
37
|
// Initialize Switch Service
|
|
36
38
|
accessory.context.Fan = accessory.context.Fan ?? {};
|
|
@@ -68,9 +70,9 @@ export class IRFan extends irdeviceBase {
|
|
|
68
70
|
} else if (this.Fan.Service.testCharacteristic(this.hap.Characteristic.RotationSpeed) && !device.irfan?.swing_mode) {
|
|
69
71
|
const characteristic = this.Fan.Service.getCharacteristic(this.hap.Characteristic.RotationSpeed);
|
|
70
72
|
this.Fan.Service.removeCharacteristic(characteristic);
|
|
71
|
-
this.debugLog(
|
|
73
|
+
this.debugLog('Rotation Speed Characteristic was removed.');
|
|
72
74
|
} else {
|
|
73
|
-
this.debugLog(
|
|
75
|
+
this.debugLog('RotationSpeed Characteristic was not removed/added, '
|
|
74
76
|
+ `Clear Cache on ${this.accessory.displayName} to remove Chracteristic`);
|
|
75
77
|
}
|
|
76
78
|
|
|
@@ -85,15 +87,15 @@ export class IRFan extends irdeviceBase {
|
|
|
85
87
|
} else if (this.Fan.Service.testCharacteristic(this.hap.Characteristic.SwingMode) && !device.irfan?.swing_mode) {
|
|
86
88
|
const characteristic = this.Fan.Service.getCharacteristic(this.hap.Characteristic.SwingMode);
|
|
87
89
|
this.Fan.Service.removeCharacteristic(characteristic);
|
|
88
|
-
this.debugLog(
|
|
90
|
+
this.debugLog('Swing Mode Characteristic was removed.');
|
|
89
91
|
} else {
|
|
90
|
-
this.debugLog(
|
|
92
|
+
this.debugLog('Swing Mode Characteristic was not removed/added, '
|
|
91
93
|
+ `Clear Cache on ${this.accessory.displayName} To Remove Chracteristic`);
|
|
92
94
|
}
|
|
93
95
|
}
|
|
94
96
|
|
|
95
97
|
async SwingModeSet(value: CharacteristicValue): Promise<void> {
|
|
96
|
-
this.debugLog(
|
|
98
|
+
await this.debugLog(`SwingMode: ${value}`);
|
|
97
99
|
if (value > this.Fan.SwingMode) {
|
|
98
100
|
this.Fan.SwingMode = 1;
|
|
99
101
|
await this.pushFanOnChanges();
|
|
@@ -108,7 +110,7 @@ export class IRFan extends irdeviceBase {
|
|
|
108
110
|
}
|
|
109
111
|
|
|
110
112
|
async RotationSpeedSet(value: CharacteristicValue): Promise<void> {
|
|
111
|
-
this.debugLog(
|
|
113
|
+
await this.debugLog(`RotationSpeed: ${value}`);
|
|
112
114
|
if (value > this.Fan.RotationSpeed) {
|
|
113
115
|
this.Fan.RotationSpeed = 1;
|
|
114
116
|
this.pushFanSpeedUpChanges();
|
|
@@ -122,7 +124,7 @@ export class IRFan extends irdeviceBase {
|
|
|
122
124
|
}
|
|
123
125
|
|
|
124
126
|
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
125
|
-
this.debugLog(
|
|
127
|
+
await this.debugLog(`Active: ${value}`);
|
|
126
128
|
|
|
127
129
|
this.Fan.Active = value;
|
|
128
130
|
if (this.Fan.Active === this.hap.Characteristic.Active.ACTIVE) {
|
|
@@ -142,7 +144,7 @@ export class IRFan extends irdeviceBase {
|
|
|
142
144
|
* Fan - "command" "highSpeed" "default" = fan speed to high
|
|
143
145
|
*/
|
|
144
146
|
async pushFanOnChanges(): Promise<void> {
|
|
145
|
-
this.debugLog(
|
|
147
|
+
await this.debugLog(`pushFanOnChanges Active: ${this.Fan.Active},`
|
|
146
148
|
+ ` disablePushOn: ${this.disablePushOn}`);
|
|
147
149
|
if (this.Fan.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
|
|
148
150
|
const commandType: string = await this.commandType();
|
|
@@ -157,7 +159,7 @@ export class IRFan extends irdeviceBase {
|
|
|
157
159
|
}
|
|
158
160
|
|
|
159
161
|
async pushFanOffChanges(): Promise<void> {
|
|
160
|
-
this.debugLog(
|
|
162
|
+
await this.debugLog(`pushLightOffChanges Active: ${this.Fan.Active},`
|
|
161
163
|
+ ` disablePushOff: ${this.disablePushOff}`);
|
|
162
164
|
if (this.Fan.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOff) {
|
|
163
165
|
const commandType: string = await this.commandType();
|
|
@@ -199,14 +201,14 @@ export class IRFan extends irdeviceBase {
|
|
|
199
201
|
}
|
|
200
202
|
|
|
201
203
|
async pushChanges(bodyChange: any): Promise<void> {
|
|
202
|
-
this.debugLog(
|
|
204
|
+
await this.debugLog('pushChanges');
|
|
203
205
|
if (this.device.connectionType === 'OpenAPI') {
|
|
204
|
-
this.infoLog(
|
|
206
|
+
this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
205
207
|
try {
|
|
206
208
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
207
209
|
const deviceStatus: any = await body.json();
|
|
208
210
|
await this.pushStatusCodes(statusCode, deviceStatus);
|
|
209
|
-
if (
|
|
211
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
210
212
|
await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
|
|
211
213
|
await this.updateHomeKitCharacteristics();
|
|
212
214
|
} else {
|
|
@@ -218,33 +220,21 @@ export class IRFan extends irdeviceBase {
|
|
|
218
220
|
await this.pushChangeError(e);
|
|
219
221
|
}
|
|
220
222
|
} else {
|
|
221
|
-
this.warnLog(
|
|
222
|
-
+ ` Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
|
|
223
|
+
await this.warnLog(`Connection Type: ${this.device.connectionType}, commands will not be sent to OpenAPI`);
|
|
223
224
|
}
|
|
224
225
|
}
|
|
225
226
|
|
|
226
227
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
this.
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
this.accessory.context.SwingMode = this.Fan.SwingMode;
|
|
238
|
-
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.SwingMode, this.Fan.SwingMode);
|
|
239
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic SwingMode: ${this.Fan.SwingMode}`);
|
|
240
|
-
}
|
|
241
|
-
if (this.Fan.RotationSpeed === undefined) {
|
|
242
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} RotationSpeed: ${this.Fan.RotationSpeed}`);
|
|
243
|
-
} else {
|
|
244
|
-
this.accessory.context.RotationSpeed = this.Fan.RotationSpeed;
|
|
245
|
-
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.RotationSpeed, this.Fan.RotationSpeed);
|
|
246
|
-
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.Fan.RotationSpeed}`);
|
|
247
|
-
}
|
|
228
|
+
await this.debugLog('updateHomeKitCharacteristics');
|
|
229
|
+
// Active
|
|
230
|
+
await this.updateCharacteristic(this.Fan.Service, this.hap.Characteristic.Active,
|
|
231
|
+
this.Fan.Active, 'Active');
|
|
232
|
+
// SwingMode
|
|
233
|
+
await this.updateCharacteristic(this.Fan.Service, this.hap.Characteristic.SwingMode,
|
|
234
|
+
this.Fan.SwingMode, 'SwingMode');
|
|
235
|
+
// RotationSpeed
|
|
236
|
+
await this.updateCharacteristic(this.Fan.Service, this.hap.Characteristic.RotationSpeed,
|
|
237
|
+
this.Fan.RotationSpeed, 'RotationSpeed');
|
|
248
238
|
}
|
|
249
239
|
|
|
250
240
|
async apiError(e: any): Promise<void> {
|
package/src/irdevice/irdevice.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { request } from 'undici';
|
|
|
6
6
|
import { Devices } from '../settings.js';
|
|
7
7
|
|
|
8
8
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
9
|
-
import type { API, HAP, Logging, PlatformAccessory } from 'homebridge';
|
|
9
|
+
import type { API, HAP, Logging, PlatformAccessory, Service, CharacteristicValue } from 'homebridge';
|
|
10
10
|
import type { SwitchBotPlatformConfig, irDevicesConfig } from '../settings.js';
|
|
11
11
|
import type { irdevice } from '../types/irdevicelist.js';
|
|
12
12
|
|
|
@@ -43,8 +43,8 @@ export abstract class irdeviceBase {
|
|
|
43
43
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
44
44
|
.setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
|
|
45
45
|
.setCharacteristic(this.hap.Characteristic.AppMatchingIdentifier, 'id1087374760')
|
|
46
|
-
.setCharacteristic(this.hap.Characteristic.Name,
|
|
47
|
-
.setCharacteristic(this.hap.Characteristic.ConfiguredName,
|
|
46
|
+
.setCharacteristic(this.hap.Characteristic.Name, device.configDeviceName ?? device.deviceName ?? accessory.displayName)
|
|
47
|
+
.setCharacteristic(this.hap.Characteristic.ConfiguredName, device.configDeviceName ?? device.deviceName ?? accessory.displayName)
|
|
48
48
|
.setCharacteristic(this.hap.Characteristic.Model, accessory.context.model ?? 'Unknown')
|
|
49
49
|
.setCharacteristic(this.hap.Characteristic.ProductData, accessory.context.deviceId)
|
|
50
50
|
.setCharacteristic(this.hap.Characteristic.SerialNumber, accessory.context.deviceId);
|
|
@@ -53,16 +53,16 @@ export abstract class irdeviceBase {
|
|
|
53
53
|
async getDeviceLogSettings(device: irdevice & irDevicesConfig): Promise<void> {
|
|
54
54
|
if (this.platform.debugMode) {
|
|
55
55
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
56
|
-
this.debugWarnLog(
|
|
56
|
+
await this.debugWarnLog(`Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
57
57
|
} else if (device.logging) {
|
|
58
58
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
59
|
-
this.debugWarnLog(
|
|
59
|
+
await this.debugWarnLog(`Using Device Config Logging: ${this.deviceLogging}`);
|
|
60
60
|
} else if (this.config.logging) {
|
|
61
61
|
this.deviceLogging = this.accessory.context.logging = this.config.logging;
|
|
62
|
-
this.debugWarnLog(
|
|
62
|
+
await this.debugWarnLog(`Using Platform Config Logging: ${this.deviceLogging}`);
|
|
63
63
|
} else {
|
|
64
64
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
65
|
-
this.debugWarnLog(
|
|
65
|
+
await this.debugWarnLog(`Logging Not Set, Using: ${this.deviceLogging}`);
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
|
@@ -137,7 +137,7 @@ export abstract class irdeviceBase {
|
|
|
137
137
|
const config = Object.assign({}, deviceConfig, irairConfig, irpurConfig, ircamConfig, irfanConfig, irlightConfig, otherConfig,
|
|
138
138
|
irtvConfig, irvcConfig, irwhConfig);
|
|
139
139
|
if (Object.entries(config).length !== 0) {
|
|
140
|
-
this.debugSuccessLog(
|
|
140
|
+
this.debugSuccessLog(`Config: ${JSON.stringify(config)}`);
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
|
|
@@ -146,33 +146,10 @@ export abstract class irdeviceBase {
|
|
|
146
146
|
accessory.context.model = device.remoteType;
|
|
147
147
|
accessory.context.deviceId = device.deviceId;
|
|
148
148
|
accessory.context.remoteType = device.remoteType;
|
|
149
|
-
if (device.firmware) {
|
|
150
|
-
accessory.context.firmware = device.firmware;
|
|
151
|
-
} else if (device.firmware === undefined || accessory.context.firmware === undefined) {
|
|
152
|
-
device.firmware = this.platform.version;
|
|
153
|
-
accessory.context.firmware = device.firmware;
|
|
154
|
-
} else {
|
|
155
|
-
accessory.context.firmware = 'Unknown';
|
|
156
|
-
}
|
|
157
149
|
|
|
158
|
-
|
|
159
|
-
let deviceFirmwareVersion: string;
|
|
160
|
-
if (device.firmware) {
|
|
161
|
-
deviceFirmwareVersion = device.firmware;
|
|
162
|
-
this.debugSuccessLog(`${device.remoteType}: ${accessory.displayName} 1 FirmwareRevision: ${device.firmware}`);
|
|
163
|
-
} else if (accessory.context.deviceVersion) {
|
|
164
|
-
deviceFirmwareVersion = accessory.context.deviceVersion;
|
|
165
|
-
this.debugSuccessLog(`${device.remoteType}: ${accessory.displayName} 2 FirmwareRevision: ${accessory.context.deviceVersion}`);
|
|
166
|
-
} else {
|
|
167
|
-
deviceFirmwareVersion = this.platform.version ?? '0.0.0';
|
|
168
|
-
if (this.platform.version) {
|
|
169
|
-
this.debugSuccessLog(`${device.remoteType}: ${accessory.displayName} 3 FirmwareRevision: ${this.platform.version}`);
|
|
170
|
-
} else {
|
|
171
|
-
this.debugSuccessLog(`${device.remoteType}: ${accessory.displayName} 4 FirmwareRevision: ${deviceFirmwareVersion}`);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
150
|
+
const deviceFirmwareVersion = device.firmware ?? accessory.context.version ?? this.platform.version ?? '0.0.0';
|
|
174
151
|
const version = deviceFirmwareVersion.toString();
|
|
175
|
-
this.debugLog(
|
|
152
|
+
await this.debugLog(`version: ${version?.replace(/^V|-.*$/g, '')}`);
|
|
176
153
|
let deviceVersion: string;
|
|
177
154
|
if (version?.includes('.') === false) {
|
|
178
155
|
const replace = version?.replace(/^V|-.*$/g, '');
|
|
@@ -189,8 +166,8 @@ export abstract class irdeviceBase {
|
|
|
189
166
|
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
|
|
190
167
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
191
168
|
.updateValue(deviceVersion);
|
|
192
|
-
accessory.context.
|
|
193
|
-
this.debugSuccessLog(
|
|
169
|
+
accessory.context.version = deviceVersion;
|
|
170
|
+
this.debugSuccessLog(`version: ${accessory.context.version}`);
|
|
194
171
|
}
|
|
195
172
|
|
|
196
173
|
async pushChangeRequest(bodyChange: string): Promise<{ body: any; statusCode: any; }> {
|
|
@@ -201,21 +178,48 @@ export abstract class irdeviceBase {
|
|
|
201
178
|
});
|
|
202
179
|
}
|
|
203
180
|
|
|
181
|
+
async successfulStatusCodes(statusCode: any, deviceStatus: any) {
|
|
182
|
+
return await this.successfulStatusCodes(statusCode, deviceStatus);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Update the characteristic value and log the change.
|
|
187
|
+
*
|
|
188
|
+
* @param Service: Service
|
|
189
|
+
* @param Characteristic: Characteristic
|
|
190
|
+
* @param CharacteristicValue: CharacteristicValue | undefined
|
|
191
|
+
* @param CharacteristicName: string
|
|
192
|
+
* @return: void
|
|
193
|
+
*
|
|
194
|
+
*/
|
|
195
|
+
async updateCharacteristic(Service: Service, Characteristic: any,
|
|
196
|
+
CharacteristicValue: CharacteristicValue | undefined, CharacteristicName: string): Promise<void> {
|
|
197
|
+
if (CharacteristicValue === undefined) {
|
|
198
|
+
await this.debugLog(`${CharacteristicName}: ${CharacteristicValue}`);
|
|
199
|
+
} else {
|
|
200
|
+
Service.updateCharacteristic(Characteristic, CharacteristicValue);
|
|
201
|
+
await this.debugLog(`updateCharacteristic ${CharacteristicName}: ${CharacteristicValue}`);
|
|
202
|
+
await this.debugWarnLog(`context before: ${this.accessory.context[CharacteristicName]}`);
|
|
203
|
+
this.accessory.context[CharacteristicName] = CharacteristicValue;
|
|
204
|
+
await this.debugWarnLog(`context after: ${this.accessory.context[CharacteristicName]}`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
204
208
|
async pushStatusCodes(statusCode: any, deviceStatus: any) {
|
|
205
|
-
this.debugWarnLog(
|
|
206
|
-
this.debugWarnLog(
|
|
207
|
-
this.debugWarnLog(
|
|
209
|
+
await this.debugWarnLog(`statusCode: ${statusCode}`);
|
|
210
|
+
await this.debugWarnLog(`deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
211
|
+
await this.debugWarnLog(`deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
208
212
|
}
|
|
209
213
|
|
|
210
214
|
async successfulPushChange(statusCode: any, deviceStatus: any, bodyChange: any) {
|
|
211
|
-
this.debugSuccessLog(
|
|
215
|
+
this.debugSuccessLog(`statusCode: ${statusCode} & deviceStatus `
|
|
212
216
|
+ `StatusCode: ${deviceStatus.statusCode}`);
|
|
213
|
-
this.successLog(
|
|
217
|
+
this.successLog('request to SwitchBot API,'
|
|
214
218
|
+ ` body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
215
219
|
}
|
|
216
220
|
|
|
217
221
|
async pushChangeError(e: Error) {
|
|
218
|
-
this.errorLog(
|
|
222
|
+
this.errorLog(`failed pushChanges with ${this.device.connectionType}`
|
|
219
223
|
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
220
224
|
}
|
|
221
225
|
|
|
@@ -278,69 +282,66 @@ export abstract class irdeviceBase {
|
|
|
278
282
|
async statusCode(statusCode: number): Promise<void> {
|
|
279
283
|
switch (statusCode) {
|
|
280
284
|
case 151:
|
|
281
|
-
this.errorLog(
|
|
285
|
+
this.errorLog(`Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
282
286
|
break;
|
|
283
287
|
case 152:
|
|
284
|
-
this.errorLog(
|
|
288
|
+
this.errorLog(`Device not found, statusCode: ${statusCode}`);
|
|
285
289
|
break;
|
|
286
290
|
case 160:
|
|
287
|
-
this.errorLog(
|
|
291
|
+
this.errorLog(`Command is not supported, statusCode: ${statusCode}`);
|
|
288
292
|
break;
|
|
289
293
|
case 161:
|
|
290
|
-
this.errorLog(
|
|
294
|
+
this.errorLog(`Device is offline, statusCode: ${statusCode}`);
|
|
291
295
|
break;
|
|
292
296
|
case 171:
|
|
293
|
-
this.errorLog(
|
|
294
|
-
+ `Hub: ${this.device.hubDeviceId}`);
|
|
297
|
+
this.errorLog(`Hub Device is offline, statusCode: ${statusCode}. Hub: ${this.device.hubDeviceId}`);
|
|
295
298
|
break;
|
|
296
299
|
case 190:
|
|
297
|
-
this.errorLog(
|
|
298
|
-
+ `
|
|
300
|
+
this.errorLog('Device internal error due to device states not synchronized with server, Or command format is invalid,'
|
|
301
|
+
+ ` statusCode: ${statusCode}`);
|
|
299
302
|
break;
|
|
300
303
|
case 100:
|
|
301
|
-
this.debugLog(
|
|
304
|
+
await this.debugLog(`Command successfully sent, statusCode: ${statusCode}`);
|
|
302
305
|
break;
|
|
303
306
|
case 200:
|
|
304
|
-
this.debugLog(
|
|
307
|
+
await this.debugLog(`Request successful, statusCode: ${statusCode}`);
|
|
305
308
|
break;
|
|
306
309
|
case 400:
|
|
307
|
-
this.errorLog(
|
|
308
|
-
+ `
|
|
310
|
+
this.errorLog('Bad Request, The client has issued an invalid request. This is commonly used to specify validation errors in a request'
|
|
311
|
+
+ ` payload, statusCode: ${statusCode}`);
|
|
309
312
|
break;
|
|
310
313
|
case 401:
|
|
311
|
-
this.errorLog(
|
|
312
|
-
+ `but the request has not been authenticated, statusCode: ${statusCode}`);
|
|
314
|
+
this.errorLog(`Unauthorized, Authorization for the API is required, but the request has not been authenticated, statusCode: ${statusCode}`);
|
|
313
315
|
break;
|
|
314
316
|
case 403:
|
|
315
|
-
this.errorLog(
|
|
316
|
-
+ `
|
|
317
|
+
this.errorLog('Forbidden, The request has been authenticated but does not have appropriate permissions, or a requested resource is not'
|
|
318
|
+
+ ` found, statusCode: ${statusCode}`);
|
|
317
319
|
break;
|
|
318
320
|
case 404:
|
|
319
|
-
this.errorLog(
|
|
320
|
-
+ `statusCode: ${statusCode}`);
|
|
321
|
+
this.errorLog(`Not Found, Specifies the requested path does not exist, statusCode: ${statusCode}`);
|
|
321
322
|
break;
|
|
322
323
|
case 406:
|
|
323
|
-
this.errorLog(
|
|
324
|
-
+ `
|
|
324
|
+
this.errorLog('Not Acceptable, The client has requested a MIME type via the Accept header for a value not supported by the server,'
|
|
325
|
+
+ ` statusCode: ${statusCode}`);
|
|
325
326
|
break;
|
|
326
327
|
case 415:
|
|
327
|
-
this.errorLog(
|
|
328
|
-
+ `
|
|
328
|
+
this.errorLog('Unsupported Media Type, The client has defined a contentType header that is not supported by the server,'
|
|
329
|
+
+ ` statusCode: ${statusCode}`);
|
|
329
330
|
break;
|
|
330
331
|
case 422:
|
|
331
|
-
this.errorLog(
|
|
332
|
-
+ `
|
|
332
|
+
this.errorLog('Unprocessable Entity, The client has made a valid request, but the server cannot process it. This is often used for APIs'
|
|
333
|
+
+ ` for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
333
334
|
break;
|
|
334
335
|
case 429:
|
|
335
|
-
this.errorLog(
|
|
336
|
-
+ `
|
|
336
|
+
this.errorLog('Too Many Requests, The client has exceeded the number of requests allowed for a given time window,'
|
|
337
|
+
+ ` statusCode: ${statusCode}`);
|
|
337
338
|
break;
|
|
338
339
|
case 500:
|
|
339
|
-
this.errorLog(
|
|
340
|
-
+ `
|
|
340
|
+
this.errorLog('Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare,'
|
|
341
|
+
+ ` statusCode: ${statusCode}`);
|
|
341
342
|
break;
|
|
342
343
|
default:
|
|
343
|
-
this.infoLog(
|
|
344
|
+
this.infoLog('Unknown statusCode: '
|
|
344
345
|
+ `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
345
346
|
}
|
|
346
347
|
}
|
|
@@ -348,65 +349,65 @@ export abstract class irdeviceBase {
|
|
|
348
349
|
/**
|
|
349
350
|
* Logging for Device
|
|
350
351
|
*/
|
|
351
|
-
infoLog(...log: any[]): void {
|
|
352
|
-
if (this.enablingDeviceLogging()) {
|
|
353
|
-
this.log.info(String(...log));
|
|
352
|
+
async infoLog(...log: any[]): Promise<void> {
|
|
353
|
+
if (await this.enablingDeviceLogging()) {
|
|
354
|
+
this.log.info(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
|
|
354
355
|
}
|
|
355
356
|
}
|
|
356
357
|
|
|
357
|
-
successLog(...log: any[]): void {
|
|
358
|
-
if (this.enablingDeviceLogging()) {
|
|
359
|
-
this.
|
|
358
|
+
async successLog(...log: any[]): Promise<void> {
|
|
359
|
+
if (await this.enablingDeviceLogging()) {
|
|
360
|
+
this.log.success(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
|
|
360
361
|
}
|
|
361
362
|
}
|
|
362
363
|
|
|
363
|
-
debugSuccessLog(...log: any[]): void {
|
|
364
|
-
if (this.enablingDeviceLogging()) {
|
|
364
|
+
async debugSuccessLog(...log: any[]): Promise<void> {
|
|
365
|
+
if (await this.enablingDeviceLogging()) {
|
|
365
366
|
if (this.deviceLogging?.includes('debug')) {
|
|
366
|
-
this.log.success(
|
|
367
|
+
this.log.success(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
|
|
367
368
|
}
|
|
368
369
|
}
|
|
369
370
|
}
|
|
370
371
|
|
|
371
|
-
warnLog(...log: any[]): void {
|
|
372
|
-
if (this.enablingDeviceLogging()) {
|
|
373
|
-
this.log.warn(String(...log));
|
|
372
|
+
async warnLog(...log: any[]): Promise<void> {
|
|
373
|
+
if (await this.enablingDeviceLogging()) {
|
|
374
|
+
this.log.warn(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
|
|
374
375
|
}
|
|
375
376
|
}
|
|
376
377
|
|
|
377
|
-
debugWarnLog(...log: any[]): void {
|
|
378
|
-
if (this.enablingDeviceLogging()) {
|
|
378
|
+
async debugWarnLog(...log: any[]): Promise<void> {
|
|
379
|
+
if (await this.enablingDeviceLogging()) {
|
|
379
380
|
if (this.deviceLogging?.includes('debug')) {
|
|
380
|
-
this.log.warn(
|
|
381
|
+
this.log.warn(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
|
|
381
382
|
}
|
|
382
383
|
}
|
|
383
384
|
}
|
|
384
385
|
|
|
385
|
-
errorLog(...log: any[]): void {
|
|
386
|
-
if (this.enablingDeviceLogging()) {
|
|
387
|
-
this.log.error(String(...log));
|
|
386
|
+
async errorLog(...log: any[]): Promise<void> {
|
|
387
|
+
if (await this.enablingDeviceLogging()) {
|
|
388
|
+
this.log.error(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
|
|
388
389
|
}
|
|
389
390
|
}
|
|
390
391
|
|
|
391
|
-
debugErrorLog(...log: any[]): void {
|
|
392
|
-
if (this.enablingDeviceLogging()) {
|
|
392
|
+
async debugErrorLog(...log: any[]): Promise<void> {
|
|
393
|
+
if (await this.enablingDeviceLogging()) {
|
|
393
394
|
if (this.deviceLogging?.includes('debug')) {
|
|
394
|
-
this.log.error(
|
|
395
|
+
this.log.error(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
|
|
395
396
|
}
|
|
396
397
|
}
|
|
397
398
|
}
|
|
398
399
|
|
|
399
|
-
debugLog(...log: any[]): void {
|
|
400
|
-
if (this.enablingDeviceLogging()) {
|
|
400
|
+
async debugLog(...log: any[]): Promise<void> {
|
|
401
|
+
if (await this.enablingDeviceLogging()) {
|
|
401
402
|
if (this.deviceLogging === 'debug') {
|
|
402
|
-
this.log.info(
|
|
403
|
+
this.log.info(`[DEBUG] ${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
|
|
403
404
|
} else {
|
|
404
|
-
this.log.debug(String(...log));
|
|
405
|
+
this.log.debug(`${this.device.remoteType}: ${this.accessory.displayName}`, String(...log));
|
|
405
406
|
}
|
|
406
407
|
}
|
|
407
408
|
}
|
|
408
409
|
|
|
409
|
-
enablingDeviceLogging(): boolean {
|
|
410
|
+
async enablingDeviceLogging(): Promise<boolean> {
|
|
410
411
|
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
411
412
|
}
|
|
412
413
|
}
|