@switchbot/homebridge-switchbot 3.5.1-beta.2 → 3.5.1-beta.4
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/dist/device/blindtilt.d.ts +15 -6
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +203 -255
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +9 -4
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +196 -218
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +9 -4
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +202 -247
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +10 -5
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +329 -378
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +9 -4
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +99 -142
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +19 -7
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +203 -264
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +28 -32
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +186 -225
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +9 -4
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +198 -227
- package/dist/device/fan.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 +106 -231
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +12 -4
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +192 -232
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +9 -4
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +91 -157
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +10 -5
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +287 -367
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +10 -5
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +171 -216
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +9 -4
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +93 -158
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +9 -4
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +94 -155
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +9 -4
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +84 -142
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -4
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +99 -124
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +9 -6
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +170 -253
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +12 -4
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +102 -128
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +2 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +2 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +2 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +2 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +2 -1
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +1 -1
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts +2 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +2 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +2 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +2 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +2 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +5 -7
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +51 -34
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +49 -191
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +19 -0
- package/dist/settings.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +279 -0
- package/dist/types/bledevicestatus.d.ts.map +1 -0
- package/dist/types/bledevicestatus.js +2 -0
- package/dist/types/bledevicestatus.js.map +1 -0
- package/dist/types/devicelist.d.ts +89 -0
- package/dist/types/devicelist.d.ts.map +1 -0
- package/dist/types/devicelist.js +6 -0
- package/dist/types/devicelist.js.map +1 -0
- package/dist/types/deviceresponse.d.ts +13 -0
- package/dist/types/deviceresponse.d.ts.map +1 -0
- package/dist/types/deviceresponse.js +2 -0
- package/dist/types/deviceresponse.js.map +1 -0
- package/dist/types/devicestatus.d.ts +149 -0
- package/dist/types/devicestatus.d.ts.map +1 -0
- package/dist/types/devicestatus.js +3 -0
- package/dist/types/devicestatus.js.map +1 -0
- package/dist/types/devicewebhookstatus.d.ts +156 -0
- package/dist/types/devicewebhookstatus.d.ts.map +1 -0
- package/dist/types/devicewebhookstatus.js +2 -0
- package/dist/types/devicewebhookstatus.js.map +1 -0
- package/dist/types/irdevicelist.d.ts +10 -0
- package/dist/types/irdevicelist.d.ts.map +1 -0
- package/dist/types/irdevicelist.js +2 -0
- package/dist/types/irdevicelist.js.map +1 -0
- package/dist/types/pushbody.d.ts +6 -0
- package/dist/types/pushbody.d.ts.map +1 -0
- package/dist/types/pushbody.js +2 -0
- package/dist/types/pushbody.js.map +1 -0
- package/dist/utils.d.ts +25 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +28 -0
- package/dist/utils.js.map +1 -1
- package/package.json +10 -10
- package/src/device/blindtilt.ts +224 -264
- package/src/device/bot.ts +208 -221
- package/src/device/ceilinglight.ts +210 -257
- package/src/device/colorbulb.ts +334 -397
- package/src/device/contact.ts +111 -146
- package/src/device/curtain.ts +220 -283
- package/src/device/device.ts +194 -245
- package/src/device/fan.ts +214 -230
- package/src/device/hub.ts +126 -246
- package/src/device/humidifier.ts +216 -243
- package/src/device/iosensor.ts +114 -166
- package/src/device/lightstrip.ts +302 -377
- package/src/device/lock.ts +187 -221
- package/src/device/meter.ts +116 -177
- package/src/device/meterplus.ts +117 -174
- package/src/device/motion.ts +99 -144
- package/src/device/plug.ts +110 -128
- package/src/device/robotvacuumcleaner.ts +189 -252
- package/src/device/waterdetector.ts +120 -138
- package/src/irdevice/airconditioner.ts +2 -1
- package/src/irdevice/airpurifier.ts +2 -1
- package/src/irdevice/camera.ts +2 -1
- package/src/irdevice/fan.ts +2 -1
- package/src/irdevice/irdevice.ts +3 -2
- package/src/irdevice/light.ts +2 -1
- package/src/irdevice/other.ts +2 -1
- package/src/irdevice/tv.ts +2 -1
- package/src/irdevice/vacuumcleaner.ts +2 -1
- package/src/irdevice/waterheater.ts +2 -1
- package/src/platform.ts +52 -34
- package/src/settings.ts +30 -239
- package/src/types/bledevicestatus.ts +305 -0
- package/src/types/devicelist.ts +124 -0
- package/src/types/deviceresponse.ts +15 -0
- package/src/types/devicestatus.ts +178 -0
- package/src/types/devicewebhookstatus.ts +196 -0
- package/src/types/irdevicelist.ts +15 -0
- package/src/types/pushbody.ts +9 -0
- package/src/utils.ts +33 -0
package/src/device/fan.ts
CHANGED
|
@@ -3,11 +3,16 @@
|
|
|
3
3
|
* plug.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import { deviceBase } from './device.js';
|
|
6
|
+
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
|
|
6
7
|
import { Subject, debounceTime, interval, skipWhile, take, tap } from 'rxjs';
|
|
7
8
|
|
|
9
|
+
import type { devicesConfig } from '../settings.js';
|
|
10
|
+
import type { device } from '../types/devicelist.js';
|
|
8
11
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
9
12
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
10
|
-
import type {
|
|
13
|
+
import type { batteryCirculatorFanServiceData } from '../types/bledevicestatus.js';
|
|
14
|
+
import type { batteryCirculatorFanStatus } from '../types/devicestatus.js';
|
|
15
|
+
import type { batteryCirculatorFanWebhookContext } from '../types/devicewebhookstatus.js';
|
|
11
16
|
|
|
12
17
|
export class Fan extends deviceBase {
|
|
13
18
|
// Services
|
|
@@ -149,6 +154,9 @@ export class Fan extends deviceBase {
|
|
|
149
154
|
// Update Homekit
|
|
150
155
|
this.updateHomeKitCharacteristics();
|
|
151
156
|
|
|
157
|
+
//regisiter webhook event handler
|
|
158
|
+
this.registerWebhook();
|
|
159
|
+
|
|
152
160
|
// Start an update interval
|
|
153
161
|
interval(this.deviceRefreshRate * 1000)
|
|
154
162
|
.pipe(skipWhile(() => this.fanUpdateInProgress))
|
|
@@ -156,9 +164,6 @@ export class Fan extends deviceBase {
|
|
|
156
164
|
await this.refreshStatus();
|
|
157
165
|
});
|
|
158
166
|
|
|
159
|
-
//regisiter webhook event handler
|
|
160
|
-
this.registerWebhook(accessory, device);
|
|
161
|
-
|
|
162
167
|
// Watch for Plug change events
|
|
163
168
|
// We put in a debounce of 100ms so we don't make duplicate calls
|
|
164
169
|
this.doFanUpdate
|
|
@@ -172,64 +177,54 @@ export class Fan extends deviceBase {
|
|
|
172
177
|
try {
|
|
173
178
|
await this.pushChanges();
|
|
174
179
|
} catch (e: any) {
|
|
175
|
-
this.apiError(e);
|
|
176
|
-
this.errorLog(
|
|
177
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
180
|
+
await this.apiError(e);
|
|
181
|
+
await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
178
182
|
}
|
|
179
183
|
this.fanUpdateInProgress = false;
|
|
180
184
|
});
|
|
181
185
|
}
|
|
182
186
|
|
|
183
|
-
async BLEparseStatus(serviceData:
|
|
184
|
-
this.debugLog(
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
case 'on':
|
|
189
|
-
this.Fan.Active = true;
|
|
190
|
-
break;
|
|
191
|
-
default:
|
|
192
|
-
this.Fan.Active = false;
|
|
193
|
-
}
|
|
194
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.Fan.Active}`);
|
|
187
|
+
async BLEparseStatus(serviceData: batteryCirculatorFanServiceData): Promise<void> {
|
|
188
|
+
await this.debugLog('BLEparseStatus');
|
|
189
|
+
// Active
|
|
190
|
+
this.Fan.Active = serviceData.state === 'on' ? this.hap.Characteristic.Active.ACTIVE : this.hap.Characteristic.Active.INACTIVE;
|
|
191
|
+
await this.debugLog(`Active: ${this.Fan.Active}`);
|
|
195
192
|
}
|
|
196
193
|
|
|
197
|
-
async openAPIparseStatus(deviceStatus:
|
|
198
|
-
this.debugLog(
|
|
194
|
+
async openAPIparseStatus(deviceStatus: batteryCirculatorFanStatus) {
|
|
195
|
+
await this.debugLog('openAPIparseStatus');
|
|
199
196
|
|
|
200
197
|
// Active
|
|
201
|
-
this.Fan.Active = deviceStatus.
|
|
202
|
-
this.debugLog(
|
|
198
|
+
this.Fan.Active = deviceStatus.power === 'on' ? this.hap.Characteristic.Active.ACTIVE : this.hap.Characteristic.Active.INACTIVE;
|
|
199
|
+
this.debugLog(`Active: ${this.Fan.Active}`);
|
|
203
200
|
|
|
204
201
|
// SwingMode
|
|
205
|
-
this.Fan.SwingMode = deviceStatus.
|
|
202
|
+
this.Fan.SwingMode = deviceStatus.oscillation === 'on' ?
|
|
206
203
|
this.hap.Characteristic.SwingMode.SWING_ENABLED : this.hap.Characteristic.SwingMode.SWING_DISABLED;
|
|
204
|
+
await this.debugLog(`SwingMode: ${this.Fan.SwingMode}`);
|
|
207
205
|
|
|
208
206
|
// RotationSpeed
|
|
209
|
-
this.Fan.RotationSpeed = deviceStatus.
|
|
207
|
+
this.Fan.RotationSpeed = deviceStatus.fanSpeed;
|
|
208
|
+
await this.debugLog(`RotationSpeed: ${this.Fan.RotationSpeed}`);
|
|
210
209
|
|
|
211
210
|
// ChargingState
|
|
212
|
-
this.Battery.ChargingState = deviceStatus.
|
|
211
|
+
this.Battery.ChargingState = deviceStatus.chargingStatus === 'charging' ?
|
|
213
212
|
this.hap.Characteristic.ChargingState.CHARGING : this.hap.Characteristic.ChargingState.NOT_CHARGING;
|
|
214
213
|
|
|
215
214
|
// BatteryLevel
|
|
216
|
-
this.Battery.BatteryLevel = Number(deviceStatus.
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
this.Battery.BatteryLevel = 100;
|
|
224
|
-
}
|
|
225
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel},`
|
|
226
|
-
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
215
|
+
this.Battery.BatteryLevel = Number(deviceStatus.battery);
|
|
216
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
217
|
+
|
|
218
|
+
// StatusLowBattery
|
|
219
|
+
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
220
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
221
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
227
222
|
|
|
228
223
|
// Firmware Version
|
|
229
|
-
const version = deviceStatus.
|
|
230
|
-
this.debugLog(
|
|
231
|
-
if (deviceStatus.
|
|
232
|
-
const deviceVersion = version
|
|
224
|
+
const version = deviceStatus.version.toString();
|
|
225
|
+
await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
|
|
226
|
+
if (deviceStatus.version) {
|
|
227
|
+
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
233
228
|
this.accessory
|
|
234
229
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
235
230
|
.setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
|
|
@@ -237,7 +232,48 @@ export class Fan extends deviceBase {
|
|
|
237
232
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
238
233
|
.updateValue(deviceVersion);
|
|
239
234
|
this.accessory.context.deviceVersion = deviceVersion;
|
|
240
|
-
this.debugSuccessLog(
|
|
235
|
+
await this.debugSuccessLog(`deviceVersion: ${this.accessory.context.deviceVersion}`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
async parseStatusWebhook(context: batteryCirculatorFanWebhookContext): Promise<void> {
|
|
240
|
+
await this.debugLog('parseStatusWebhook');
|
|
241
|
+
await this.debugLog(`(version, battery, powerState, oscillation, chargingStatus, fanSpeed) = Webhook:(${context.version}, ${context.battery},`
|
|
242
|
+
+ ` ${context.powerState}, ${context.oscillation}, ${context.chargingStatus}, ${context.fanSpeed}),`
|
|
243
|
+
+ ` current:(${this.accessory.context.deviceVersion}, ${this.Battery.BatteryLevel}, ${this.Fan.Active}, ${this.Fan.SwingMode},`
|
|
244
|
+
+ ` ${this.Battery.ChargingState}, ${this.Fan.RotationSpeed})`);
|
|
245
|
+
// Active
|
|
246
|
+
this.Fan.Active = context.powerState === 'ON' ? this.hap.Characteristic.Active.ACTIVE : this.hap.Characteristic.Active.INACTIVE;
|
|
247
|
+
await this.debugLog(`Active: ${this.Fan.Active}`);
|
|
248
|
+
// SwingMode
|
|
249
|
+
this.Fan.SwingMode = context.oscillation === 'on' ?
|
|
250
|
+
this.hap.Characteristic.SwingMode.SWING_ENABLED : this.hap.Characteristic.SwingMode.SWING_DISABLED;
|
|
251
|
+
await this.debugLog(`SwingMode: ${this.Fan.SwingMode}`);
|
|
252
|
+
// RotationSpeed
|
|
253
|
+
this.Fan.RotationSpeed = context.fanSpeed;
|
|
254
|
+
await this.debugLog(`RotationSpeed: ${this.Fan.RotationSpeed}`);
|
|
255
|
+
// BatteryLevel
|
|
256
|
+
this.Battery.BatteryLevel = context.battery;
|
|
257
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
258
|
+
// StatusLowBattery
|
|
259
|
+
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
260
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
261
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
262
|
+
// ChargingState
|
|
263
|
+
this.Battery.ChargingState = context.chargingStatus === 'charging' ?
|
|
264
|
+
this.hap.Characteristic.ChargingState.CHARGING : this.hap.Characteristic.ChargingState.NOT_CHARGING;
|
|
265
|
+
await this.debugLog(`ChargingState: ${this.Battery.ChargingState}`);
|
|
266
|
+
// FirmwareVersion
|
|
267
|
+
if (context.version) {
|
|
268
|
+
const deviceVersion = context.version.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
269
|
+
this.accessory
|
|
270
|
+
.getService(this.hap.Service.AccessoryInformation)!
|
|
271
|
+
.setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
|
|
272
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
|
|
273
|
+
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
274
|
+
.updateValue(deviceVersion);
|
|
275
|
+
this.accessory.context.deviceVersion = deviceVersion;
|
|
276
|
+
await this.debugSuccessLog(`deviceVersion: ${this.accessory.context.deviceVersion}`);
|
|
241
277
|
}
|
|
242
278
|
}
|
|
243
279
|
|
|
@@ -246,20 +282,19 @@ export class Fan extends deviceBase {
|
|
|
246
282
|
*/
|
|
247
283
|
async refreshStatus(): Promise<void> {
|
|
248
284
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
249
|
-
this.errorLog(
|
|
285
|
+
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
250
286
|
} else if (this.BLE) {
|
|
251
287
|
await this.BLERefreshStatus();
|
|
252
288
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
253
289
|
await this.openAPIRefreshStatus();
|
|
254
290
|
} else {
|
|
255
291
|
await this.offlineOff();
|
|
256
|
-
this.debugWarnLog(
|
|
257
|
-
+ ` ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
292
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
258
293
|
}
|
|
259
294
|
}
|
|
260
295
|
|
|
261
296
|
async BLERefreshStatus(): Promise<void> {
|
|
262
|
-
this.debugLog(
|
|
297
|
+
await this.debugLog('BLERefreshStatus');
|
|
263
298
|
const switchbot = await this.switchbotBLE();
|
|
264
299
|
|
|
265
300
|
if (switchbot === undefined) {
|
|
@@ -268,13 +303,13 @@ export class Fan extends deviceBase {
|
|
|
268
303
|
// Start to monitor advertisement packets
|
|
269
304
|
(async () => {
|
|
270
305
|
// Start to monitor advertisement packets
|
|
271
|
-
const serviceData
|
|
306
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as unknown as batteryCirculatorFanServiceData;
|
|
272
307
|
// Update HomeKit
|
|
273
|
-
if (serviceData.model
|
|
308
|
+
if (serviceData.model === SwitchBotBLEModel.Unknown && SwitchBotBLEModelName.Unknown) {
|
|
274
309
|
await this.BLEparseStatus(serviceData);
|
|
275
310
|
await this.updateHomeKitCharacteristics();
|
|
276
311
|
} else {
|
|
277
|
-
this.errorLog(
|
|
312
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
278
313
|
await this.BLERefreshConnection(switchbot);
|
|
279
314
|
}
|
|
280
315
|
})();
|
|
@@ -282,71 +317,39 @@ export class Fan extends deviceBase {
|
|
|
282
317
|
}
|
|
283
318
|
|
|
284
319
|
async openAPIRefreshStatus(): Promise<void> {
|
|
285
|
-
this.debugLog(
|
|
320
|
+
await this.debugLog('openAPIRefreshStatus');
|
|
286
321
|
try {
|
|
287
322
|
const { body, statusCode } = await this.deviceRefreshStatus();
|
|
288
323
|
const deviceStatus: any = await body.json();
|
|
289
|
-
await this.
|
|
290
|
-
if (
|
|
291
|
-
await this.
|
|
292
|
-
await this.openAPIparseStatus(deviceStatus);
|
|
324
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);;
|
|
325
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
326
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
327
|
+
await this.openAPIparseStatus(deviceStatus.body);
|
|
293
328
|
await this.updateHomeKitCharacteristics();
|
|
294
329
|
} else {
|
|
295
|
-
await this.
|
|
330
|
+
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
331
|
+
await this.debugWarnLog(statusCode, deviceStatus);
|
|
296
332
|
}
|
|
297
333
|
} catch (e: any) {
|
|
298
334
|
await this.apiError(e);
|
|
299
|
-
await this.
|
|
335
|
+
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
300
336
|
}
|
|
301
337
|
}
|
|
302
338
|
|
|
303
|
-
async registerWebhook(
|
|
304
|
-
if (device.webhook) {
|
|
305
|
-
this.debugLog(
|
|
306
|
-
this.platform.webhookEventHandler[device.deviceId] = async (context) => {
|
|
339
|
+
async registerWebhook() {
|
|
340
|
+
if (this.device.webhook) {
|
|
341
|
+
await this.debugLog('is listening webhook.');
|
|
342
|
+
this.platform.webhookEventHandler[this.device.deviceId] = async (context: batteryCirculatorFanWebhookContext) => {
|
|
307
343
|
try {
|
|
308
|
-
this.debugLog(
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
const { BatteryLevel, ChargingState } = this.Battery;
|
|
312
|
-
const { FirmwareRevision } = accessory.context;
|
|
313
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} (version, battery, powerState, oscillation, chargingStatus, fanSpeed) = `
|
|
314
|
-
+ `Webhook:(${version}, ${battery}, ${powerState}, ${oscillation}, ${chargingStatus}, ${fanSpeed}), `
|
|
315
|
-
+ `current:(${FirmwareRevision}, ${BatteryLevel}, ${Active}, ${SwingMode}, ${ChargingState}, ${RotationSpeed})`);
|
|
316
|
-
|
|
317
|
-
// Active
|
|
318
|
-
this.Fan.Active = powerState === 'ON' ? this.hap.Characteristic.Active.ACTIVE : this.hap.Characteristic.Active.INACTIVE;
|
|
319
|
-
|
|
320
|
-
// SwingMode
|
|
321
|
-
this.Fan.SwingMode = oscillation === 'on' ?
|
|
322
|
-
this.hap.Characteristic.SwingMode.SWING_ENABLED : this.hap.Characteristic.SwingMode.SWING_DISABLED;
|
|
323
|
-
|
|
324
|
-
// RotationSpeed
|
|
325
|
-
this.Fan.RotationSpeed = fanSpeed;
|
|
326
|
-
|
|
327
|
-
// ChargingState
|
|
328
|
-
this.Battery.ChargingState = chargingStatus === 'charging' ?
|
|
329
|
-
this.hap.Characteristic.ChargingState.CHARGING : this.hap.Characteristic.ChargingState.NOT_CHARGING;
|
|
330
|
-
|
|
331
|
-
// BatteryLevel
|
|
332
|
-
this.Battery.BatteryLevel = battery;
|
|
333
|
-
|
|
334
|
-
// Firmware Version
|
|
335
|
-
if (version) {
|
|
336
|
-
accessory.context.version = version;
|
|
337
|
-
accessory
|
|
338
|
-
.getService(this.hap.Service.AccessoryInformation)!
|
|
339
|
-
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.version)
|
|
340
|
-
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
341
|
-
.updateValue(accessory.context.version);
|
|
342
|
-
}
|
|
343
|
-
this.updateHomeKitCharacteristics();
|
|
344
|
+
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
345
|
+
await this.parseStatusWebhook(context);
|
|
346
|
+
await this.updateHomeKitCharacteristics();
|
|
344
347
|
} catch (e: any) {
|
|
345
|
-
this.errorLog(
|
|
348
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
346
349
|
}
|
|
347
350
|
};
|
|
348
351
|
} else {
|
|
349
|
-
this.debugLog(
|
|
352
|
+
await this.debugLog('is not listening webhook.');
|
|
350
353
|
}
|
|
351
354
|
}
|
|
352
355
|
|
|
@@ -362,14 +365,25 @@ export class Fan extends deviceBase {
|
|
|
362
365
|
|
|
363
366
|
async pushChanges(): Promise<void> {
|
|
364
367
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
365
|
-
this.errorLog(
|
|
368
|
+
await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
|
|
366
369
|
} else if (this.BLE) {
|
|
367
370
|
await this.BLEpushChanges();
|
|
368
371
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
369
372
|
await this.openAPIpushChanges();
|
|
373
|
+
if (this.Fan.Active) {
|
|
374
|
+
await this.debugLog(`Active: ${this.Fan.Active}`);
|
|
375
|
+
// Push RotationSpeed Update
|
|
376
|
+
await this.debugLog(`RotationSpeed: ${this.Fan.RotationSpeed}`);
|
|
377
|
+
await this.pushRotationSpeedChanges();
|
|
378
|
+
// Push SwingMode Update
|
|
379
|
+
await this.debugLog(`SwingMode: ${this.Fan.SwingMode}`);
|
|
380
|
+
await this.pushSwingModeChanges();
|
|
381
|
+
} else {
|
|
382
|
+
await this.debugLog('BLE (RotationSpeed) & (SwingMode) changes will not happen, as the device is Off.');
|
|
383
|
+
}
|
|
370
384
|
} else {
|
|
371
385
|
await this.offlineOff();
|
|
372
|
-
await this.
|
|
386
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
|
|
373
387
|
}
|
|
374
388
|
// Refresh the status from the API
|
|
375
389
|
interval(15000)
|
|
@@ -381,118 +395,107 @@ export class Fan extends deviceBase {
|
|
|
381
395
|
}
|
|
382
396
|
|
|
383
397
|
async BLEpushChanges(): Promise<void> {
|
|
384
|
-
this.debugLog(
|
|
398
|
+
await this.debugLog('BLEpushChanges');
|
|
385
399
|
if (this.Fan.Active !== this.accessory.context.Active) {
|
|
386
|
-
this.debugLog(
|
|
387
|
-
|
|
388
|
-
const switchbot = await this.platform.connectBLE();
|
|
389
|
-
// Convert to BLE Address
|
|
400
|
+
await this.debugLog(`BLEpushChanges On: ${this.Fan.Active} OnCached: ${this.accessory.context.Active}`);
|
|
401
|
+
const switchbot = await this.platform.connectBLE(this.accessory, this.device);
|
|
390
402
|
await this.convertBLEAddress();
|
|
391
|
-
switchbot
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
403
|
+
if (switchbot !== false) {
|
|
404
|
+
switchbot
|
|
405
|
+
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
406
|
+
.then(async (device_list: any) => {
|
|
407
|
+
return await this.retryBLE({
|
|
408
|
+
max: await this.maxRetryBLE(),
|
|
409
|
+
fn: async () => {
|
|
410
|
+
if (this.Fan.Active) {
|
|
411
|
+
return await device_list[0].turnOn({ id: this.device.bleMac });
|
|
412
|
+
} else {
|
|
413
|
+
return await device_list[0].turnOff({ id: this.device.bleMac });
|
|
414
|
+
}
|
|
415
|
+
},
|
|
416
|
+
});
|
|
417
|
+
})
|
|
418
|
+
.then(async () => {
|
|
419
|
+
await this.successLog(`Active: ${this.Fan.Active} sent over SwitchBot BLE, sent successfully`);
|
|
420
|
+
await this.updateHomeKitCharacteristics();
|
|
421
|
+
})
|
|
422
|
+
.catch(async (e: any) => {
|
|
423
|
+
await this.apiError(e);
|
|
424
|
+
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
425
|
+
await this.BLEPushConnection();
|
|
404
426
|
});
|
|
405
|
-
|
|
406
|
-
.
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
})
|
|
410
|
-
.catch(async (e: any) => {
|
|
411
|
-
await this.apiError(e);
|
|
412
|
-
await this.pushChangeError('BLEpushChanges', e);
|
|
413
|
-
await this.BLEPushConnection();
|
|
414
|
-
});
|
|
427
|
+
} else {
|
|
428
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
429
|
+
await this.BLEPushConnection();
|
|
430
|
+
}
|
|
415
431
|
} else {
|
|
416
|
-
this.debugLog(
|
|
417
|
-
+ ` Active: ${this.Fan.Active}, ActiveCached: ${this.accessory.context.Active}`);
|
|
432
|
+
await this.debugLog(`No change (BLEpushChanges), Active: ${this.Fan.Active}, ActiveCached: ${this.accessory.context.Active}`);
|
|
418
433
|
}
|
|
419
434
|
}
|
|
420
435
|
|
|
421
436
|
async openAPIpushChanges() {
|
|
422
|
-
this.debugLog(
|
|
437
|
+
await this.debugLog('openAPIpushChanges');
|
|
423
438
|
if (this.Fan.Active !== this.accessory.context.Active) {
|
|
424
|
-
|
|
425
|
-
if (this.Fan.Active) {
|
|
426
|
-
command = 'turnOn';
|
|
427
|
-
} else {
|
|
428
|
-
command = 'turnOff';
|
|
429
|
-
}
|
|
439
|
+
const command = this.Fan.Active ? 'turnOn' : 'turnOff';
|
|
430
440
|
const bodyChange = JSON.stringify({
|
|
431
441
|
command: `${command}`,
|
|
432
442
|
parameter: 'default',
|
|
433
443
|
commandType: 'command',
|
|
434
444
|
});
|
|
435
|
-
this.debugLog(
|
|
445
|
+
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
436
446
|
try {
|
|
437
447
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
438
448
|
const deviceStatus: any = await body.json();
|
|
439
|
-
await this.
|
|
440
|
-
if (
|
|
441
|
-
await this.
|
|
449
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
450
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
451
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
442
452
|
await this.updateHomeKitCharacteristics();
|
|
443
453
|
} else {
|
|
444
454
|
await this.statusCode(statusCode);
|
|
445
455
|
await this.statusCode(deviceStatus.statusCode);
|
|
446
456
|
}
|
|
447
457
|
} catch (e: any) {
|
|
448
|
-
this.apiError(e);
|
|
449
|
-
await this.
|
|
458
|
+
await this.apiError(e);
|
|
459
|
+
await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
450
460
|
}
|
|
451
461
|
} else {
|
|
452
|
-
this.debugLog(
|
|
453
|
-
+ `On: ${this.Fan.Active}, ActiveCached: ${this.accessory.context.Active}`);
|
|
454
|
-
}
|
|
455
|
-
// Push RotationSpeed Update
|
|
456
|
-
if (this.Fan.Active) {
|
|
457
|
-
await this.pushRotationSpeedChanges();
|
|
458
|
-
}
|
|
459
|
-
// Push SwingMode Update
|
|
460
|
-
if (this.Fan.Active) {
|
|
461
|
-
await this.pushSwingModeChanges();
|
|
462
|
+
await this.debugLog(`No changes (openAPIpushChanges), Active: ${this.Fan.Active}, ActiveCached: ${this.accessory.context.Active}`);
|
|
462
463
|
}
|
|
463
464
|
}
|
|
464
465
|
|
|
465
466
|
async pushRotationSpeedChanges(): Promise<void> {
|
|
466
|
-
await this.
|
|
467
|
+
await this.debugLog('pushRotationSpeedChanges');
|
|
467
468
|
if (this.Fan.SwingMode !== this.accessory.context.SwingMode) {
|
|
468
469
|
const bodyChange = JSON.stringify({
|
|
469
470
|
command: 'setWindSpeed',
|
|
470
471
|
parameter: `${this.Fan.RotationSpeed}`,
|
|
471
472
|
commandType: 'command',
|
|
472
473
|
});
|
|
473
|
-
await this.
|
|
474
|
+
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
474
475
|
try {
|
|
475
476
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
476
477
|
const deviceStatus: any = await body.json();
|
|
477
|
-
await this.
|
|
478
|
-
if (
|
|
479
|
-
await this.
|
|
478
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
479
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
480
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
480
481
|
await this.updateHomeKitCharacteristics();
|
|
481
482
|
} else {
|
|
482
483
|
await this.statusCode(statusCode);
|
|
483
484
|
await this.statusCode(deviceStatus.statusCode);
|
|
484
485
|
}
|
|
485
486
|
} catch (e: any) {
|
|
486
|
-
this.apiError(e);
|
|
487
|
-
await this.
|
|
487
|
+
await this.apiError(e);
|
|
488
|
+
await this.errorLog(`failed pushRotationSpeedChanges with ${this.device.connectionType} Connection,`
|
|
489
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
488
490
|
}
|
|
489
491
|
} else {
|
|
490
|
-
await this.
|
|
492
|
+
await this.debugLog(`No changes (pushRotationSpeedChanges), RotationSpeed: ${this.Fan.RotationSpeed},`
|
|
493
|
+
+ ` RotationSpeedCached: ${this.accessory.context.RotationSpeed}`);
|
|
491
494
|
}
|
|
492
495
|
}
|
|
493
496
|
|
|
494
497
|
async pushSwingModeChanges(): Promise<void> {
|
|
495
|
-
await this.
|
|
498
|
+
await this.debugLog('pushSwingModeChanges');
|
|
496
499
|
if (this.Fan.SwingMode !== this.accessory.context.SwingMode) {
|
|
497
500
|
const parameter = this.Fan.SwingMode === this.hap.Characteristic.SwingMode.SWING_ENABLED ? 'on' : 'off';
|
|
498
501
|
const bodyChange = JSON.stringify({
|
|
@@ -500,24 +503,25 @@ export class Fan extends deviceBase {
|
|
|
500
503
|
parameter: `${parameter}`,
|
|
501
504
|
commandType: 'command',
|
|
502
505
|
});
|
|
503
|
-
await this.
|
|
506
|
+
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
504
507
|
try {
|
|
505
508
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
506
509
|
const deviceStatus: any = await body.json();
|
|
507
|
-
await this.
|
|
508
|
-
if (
|
|
509
|
-
await this.
|
|
510
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
511
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
512
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
510
513
|
await this.updateHomeKitCharacteristics();
|
|
511
514
|
} else {
|
|
512
515
|
await this.statusCode(statusCode);
|
|
513
516
|
await this.statusCode(deviceStatus.statusCode);
|
|
514
517
|
}
|
|
515
518
|
} catch (e: any) {
|
|
516
|
-
this.apiError(e);
|
|
517
|
-
await this.
|
|
519
|
+
await this.apiError(e);
|
|
520
|
+
await this.errorLog(`failed pushSwingModeChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
518
521
|
}
|
|
519
522
|
} else {
|
|
520
|
-
await this.
|
|
523
|
+
await this.debugLog(`No changes (pushSwingModeChanges), SwingMode: ${this.Fan.SwingMode},`
|
|
524
|
+
+ ` SwingModeCached: ${this.accessory.context.SwingMode}`);
|
|
521
525
|
}
|
|
522
526
|
}
|
|
523
527
|
|
|
@@ -526,9 +530,9 @@ export class Fan extends deviceBase {
|
|
|
526
530
|
*/
|
|
527
531
|
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
528
532
|
if (this.Fan.Active !== this.accessory.context.Active) {
|
|
529
|
-
await this.
|
|
533
|
+
await this.infoLog(`Set Active: ${value}`);
|
|
530
534
|
} else {
|
|
531
|
-
await this.
|
|
535
|
+
await this.debugLog(`No Changes, Active: ${value}`);
|
|
532
536
|
}
|
|
533
537
|
|
|
534
538
|
this.Fan.Active = value;
|
|
@@ -540,9 +544,9 @@ export class Fan extends deviceBase {
|
|
|
540
544
|
*/
|
|
541
545
|
async RotationSpeedSet(value: CharacteristicValue): Promise<void> {
|
|
542
546
|
if (this.Fan.RotationSpeed !== this.accessory.context.RotationSpeed) {
|
|
543
|
-
await this.
|
|
547
|
+
await this.infoLog(`Set RotationSpeed ${value}`);
|
|
544
548
|
} else {
|
|
545
|
-
await this.
|
|
549
|
+
await this.debugLog(`No Changes, RotationSpeed: ${value}`);
|
|
546
550
|
}
|
|
547
551
|
|
|
548
552
|
this.Fan.RotationSpeed = value;
|
|
@@ -554,9 +558,9 @@ export class Fan extends deviceBase {
|
|
|
554
558
|
*/
|
|
555
559
|
async SwingModeSet(value: CharacteristicValue): Promise<void> {
|
|
556
560
|
if (this.Fan.SwingMode !== this.accessory.context.SwingMode) {
|
|
557
|
-
await this.
|
|
561
|
+
await this.infoLog(`Set SwingMode ${value}`);
|
|
558
562
|
} else {
|
|
559
|
-
await this.
|
|
563
|
+
await this.debugLog(`No Changes, SwingMode: ${value}`);
|
|
560
564
|
}
|
|
561
565
|
|
|
562
566
|
this.Fan.SwingMode = value;
|
|
@@ -568,9 +572,9 @@ export class Fan extends deviceBase {
|
|
|
568
572
|
*/
|
|
569
573
|
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
570
574
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
571
|
-
await this.
|
|
575
|
+
await this.infoLog(`Set On: ${value}`);
|
|
572
576
|
} else {
|
|
573
|
-
await this.
|
|
577
|
+
await this.debugLog(`No Changes, On: ${value}`);
|
|
574
578
|
}
|
|
575
579
|
|
|
576
580
|
this.LightBulb.On = value;
|
|
@@ -581,12 +585,14 @@ export class Fan extends deviceBase {
|
|
|
581
585
|
* Handle requests to set the value of the "Brightness" characteristic
|
|
582
586
|
*/
|
|
583
587
|
async BrightnessSet(value: CharacteristicValue): Promise<void> {
|
|
584
|
-
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
585
|
-
await this.
|
|
586
|
-
} else if (this.LightBulb.On) {
|
|
587
|
-
await this.changeSet(value, 'Brightness');
|
|
588
|
+
if (this.LightBulb.On && (this.LightBulb.Brightness !== this.accessory.context.Brightness)) {
|
|
589
|
+
await this.infoLog(`Set Brightness: ${value}`);
|
|
588
590
|
} else {
|
|
589
|
-
|
|
591
|
+
if (this.LightBulb.On) {
|
|
592
|
+
this.debugLog(`No Changes, Brightness: ${value}`);
|
|
593
|
+
} else {
|
|
594
|
+
this.debugLog(`Set Brightness: ${value}, On: ${this.LightBulb.On}`);
|
|
595
|
+
}
|
|
590
596
|
}
|
|
591
597
|
|
|
592
598
|
this.LightBulb.Brightness = value;
|
|
@@ -595,68 +601,42 @@ export class Fan extends deviceBase {
|
|
|
595
601
|
|
|
596
602
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
597
603
|
// Active
|
|
598
|
-
|
|
599
|
-
this.
|
|
600
|
-
} else {
|
|
601
|
-
this.accessory.context.Active = this.Fan.Active;
|
|
602
|
-
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.Active, this.Fan.Active);
|
|
603
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Fan.Active}`);
|
|
604
|
-
}
|
|
604
|
+
await this.updateCharacteristic(this.Fan.Service, this.hap.Characteristic.Active,
|
|
605
|
+
this.Fan.Active, 'Active');
|
|
605
606
|
// RotationSpeed
|
|
606
|
-
|
|
607
|
-
this.
|
|
608
|
-
} else {
|
|
609
|
-
this.accessory.context.RotationSpeed = this.Fan.RotationSpeed;
|
|
610
|
-
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.RotationSpeed, this.Fan.RotationSpeed);
|
|
611
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.Fan.RotationSpeed}`);
|
|
612
|
-
}
|
|
607
|
+
await this.updateCharacteristic(this.Fan.Service, this.hap.Characteristic.RotationSpeed,
|
|
608
|
+
this.Fan.RotationSpeed, 'RotationSpeed');
|
|
613
609
|
// SwingMode
|
|
614
|
-
|
|
615
|
-
this.
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
this.
|
|
619
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic SwingMode: ${this.Fan.SwingMode}`);
|
|
620
|
-
}
|
|
621
|
-
// BateryLevel
|
|
622
|
-
if (this.Battery.BatteryLevel === undefined) {
|
|
623
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
624
|
-
} else {
|
|
625
|
-
this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
|
|
626
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
|
|
627
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
628
|
-
}
|
|
610
|
+
await this.updateCharacteristic(this.Fan.Service, this.hap.Characteristic.SwingMode,
|
|
611
|
+
this.Fan.SwingMode, 'SwingMode');
|
|
612
|
+
// BatteryLevel
|
|
613
|
+
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.BatteryLevel,
|
|
614
|
+
this.Battery.BatteryLevel, 'BatteryLevel');
|
|
629
615
|
// ChargingState
|
|
630
|
-
|
|
631
|
-
this.
|
|
632
|
-
} else {
|
|
633
|
-
this.accessory.context.ChargingState = this.Battery.ChargingState;
|
|
634
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.ChargingState, this.Battery.ChargingState);
|
|
635
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic ChargingState: ${this.Battery.ChargingState}`);
|
|
636
|
-
}
|
|
616
|
+
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.ChargingState,
|
|
617
|
+
this.Battery.ChargingState, 'ChargingState');
|
|
637
618
|
// StatusLowBattery
|
|
638
|
-
|
|
639
|
-
this.
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
this.
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
619
|
+
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.StatusLowBattery,
|
|
620
|
+
this.Battery.StatusLowBattery, 'StatusLowBattery');
|
|
621
|
+
// On
|
|
622
|
+
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.On,
|
|
623
|
+
this.LightBulb.On, 'On');
|
|
624
|
+
// Brightness
|
|
625
|
+
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Brightness,
|
|
626
|
+
this.LightBulb.Brightness, 'Brightness');
|
|
646
627
|
}
|
|
647
628
|
|
|
648
629
|
async BLEPushConnection() {
|
|
649
630
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
650
|
-
this.warnLog(
|
|
631
|
+
await this.warnLog('Using OpenAPI Connection to Push Changes');
|
|
651
632
|
await this.openAPIpushChanges();
|
|
652
633
|
}
|
|
653
634
|
}
|
|
654
635
|
|
|
655
636
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
656
|
-
this.errorLog(
|
|
657
|
-
+ ` ${JSON.stringify(switchbot)}`);
|
|
637
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchbot)}`);
|
|
658
638
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
659
|
-
this.warnLog(
|
|
639
|
+
await this.warnLog('Using OpenAPI Connection to Refresh Status');
|
|
660
640
|
await this.openAPIRefreshStatus();
|
|
661
641
|
}
|
|
662
642
|
}
|
|
@@ -666,6 +646,8 @@ export class Fan extends deviceBase {
|
|
|
666
646
|
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
|
|
667
647
|
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.RotationSpeed, 0);
|
|
668
648
|
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.SwingMode, this.hap.Characteristic.SwingMode.SWING_DISABLED);
|
|
649
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, false);
|
|
650
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Brightness, 0);
|
|
669
651
|
}
|
|
670
652
|
}
|
|
671
653
|
|
|
@@ -673,5 +655,7 @@ export class Fan extends deviceBase {
|
|
|
673
655
|
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
|
|
674
656
|
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.RotationSpeed, e);
|
|
675
657
|
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.SwingMode, e);
|
|
658
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
659
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Brightness, e);
|
|
676
660
|
}
|
|
677
661
|
}
|