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