@switchbot/homebridge-switchbot 3.5.1-beta.0 → 3.5.1-beta.10
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/README.md +16 -0
- package/dist/device/blindtilt.d.ts +15 -6
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +224 -370
- 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 +197 -221
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +10 -5
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +214 -292
- 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 +335 -421
- 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 +121 -200
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +20 -7
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +229 -403
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +41 -22
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +212 -181
- 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 +204 -249
- 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 +107 -233
- 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 +193 -235
- 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 +92 -159
- 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 +288 -370
- 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 +172 -219
- 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 +94 -160
- 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 +95 -157
- 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 +85 -144
- 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 +100 -127
- 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 +172 -259
- 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 +106 -131
- 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 +2 -3
- 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 +2 -3
- 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 +2 -3
- 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 +2 -3
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +3 -1
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +5 -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 +2 -3
- 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 +2 -3
- 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 +2 -3
- 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 +2 -3
- 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 +2 -3
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +14 -14
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +102 -86
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +49 -190
- 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 +11 -11
- package/src/device/blindtilt.ts +254 -376
- package/src/device/bot.ts +209 -224
- package/src/device/ceilinglight.ts +227 -297
- package/src/device/colorbulb.ts +345 -435
- package/src/device/contact.ts +139 -200
- package/src/device/curtain.ts +254 -414
- package/src/device/device.ts +221 -190
- package/src/device/fan.ts +222 -253
- package/src/device/hub.ts +127 -248
- package/src/device/humidifier.ts +217 -246
- package/src/device/iosensor.ts +115 -168
- package/src/device/lightstrip.ts +303 -380
- package/src/device/lock.ts +188 -224
- package/src/device/meter.ts +117 -179
- package/src/device/meterplus.ts +118 -176
- package/src/device/motion.ts +100 -146
- package/src/device/plug.ts +111 -131
- package/src/device/robotvacuumcleaner.ts +191 -258
- package/src/device/waterdetector.ts +124 -141
- package/src/irdevice/airconditioner.ts +4 -4
- package/src/irdevice/airpurifier.ts +4 -4
- package/src/irdevice/camera.ts +4 -4
- package/src/irdevice/fan.ts +4 -4
- package/src/irdevice/irdevice.ts +8 -2
- package/src/irdevice/light.ts +4 -4
- package/src/irdevice/other.ts +4 -4
- package/src/irdevice/tv.ts +4 -4
- package/src/irdevice/vacuumcleaner.ts +4 -4
- package/src/irdevice/waterheater.ts +4 -4
- package/src/platform.ts +104 -87
- package/src/settings.ts +30 -238
- 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,35 +282,34 @@ 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) {
|
|
266
301
|
await this.BLERefreshConnection(switchbot);
|
|
267
302
|
} else {
|
|
268
|
-
// Start to monitor advertisement packets
|
|
269
|
-
(async () => {
|
|
270
303
|
// Start to monitor advertisement packets
|
|
271
|
-
|
|
304
|
+
(async () => {
|
|
305
|
+
// Start to monitor advertisement packets
|
|
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,72 +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
|
-
this.apiError(e);
|
|
299
|
-
this.errorLog(
|
|
300
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
334
|
+
await this.apiError(e);
|
|
335
|
+
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
301
336
|
}
|
|
302
337
|
}
|
|
303
338
|
|
|
304
|
-
async registerWebhook(
|
|
305
|
-
if (device.webhook) {
|
|
306
|
-
this.debugLog(
|
|
307
|
-
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) => {
|
|
308
343
|
try {
|
|
309
|
-
this.debugLog(
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
const { BatteryLevel, ChargingState } = this.Battery;
|
|
313
|
-
const { FirmwareRevision } = accessory.context;
|
|
314
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} (version, battery, powerState, oscillation, chargingStatus, fanSpeed) = `
|
|
315
|
-
+ `Webhook:(${version}, ${battery}, ${powerState}, ${oscillation}, ${chargingStatus}, ${fanSpeed}), `
|
|
316
|
-
+ `current:(${FirmwareRevision}, ${BatteryLevel}, ${Active}, ${SwingMode}, ${ChargingState}, ${RotationSpeed})`);
|
|
317
|
-
|
|
318
|
-
// Active
|
|
319
|
-
this.Fan.Active = powerState === 'ON' ? this.hap.Characteristic.Active.ACTIVE : this.hap.Characteristic.Active.INACTIVE;
|
|
320
|
-
|
|
321
|
-
// SwingMode
|
|
322
|
-
this.Fan.SwingMode = oscillation === 'on' ?
|
|
323
|
-
this.hap.Characteristic.SwingMode.SWING_ENABLED : this.hap.Characteristic.SwingMode.SWING_DISABLED;
|
|
324
|
-
|
|
325
|
-
// RotationSpeed
|
|
326
|
-
this.Fan.RotationSpeed = fanSpeed;
|
|
327
|
-
|
|
328
|
-
// ChargingState
|
|
329
|
-
this.Battery.ChargingState = chargingStatus === 'charging' ?
|
|
330
|
-
this.hap.Characteristic.ChargingState.CHARGING : this.hap.Characteristic.ChargingState.NOT_CHARGING;
|
|
331
|
-
|
|
332
|
-
// BatteryLevel
|
|
333
|
-
this.Battery.BatteryLevel = battery;
|
|
334
|
-
|
|
335
|
-
// Firmware Version
|
|
336
|
-
if (version) {
|
|
337
|
-
accessory.context.version = version;
|
|
338
|
-
accessory
|
|
339
|
-
.getService(this.hap.Service.AccessoryInformation)!
|
|
340
|
-
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.version)
|
|
341
|
-
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
342
|
-
.updateValue(accessory.context.version);
|
|
343
|
-
}
|
|
344
|
-
this.updateHomeKitCharacteristics();
|
|
344
|
+
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
345
|
+
await this.parseStatusWebhook(context);
|
|
346
|
+
await this.updateHomeKitCharacteristics();
|
|
345
347
|
} catch (e: any) {
|
|
346
|
-
this.errorLog(
|
|
348
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
347
349
|
}
|
|
348
350
|
};
|
|
349
351
|
} else {
|
|
350
|
-
this.debugLog(
|
|
352
|
+
await this.debugLog('is not listening webhook.');
|
|
351
353
|
}
|
|
352
354
|
}
|
|
353
355
|
|
|
@@ -363,15 +365,25 @@ export class Fan extends deviceBase {
|
|
|
363
365
|
|
|
364
366
|
async pushChanges(): Promise<void> {
|
|
365
367
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
366
|
-
this.errorLog(
|
|
368
|
+
await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
|
|
367
369
|
} else if (this.BLE) {
|
|
368
370
|
await this.BLEpushChanges();
|
|
369
371
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
370
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
|
+
}
|
|
371
384
|
} else {
|
|
372
385
|
await this.offlineOff();
|
|
373
|
-
this.debugWarnLog(
|
|
374
|
-
+ ` ${this.device.connectionType}, pushChanges will not happen.`);
|
|
386
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
|
|
375
387
|
}
|
|
376
388
|
// Refresh the status from the API
|
|
377
389
|
interval(15000)
|
|
@@ -383,156 +395,133 @@ export class Fan extends deviceBase {
|
|
|
383
395
|
}
|
|
384
396
|
|
|
385
397
|
async BLEpushChanges(): Promise<void> {
|
|
386
|
-
this.debugLog(
|
|
398
|
+
await this.debugLog('BLEpushChanges');
|
|
387
399
|
if (this.Fan.Active !== this.accessory.context.Active) {
|
|
388
|
-
this.debugLog(
|
|
389
|
-
|
|
390
|
-
const switchbot = await this.platform.connectBLE();
|
|
391
|
-
// 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);
|
|
392
402
|
await this.convertBLEAddress();
|
|
393
|
-
switchbot
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
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();
|
|
406
426
|
});
|
|
407
|
-
|
|
408
|
-
.
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
+ `Active: ${this.Fan.Active} sent over BLE, sent successfully`);
|
|
412
|
-
this.Fan.Active = false;
|
|
413
|
-
})
|
|
414
|
-
.catch(async (e: any) => {
|
|
415
|
-
this.apiError(e);
|
|
416
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
|
|
417
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
418
|
-
await this.BLEPushConnection();
|
|
419
|
-
});
|
|
427
|
+
} else {
|
|
428
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
429
|
+
await this.BLEPushConnection();
|
|
430
|
+
}
|
|
420
431
|
} else {
|
|
421
|
-
this.debugLog(
|
|
422
|
-
+ ` 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}`);
|
|
423
433
|
}
|
|
424
434
|
}
|
|
425
435
|
|
|
426
436
|
async openAPIpushChanges() {
|
|
427
|
-
this.debugLog(
|
|
437
|
+
await this.debugLog('openAPIpushChanges');
|
|
428
438
|
if (this.Fan.Active !== this.accessory.context.Active) {
|
|
429
|
-
|
|
430
|
-
if (this.Fan.Active) {
|
|
431
|
-
command = 'turnOn';
|
|
432
|
-
} else {
|
|
433
|
-
command = 'turnOff';
|
|
434
|
-
}
|
|
439
|
+
const command = this.Fan.Active ? 'turnOn' : 'turnOff';
|
|
435
440
|
const bodyChange = JSON.stringify({
|
|
436
441
|
command: `${command}`,
|
|
437
442
|
parameter: 'default',
|
|
438
443
|
commandType: 'command',
|
|
439
444
|
});
|
|
440
|
-
this.debugLog(
|
|
445
|
+
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
441
446
|
try {
|
|
442
447
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
443
448
|
const deviceStatus: any = await body.json();
|
|
444
|
-
await this.
|
|
445
|
-
if (
|
|
446
|
-
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)}`);
|
|
447
452
|
await this.updateHomeKitCharacteristics();
|
|
448
453
|
} else {
|
|
449
454
|
await this.statusCode(statusCode);
|
|
450
455
|
await this.statusCode(deviceStatus.statusCode);
|
|
451
456
|
}
|
|
452
457
|
} catch (e: any) {
|
|
453
|
-
this.apiError(e);
|
|
454
|
-
this.errorLog(
|
|
455
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
458
|
+
await this.apiError(e);
|
|
459
|
+
await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
456
460
|
}
|
|
457
461
|
} else {
|
|
458
|
-
this.debugLog(
|
|
459
|
-
+ `On: ${this.Fan.Active}, ActiveCached: ${this.accessory.context.Active}`);
|
|
460
|
-
}
|
|
461
|
-
// Push RotationSpeed Update
|
|
462
|
-
if (this.Fan.Active) {
|
|
463
|
-
await this.pushRotationSpeedChanges();
|
|
464
|
-
}
|
|
465
|
-
// Push SwingMode Update
|
|
466
|
-
if (this.Fan.Active) {
|
|
467
|
-
await this.pushSwingModeChanges();
|
|
462
|
+
await this.debugLog(`No changes (openAPIpushChanges), Active: ${this.Fan.Active}, ActiveCached: ${this.accessory.context.Active}`);
|
|
468
463
|
}
|
|
469
464
|
}
|
|
470
465
|
|
|
471
466
|
async pushRotationSpeedChanges(): Promise<void> {
|
|
472
|
-
this.debugLog(
|
|
467
|
+
await this.debugLog('pushRotationSpeedChanges');
|
|
473
468
|
if (this.Fan.SwingMode !== this.accessory.context.SwingMode) {
|
|
474
469
|
const bodyChange = JSON.stringify({
|
|
475
470
|
command: 'setWindSpeed',
|
|
476
471
|
parameter: `${this.Fan.RotationSpeed}`,
|
|
477
472
|
commandType: 'command',
|
|
478
473
|
});
|
|
479
|
-
this.debugLog(
|
|
474
|
+
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
480
475
|
try {
|
|
481
476
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
482
477
|
const deviceStatus: any = await body.json();
|
|
483
|
-
await this.
|
|
484
|
-
if (
|
|
485
|
-
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)}`);
|
|
486
481
|
await this.updateHomeKitCharacteristics();
|
|
487
482
|
} else {
|
|
488
483
|
await this.statusCode(statusCode);
|
|
489
484
|
await this.statusCode(deviceStatus.statusCode);
|
|
490
485
|
}
|
|
491
486
|
} catch (e: any) {
|
|
492
|
-
this.apiError(e);
|
|
493
|
-
this.errorLog(
|
|
494
|
-
+ `
|
|
487
|
+
await this.apiError(e);
|
|
488
|
+
await this.errorLog(`failed pushRotationSpeedChanges with ${this.device.connectionType} Connection,`
|
|
489
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
495
490
|
}
|
|
496
491
|
} else {
|
|
497
|
-
this.debugLog(
|
|
498
|
-
+ `
|
|
492
|
+
await this.debugLog(`No changes (pushRotationSpeedChanges), RotationSpeed: ${this.Fan.RotationSpeed},`
|
|
493
|
+
+ ` RotationSpeedCached: ${this.accessory.context.RotationSpeed}`);
|
|
499
494
|
}
|
|
500
495
|
}
|
|
501
496
|
|
|
502
497
|
async pushSwingModeChanges(): Promise<void> {
|
|
503
|
-
this.debugLog(
|
|
498
|
+
await this.debugLog('pushSwingModeChanges');
|
|
504
499
|
if (this.Fan.SwingMode !== this.accessory.context.SwingMode) {
|
|
505
|
-
|
|
506
|
-
if (this.Fan.SwingMode === this.hap.Characteristic.SwingMode.SWING_ENABLED) {
|
|
507
|
-
parameter = 'on';
|
|
508
|
-
} else {
|
|
509
|
-
parameter = 'off';
|
|
510
|
-
}
|
|
500
|
+
const parameter = this.Fan.SwingMode === this.hap.Characteristic.SwingMode.SWING_ENABLED ? 'on' : 'off';
|
|
511
501
|
const bodyChange = JSON.stringify({
|
|
512
502
|
command: 'setOscillation',
|
|
513
503
|
parameter: `${parameter}`,
|
|
514
504
|
commandType: 'command',
|
|
515
505
|
});
|
|
516
|
-
this.debugLog(
|
|
506
|
+
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
517
507
|
try {
|
|
518
508
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
519
509
|
const deviceStatus: any = await body.json();
|
|
520
|
-
await this.
|
|
521
|
-
if (
|
|
522
|
-
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)}`);
|
|
523
513
|
await this.updateHomeKitCharacteristics();
|
|
524
514
|
} else {
|
|
525
515
|
await this.statusCode(statusCode);
|
|
526
516
|
await this.statusCode(deviceStatus.statusCode);
|
|
527
517
|
}
|
|
528
518
|
} catch (e: any) {
|
|
529
|
-
this.apiError(e);
|
|
530
|
-
this.errorLog(
|
|
531
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
519
|
+
await this.apiError(e);
|
|
520
|
+
await this.errorLog(`failed pushSwingModeChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
532
521
|
}
|
|
533
522
|
} else {
|
|
534
|
-
this.debugLog(
|
|
535
|
-
+ `SwingModeCached: ${this.accessory.context.SwingMode}`);
|
|
523
|
+
await this.debugLog(`No changes (pushSwingModeChanges), SwingMode: ${this.Fan.SwingMode},`
|
|
524
|
+
+ ` SwingModeCached: ${this.accessory.context.SwingMode}`);
|
|
536
525
|
}
|
|
537
526
|
}
|
|
538
527
|
|
|
@@ -540,10 +529,10 @@ export class Fan extends deviceBase {
|
|
|
540
529
|
* Handle requests to set the value of the "On" characteristic
|
|
541
530
|
*/
|
|
542
531
|
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
543
|
-
if (this.Fan.Active
|
|
544
|
-
this.
|
|
532
|
+
if (this.Fan.Active !== this.accessory.context.Active) {
|
|
533
|
+
await this.infoLog(`Set Active: ${value}`);
|
|
545
534
|
} else {
|
|
546
|
-
this.
|
|
535
|
+
await this.debugLog(`No Changes, Active: ${value}`);
|
|
547
536
|
}
|
|
548
537
|
|
|
549
538
|
this.Fan.Active = value;
|
|
@@ -554,10 +543,10 @@ export class Fan extends deviceBase {
|
|
|
554
543
|
* Handle requests to set the value of the "On" characteristic
|
|
555
544
|
*/
|
|
556
545
|
async RotationSpeedSet(value: CharacteristicValue): Promise<void> {
|
|
557
|
-
if (this.Fan.RotationSpeed
|
|
558
|
-
this.
|
|
546
|
+
if (this.Fan.RotationSpeed !== this.accessory.context.RotationSpeed) {
|
|
547
|
+
await this.infoLog(`Set RotationSpeed ${value}`);
|
|
559
548
|
} else {
|
|
560
|
-
this.
|
|
549
|
+
await this.debugLog(`No Changes, RotationSpeed: ${value}`);
|
|
561
550
|
}
|
|
562
551
|
|
|
563
552
|
this.Fan.RotationSpeed = value;
|
|
@@ -568,10 +557,10 @@ export class Fan extends deviceBase {
|
|
|
568
557
|
* Handle requests to set the value of the "On" characteristic
|
|
569
558
|
*/
|
|
570
559
|
async SwingModeSet(value: CharacteristicValue): Promise<void> {
|
|
571
|
-
if (this.Fan.SwingMode
|
|
572
|
-
this.
|
|
560
|
+
if (this.Fan.SwingMode !== this.accessory.context.SwingMode) {
|
|
561
|
+
await this.infoLog(`Set SwingMode ${value}`);
|
|
573
562
|
} else {
|
|
574
|
-
this.
|
|
563
|
+
await this.debugLog(`No Changes, SwingMode: ${value}`);
|
|
575
564
|
}
|
|
576
565
|
|
|
577
566
|
this.Fan.SwingMode = value;
|
|
@@ -582,10 +571,10 @@ export class Fan extends deviceBase {
|
|
|
582
571
|
* Handle requests to set the value of the "On" characteristic
|
|
583
572
|
*/
|
|
584
573
|
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
585
|
-
if (this.LightBulb.On
|
|
586
|
-
this.
|
|
574
|
+
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
575
|
+
await this.infoLog(`Set On: ${value}`);
|
|
587
576
|
} else {
|
|
588
|
-
this.
|
|
577
|
+
await this.debugLog(`No Changes, On: ${value}`);
|
|
589
578
|
}
|
|
590
579
|
|
|
591
580
|
this.LightBulb.On = value;
|
|
@@ -596,12 +585,14 @@ export class Fan extends deviceBase {
|
|
|
596
585
|
* Handle requests to set the value of the "Brightness" characteristic
|
|
597
586
|
*/
|
|
598
587
|
async BrightnessSet(value: CharacteristicValue): Promise<void> {
|
|
599
|
-
if (this.LightBulb.Brightness
|
|
600
|
-
this.
|
|
601
|
-
} else if (this.LightBulb.On) {
|
|
602
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Brightness: ${value}`);
|
|
588
|
+
if (this.LightBulb.On && (this.LightBulb.Brightness !== this.accessory.context.Brightness)) {
|
|
589
|
+
await this.infoLog(`Set Brightness: ${value}`);
|
|
603
590
|
} else {
|
|
604
|
-
|
|
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
|
+
}
|
|
605
596
|
}
|
|
606
597
|
|
|
607
598
|
this.LightBulb.Brightness = value;
|
|
@@ -610,68 +601,42 @@ export class Fan extends deviceBase {
|
|
|
610
601
|
|
|
611
602
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
612
603
|
// Active
|
|
613
|
-
|
|
614
|
-
this.
|
|
615
|
-
} else {
|
|
616
|
-
this.accessory.context.Active = this.Fan.Active;
|
|
617
|
-
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.Active, this.Fan.Active);
|
|
618
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Fan.Active}`);
|
|
619
|
-
}
|
|
604
|
+
await this.updateCharacteristic(this.Fan.Service, this.hap.Characteristic.Active,
|
|
605
|
+
this.Fan.Active, 'Active');
|
|
620
606
|
// RotationSpeed
|
|
621
|
-
|
|
622
|
-
this.
|
|
623
|
-
} else {
|
|
624
|
-
this.accessory.context.RotationSpeed = this.Fan.RotationSpeed;
|
|
625
|
-
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.RotationSpeed, this.Fan.RotationSpeed);
|
|
626
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.Fan.RotationSpeed}`);
|
|
627
|
-
}
|
|
607
|
+
await this.updateCharacteristic(this.Fan.Service, this.hap.Characteristic.RotationSpeed,
|
|
608
|
+
this.Fan.RotationSpeed, 'RotationSpeed');
|
|
628
609
|
// SwingMode
|
|
629
|
-
|
|
630
|
-
this.
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
this.
|
|
634
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic SwingMode: ${this.Fan.SwingMode}`);
|
|
635
|
-
}
|
|
636
|
-
// BateryLevel
|
|
637
|
-
if (this.Battery.BatteryLevel === undefined) {
|
|
638
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
639
|
-
} else {
|
|
640
|
-
this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
|
|
641
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
|
|
642
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
643
|
-
}
|
|
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');
|
|
644
615
|
// ChargingState
|
|
645
|
-
|
|
646
|
-
this.
|
|
647
|
-
} else {
|
|
648
|
-
this.accessory.context.ChargingState = this.Battery.ChargingState;
|
|
649
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.ChargingState, this.Battery.ChargingState);
|
|
650
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic ChargingState: ${this.Battery.ChargingState}`);
|
|
651
|
-
}
|
|
616
|
+
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.ChargingState,
|
|
617
|
+
this.Battery.ChargingState, 'ChargingState');
|
|
652
618
|
// StatusLowBattery
|
|
653
|
-
|
|
654
|
-
this.
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
this.
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
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');
|
|
661
627
|
}
|
|
662
628
|
|
|
663
629
|
async BLEPushConnection() {
|
|
664
630
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
665
|
-
this.warnLog(
|
|
631
|
+
await this.warnLog('Using OpenAPI Connection to Push Changes');
|
|
666
632
|
await this.openAPIpushChanges();
|
|
667
633
|
}
|
|
668
634
|
}
|
|
669
635
|
|
|
670
636
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
671
|
-
this.errorLog(
|
|
672
|
-
+ ` ${JSON.stringify(switchbot)}`);
|
|
637
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchbot)}`);
|
|
673
638
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
674
|
-
this.warnLog(
|
|
639
|
+
await this.warnLog('Using OpenAPI Connection to Refresh Status');
|
|
675
640
|
await this.openAPIRefreshStatus();
|
|
676
641
|
}
|
|
677
642
|
}
|
|
@@ -681,6 +646,8 @@ export class Fan extends deviceBase {
|
|
|
681
646
|
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
|
|
682
647
|
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.RotationSpeed, 0);
|
|
683
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);
|
|
684
651
|
}
|
|
685
652
|
}
|
|
686
653
|
|
|
@@ -688,5 +655,7 @@ export class Fan extends deviceBase {
|
|
|
688
655
|
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
|
|
689
656
|
this.Fan.Service.updateCharacteristic(this.hap.Characteristic.RotationSpeed, e);
|
|
690
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);
|
|
691
660
|
}
|
|
692
661
|
}
|