@switchbot/homebridge-switchbot 3.8.3 → 4.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/npm-version-script.cjs +81 -0
- package/.github/workflows/beta-release.yml +12 -4
- package/CHANGELOG.md +15 -1
- package/config.schema.json +583 -937
- package/dist/device/blindtilt.d.ts +1 -4
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +68 -66
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +1 -4
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +63 -59
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +1 -4
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +56 -65
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +1 -4
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +73 -80
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +1 -4
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +38 -38
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +1 -4
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +60 -60
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +6 -6
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +86 -20
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +1 -4
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +50 -51
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +1 -4
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +48 -48
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +1 -4
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +53 -55
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +1 -4
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +35 -35
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +1 -4
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +57 -65
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +1 -4
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +38 -39
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +1 -4
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +35 -35
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +1 -4
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +35 -35
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +1 -4
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +27 -27
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +1 -4
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +32 -32
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +1 -4
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +39 -40
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +1 -4
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +28 -28
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +1 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +31 -32
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +1 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +11 -12
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +9 -10
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +1 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +22 -23
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +6 -6
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +28 -14
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +12 -13
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +12 -15
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +27 -28
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +9 -10
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +9 -10
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +9 -22
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +154 -260
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +64 -82
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +0 -20
- package/dist/settings.js.map +1 -1
- package/dist/utils.d.ts +1 -102
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +0 -105
- package/dist/utils.js.map +1 -1
- package/docs/assets/highlight.css +42 -0
- package/docs/assets/main.js +1 -1
- package/docs/functions/default.html +1 -1
- package/docs/index.html +61 -50
- package/docs/media/security-privacy-bluetooth.png +0 -0
- package/package.json +5 -7
- package/src/device/blindtilt.ts +74 -74
- package/src/device/bot.ts +68 -67
- package/src/device/ceilinglight.ts +59 -70
- package/src/device/colorbulb.ts +79 -88
- package/src/device/contact.ts +40 -43
- package/src/device/curtain.ts +66 -68
- package/src/device/device.ts +86 -40
- package/src/device/fan.ts +52 -56
- package/src/device/hub.ts +50 -53
- package/src/device/humidifier.ts +56 -61
- package/src/device/iosensor.ts +37 -40
- package/src/device/lightstrip.ts +62 -72
- package/src/device/lock.ts +41 -45
- package/src/device/meter.ts +37 -40
- package/src/device/meterplus.ts +37 -40
- package/src/device/motion.ts +29 -32
- package/src/device/plug.ts +34 -37
- package/src/device/robotvacuumcleaner.ts +41 -49
- package/src/device/waterdetector.ts +30 -33
- package/src/irdevice/airconditioner.ts +33 -35
- package/src/irdevice/airpurifier.ts +12 -13
- package/src/irdevice/camera.ts +10 -11
- package/src/irdevice/fan.ts +24 -25
- package/src/irdevice/irdevice.ts +31 -27
- package/src/irdevice/light.ts +14 -15
- package/src/irdevice/other.ts +14 -17
- package/src/irdevice/tv.ts +28 -29
- package/src/irdevice/vacuumcleaner.ts +10 -11
- package/src/irdevice/waterheater.ts +10 -11
- package/src/platform.ts +178 -287
- package/src/settings.ts +67 -88
- package/src/utils.ts +2 -106
- package/dist/types/bledevicestatus.d.ts +0 -281
- package/dist/types/bledevicestatus.d.ts.map +0 -1
- package/dist/types/bledevicestatus.js +0 -2
- package/dist/types/bledevicestatus.js.map +0 -1
- package/dist/types/devicelist.d.ts +0 -89
- package/dist/types/devicelist.d.ts.map +0 -1
- package/dist/types/devicelist.js +0 -6
- package/dist/types/devicelist.js.map +0 -1
- package/dist/types/deviceresponse.d.ts +0 -13
- package/dist/types/deviceresponse.d.ts.map +0 -1
- package/dist/types/deviceresponse.js +0 -2
- package/dist/types/deviceresponse.js.map +0 -1
- package/dist/types/devicestatus.d.ts +0 -149
- package/dist/types/devicestatus.d.ts.map +0 -1
- package/dist/types/devicestatus.js +0 -3
- package/dist/types/devicestatus.js.map +0 -1
- package/dist/types/devicewebhookstatus.d.ts +0 -156
- package/dist/types/devicewebhookstatus.d.ts.map +0 -1
- package/dist/types/devicewebhookstatus.js +0 -2
- package/dist/types/devicewebhookstatus.js.map +0 -1
- package/dist/types/irdevicelist.d.ts +0 -10
- package/dist/types/irdevicelist.d.ts.map +0 -1
- package/dist/types/irdevicelist.js +0 -2
- package/dist/types/irdevicelist.js.map +0 -1
- package/dist/types/pushbody.d.ts +0 -6
- package/dist/types/pushbody.d.ts.map +0 -1
- package/dist/types/pushbody.js +0 -2
- package/dist/types/pushbody.js.map +0 -1
- package/src/types/bledevicestatus.ts +0 -303
- package/src/types/devicelist.ts +0 -124
- package/src/types/deviceresponse.ts +0 -14
- package/src/types/devicestatus.ts +0 -178
- package/src/types/devicewebhookstatus.ts +0 -191
- package/src/types/irdevicelist.ts +0 -15
- package/src/types/pushbody.ts +0 -9
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* airconditioners.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { bodyChange, irdevice } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
|
-
import type { irDevicesConfig } from '../settings.js'
|
|
9
|
-
import type { irdevice } from '../types/irdevicelist.js'
|
|
9
|
+
import type { irAirConfig, irDevicesConfig } from '../settings.js'
|
|
10
10
|
|
|
11
11
|
import { irdeviceBase } from './irdevice.js'
|
|
12
12
|
|
|
@@ -124,8 +124,8 @@ export class AirConditioner extends irdeviceBase {
|
|
|
124
124
|
|
|
125
125
|
// Initialize HumiditySensor property
|
|
126
126
|
|
|
127
|
-
if (this.device.
|
|
128
|
-
const meterUuid = this.platform.api.hap.uuid.generate(`${
|
|
127
|
+
if ((this.device as irAirConfig).meterType && (this.device as irAirConfig).meterId) {
|
|
128
|
+
const meterUuid = this.platform.api.hap.uuid.generate(`${(device as irAirConfig).meterId}-${(device as irAirConfig).meterType}`)
|
|
129
129
|
this.meter = this.platform.accessories.find(accessory => accessory.UUID === meterUuid)
|
|
130
130
|
accessory.context.HumiditySensor = accessory.context.HumiditySensor ?? {}
|
|
131
131
|
this.HumiditySensor = {
|
|
@@ -136,8 +136,8 @@ export class AirConditioner extends irdeviceBase {
|
|
|
136
136
|
accessory.context.HumiditySensor = this.HumiditySensor as object
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
if (this.device.
|
|
140
|
-
const meterUuid = this.platform.api.hap.uuid.generate(`${
|
|
139
|
+
if ((this.device as irAirConfig).meterType && (this.device as irAirConfig).meterId) {
|
|
140
|
+
const meterUuid = this.platform.api.hap.uuid.generate(`${(device as irAirConfig).meterId}-${(device as irAirConfig).meterType}`)
|
|
141
141
|
this.meter = this.platform.accessories.find(accessory => accessory.UUID === meterUuid)
|
|
142
142
|
}
|
|
143
143
|
|
|
@@ -162,11 +162,11 @@ export class AirConditioner extends irdeviceBase {
|
|
|
162
162
|
if (this.HeaterCooler.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
|
|
163
163
|
const commandType: string = await this.commandType()
|
|
164
164
|
const command: string = await this.commandOn()
|
|
165
|
-
const bodyChange =
|
|
165
|
+
const bodyChange: bodyChange = {
|
|
166
166
|
command,
|
|
167
167
|
parameter: 'default',
|
|
168
168
|
commandType,
|
|
169
|
-
}
|
|
169
|
+
}
|
|
170
170
|
await this.pushChanges(bodyChange)
|
|
171
171
|
}
|
|
172
172
|
}
|
|
@@ -176,11 +176,11 @@ export class AirConditioner extends irdeviceBase {
|
|
|
176
176
|
if (this.HeaterCooler.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOff) {
|
|
177
177
|
const commandType: string = await this.commandType()
|
|
178
178
|
const command: string = await this.commandOff()
|
|
179
|
-
const bodyChange =
|
|
179
|
+
const bodyChange: bodyChange = {
|
|
180
180
|
command,
|
|
181
181
|
parameter: 'default',
|
|
182
182
|
commandType,
|
|
183
|
-
}
|
|
183
|
+
}
|
|
184
184
|
await this.pushChanges(bodyChange)
|
|
185
185
|
}
|
|
186
186
|
}
|
|
@@ -219,12 +219,11 @@ export class AirConditioner extends irdeviceBase {
|
|
|
219
219
|
const parameter = `${this.HeaterCooler.ThresholdTemperature},${this.CurrentMode},${this.CurrentFanSpeed},${this.state}`
|
|
220
220
|
|
|
221
221
|
await this.UpdateCurrentHeaterCoolerState()
|
|
222
|
-
const bodyChange =
|
|
222
|
+
const bodyChange: bodyChange = {
|
|
223
223
|
command: 'setAll',
|
|
224
224
|
parameter: `${parameter}`,
|
|
225
225
|
commandType: 'command',
|
|
226
|
-
}
|
|
227
|
-
|
|
226
|
+
}
|
|
228
227
|
await this.pushChanges(bodyChange)
|
|
229
228
|
}
|
|
230
229
|
|
|
@@ -254,38 +253,38 @@ export class AirConditioner extends irdeviceBase {
|
|
|
254
253
|
this.HeaterCooler.RotationSpeed = this.HeaterCooler.RotationSpeed || this.accessory.context.RotationSpeed
|
|
255
254
|
}
|
|
256
255
|
|
|
257
|
-
if (this.device.
|
|
258
|
-
this.hide_automode = this.device.
|
|
256
|
+
if ((this.device as irAirConfig).hide_automode) {
|
|
257
|
+
this.hide_automode = (this.device as irAirConfig).hide_automode
|
|
259
258
|
this.accessory.context.hide_automode = this.hide_automode
|
|
260
259
|
} else {
|
|
261
|
-
this.hide_automode = this.device.
|
|
260
|
+
this.hide_automode = (this.device as irAirConfig).hide_automode
|
|
262
261
|
this.accessory.context.hide_automode = this.hide_automode
|
|
263
262
|
}
|
|
264
263
|
|
|
265
|
-
if (this.device.
|
|
266
|
-
this.set_max_heat = this.device.
|
|
264
|
+
if ((this.device as irAirConfig).set_max_heat) {
|
|
265
|
+
this.set_max_heat = (this.device as irAirConfig).set_max_heat
|
|
267
266
|
this.accessory.context.set_max_heat = this.set_max_heat
|
|
268
267
|
} else {
|
|
269
268
|
this.set_max_heat = 35
|
|
270
269
|
this.accessory.context.set_max_heat = this.set_max_heat
|
|
271
270
|
}
|
|
272
|
-
if (this.device.
|
|
273
|
-
this.set_min_heat = this.device.
|
|
271
|
+
if ((this.device as irAirConfig).set_min_heat) {
|
|
272
|
+
this.set_min_heat = (this.device as irAirConfig).set_min_heat
|
|
274
273
|
this.accessory.context.set_min_heat = this.set_min_heat
|
|
275
274
|
} else {
|
|
276
275
|
this.set_min_heat = 0
|
|
277
276
|
this.accessory.context.set_min_heat = this.set_min_heat
|
|
278
277
|
}
|
|
279
278
|
|
|
280
|
-
if (this.device.
|
|
281
|
-
this.set_max_cool = this.device.
|
|
279
|
+
if ((this.device as irAirConfig).set_max_cool) {
|
|
280
|
+
this.set_max_cool = (this.device as irAirConfig).set_max_cool
|
|
282
281
|
this.accessory.context.set_max_cool = this.set_max_cool
|
|
283
282
|
} else {
|
|
284
283
|
this.set_max_cool = 35
|
|
285
284
|
this.accessory.context.set_max_cool = this.set_max_cool
|
|
286
285
|
}
|
|
287
|
-
if (this.device.
|
|
288
|
-
this.set_min_cool = this.device.
|
|
286
|
+
if ((this.device as irAirConfig).set_min_cool) {
|
|
287
|
+
this.set_min_cool = (this.device as irAirConfig).set_min_cool
|
|
289
288
|
this.accessory.context.set_min_cool = this.set_min_cool
|
|
290
289
|
} else {
|
|
291
290
|
this.set_min_cool = 0
|
|
@@ -317,14 +316,13 @@ export class AirConditioner extends irdeviceBase {
|
|
|
317
316
|
if (this.device.connectionType === 'OpenAPI' && !this.disablePushDetail) {
|
|
318
317
|
await this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`)
|
|
319
318
|
try {
|
|
320
|
-
const { body
|
|
321
|
-
const deviceStatus: any = await body
|
|
322
|
-
await this.pushStatusCodes(
|
|
323
|
-
if (await this.successfulStatusCodes(
|
|
324
|
-
await this.successfulPushChange(
|
|
319
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
320
|
+
const deviceStatus: any = await body
|
|
321
|
+
await this.pushStatusCodes(deviceStatus)
|
|
322
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
323
|
+
await this.successfulPushChange(deviceStatus, bodyChange)
|
|
325
324
|
await this.updateHomeKitCharacteristics()
|
|
326
325
|
} else {
|
|
327
|
-
await this.statusCode(statusCode)
|
|
328
326
|
await this.statusCode(deviceStatus.statusCode)
|
|
329
327
|
}
|
|
330
328
|
} catch (e: any) {
|
|
@@ -527,10 +525,10 @@ export class AirConditioner extends irdeviceBase {
|
|
|
527
525
|
}
|
|
528
526
|
|
|
529
527
|
async getAirConditionerConfigSettings(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): Promise<void> {
|
|
530
|
-
accessory.context.hide_automode = this.hide_automode = device.
|
|
531
|
-
accessory.context.set_max_heat = this.set_max_heat = device.
|
|
532
|
-
accessory.context.set_min_heat = this.set_min_heat = device.
|
|
533
|
-
accessory.context.set_max_cool = this.set_max_cool = device.
|
|
534
|
-
accessory.context.set_min_cool = this.set_min_cool = device.
|
|
528
|
+
accessory.context.hide_automode = this.hide_automode = (device as irAirConfig).hide_automode
|
|
529
|
+
accessory.context.set_max_heat = this.set_max_heat = (device as irAirConfig).set_max_heat ?? 35
|
|
530
|
+
accessory.context.set_min_heat = this.set_min_heat = (device as irAirConfig).set_min_heat ?? 0
|
|
531
|
+
accessory.context.set_max_cool = this.set_max_cool = (device as irAirConfig).set_max_cool ?? 35
|
|
532
|
+
accessory.context.set_min_cool = this.set_min_cool = (device as irAirConfig).set_min_cool ?? 0
|
|
535
533
|
}
|
|
536
534
|
}
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* airpurifier.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { bodyChange, irdevice } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
9
|
import type { irDevicesConfig } from '../settings.js'
|
|
9
|
-
import type { irdevice } from '../types/irdevicelist.js'
|
|
10
10
|
|
|
11
11
|
import { irdeviceBase } from './irdevice.js'
|
|
12
12
|
|
|
@@ -149,11 +149,11 @@ export class AirPurifier extends irdeviceBase {
|
|
|
149
149
|
if (this.AirPurifier.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
|
|
150
150
|
const commandType: string = await this.commandType()
|
|
151
151
|
const command: string = await this.commandOn()
|
|
152
|
-
const bodyChange =
|
|
152
|
+
const bodyChange: bodyChange = {
|
|
153
153
|
command,
|
|
154
154
|
parameter: 'default',
|
|
155
155
|
commandType,
|
|
156
|
-
}
|
|
156
|
+
}
|
|
157
157
|
await this.pushChanges(bodyChange)
|
|
158
158
|
}
|
|
159
159
|
}
|
|
@@ -163,11 +163,11 @@ export class AirPurifier extends irdeviceBase {
|
|
|
163
163
|
if (this.AirPurifier.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOn) {
|
|
164
164
|
const commandType: string = await this.commandType()
|
|
165
165
|
const command: string = await this.commandOff()
|
|
166
|
-
const bodyChange =
|
|
166
|
+
const bodyChange: bodyChange = {
|
|
167
167
|
command,
|
|
168
168
|
parameter: 'default',
|
|
169
169
|
commandType,
|
|
170
|
-
}
|
|
170
|
+
}
|
|
171
171
|
await this.pushChanges(bodyChange)
|
|
172
172
|
}
|
|
173
173
|
}
|
|
@@ -191,11 +191,11 @@ export class AirPurifier extends irdeviceBase {
|
|
|
191
191
|
this.CurrentAPFanSpeed = this.CurrentFanSpeed ?? 1
|
|
192
192
|
this.APActive = this.AirPurifier.Active === 1 ? 'on' : 'off'
|
|
193
193
|
const parameter = `${this.CurrentAPTemp},${this.CurrentAPMode},${this.CurrentAPFanSpeed},${this.APActive}`
|
|
194
|
-
const bodyChange =
|
|
194
|
+
const bodyChange: bodyChange = {
|
|
195
195
|
command: 'setAll',
|
|
196
196
|
parameter: `${parameter}`,
|
|
197
197
|
commandType: 'command',
|
|
198
|
-
}
|
|
198
|
+
}
|
|
199
199
|
if (this.AirPurifier.Active === 1) {
|
|
200
200
|
if ((Number(this.TemperatureSensor!.CurrentTemperature) || 24) < (this.LastTemperature || 30)) {
|
|
201
201
|
this.AirPurifier.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.COOLING
|
|
@@ -213,14 +213,13 @@ export class AirPurifier extends irdeviceBase {
|
|
|
213
213
|
if (this.device.connectionType === 'OpenAPI') {
|
|
214
214
|
this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`)
|
|
215
215
|
try {
|
|
216
|
-
const { body
|
|
217
|
-
const deviceStatus: any = await body
|
|
218
|
-
await this.pushStatusCodes(
|
|
219
|
-
if (await this.successfulStatusCodes(
|
|
220
|
-
await this.successfulPushChange(
|
|
216
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
217
|
+
const deviceStatus: any = await body
|
|
218
|
+
await this.pushStatusCodes(deviceStatus)
|
|
219
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
220
|
+
await this.successfulPushChange(deviceStatus, bodyChange)
|
|
221
221
|
await this.updateHomeKitCharacteristics()
|
|
222
222
|
} else {
|
|
223
|
-
await this.statusCode(statusCode)
|
|
224
223
|
await this.statusCode(deviceStatus.statusCode)
|
|
225
224
|
}
|
|
226
225
|
} catch (e: any) {
|
package/src/irdevice/camera.ts
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* camera.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { bodyChange, irdevice } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
9
|
import type { irDevicesConfig } from '../settings.js'
|
|
9
|
-
import type { irdevice } from '../types/irdevicelist.js'
|
|
10
10
|
|
|
11
11
|
import { irdeviceBase } from './irdevice.js'
|
|
12
12
|
|
|
@@ -72,11 +72,11 @@ export class Camera extends irdeviceBase {
|
|
|
72
72
|
if (this.Switch.On && !this.disablePushOn) {
|
|
73
73
|
const commandType: string = await this.commandType()
|
|
74
74
|
const command: string = await this.commandOn()
|
|
75
|
-
const bodyChange =
|
|
75
|
+
const bodyChange: bodyChange = {
|
|
76
76
|
command,
|
|
77
77
|
parameter: 'default',
|
|
78
78
|
commandType,
|
|
79
|
-
}
|
|
79
|
+
}
|
|
80
80
|
await this.pushChanges(bodyChange)
|
|
81
81
|
}
|
|
82
82
|
}
|
|
@@ -86,11 +86,11 @@ export class Camera extends irdeviceBase {
|
|
|
86
86
|
if (!this.Switch.On && !this.disablePushOff) {
|
|
87
87
|
const commandType: string = await this.commandType()
|
|
88
88
|
const command: string = await this.commandOff()
|
|
89
|
-
const bodyChange =
|
|
89
|
+
const bodyChange: bodyChange = {
|
|
90
90
|
command,
|
|
91
91
|
parameter: 'default',
|
|
92
92
|
commandType,
|
|
93
|
-
}
|
|
93
|
+
}
|
|
94
94
|
await this.pushChanges(bodyChange)
|
|
95
95
|
}
|
|
96
96
|
}
|
|
@@ -100,14 +100,13 @@ export class Camera extends irdeviceBase {
|
|
|
100
100
|
if (this.device.connectionType === 'OpenAPI') {
|
|
101
101
|
this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`)
|
|
102
102
|
try {
|
|
103
|
-
const { body
|
|
104
|
-
const deviceStatus: any = await body
|
|
105
|
-
await this.pushStatusCodes(
|
|
106
|
-
if (await this.successfulStatusCodes(
|
|
107
|
-
await this.successfulPushChange(
|
|
103
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
104
|
+
const deviceStatus: any = await body
|
|
105
|
+
await this.pushStatusCodes(deviceStatus)
|
|
106
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
107
|
+
await this.successfulPushChange(deviceStatus, bodyChange)
|
|
108
108
|
await this.updateHomeKitCharacteristics()
|
|
109
109
|
} else {
|
|
110
|
-
await this.statusCode(statusCode)
|
|
111
110
|
await this.statusCode(deviceStatus.statusCode)
|
|
112
111
|
}
|
|
113
112
|
} catch (e: any) {
|
package/src/irdevice/fan.ts
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* fan.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { bodyChange, irdevice } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
|
-
import type { irDevicesConfig } from '../settings.js'
|
|
9
|
-
import type { irdevice } from '../types/irdevicelist.js'
|
|
9
|
+
import type { irDevicesConfig, irFanConfig } from '../settings.js'
|
|
10
10
|
|
|
11
11
|
import { irdeviceBase } from './irdevice.js'
|
|
12
12
|
|
|
@@ -51,16 +51,16 @@ export class IRFan extends irdeviceBase {
|
|
|
51
51
|
return this.Fan.Active
|
|
52
52
|
}).onSet(this.ActiveSet.bind(this))
|
|
53
53
|
|
|
54
|
-
if (device.
|
|
54
|
+
if ((device as irFanConfig).rotation_speed) {
|
|
55
55
|
// handle Rotation Speed events using the RotationSpeed characteristic
|
|
56
56
|
this.Fan.Service.getCharacteristic(this.hap.Characteristic.RotationSpeed).setProps({
|
|
57
|
-
minStep: device.
|
|
58
|
-
minValue: device.
|
|
59
|
-
maxValue: device.
|
|
57
|
+
minStep: (device as irFanConfig).set_minStep ?? 1,
|
|
58
|
+
minValue: (device as irFanConfig).set_min ?? 1,
|
|
59
|
+
maxValue: (device as irFanConfig).set_max ?? 100,
|
|
60
60
|
}).onGet(() => {
|
|
61
61
|
return this.Fan.RotationSpeed
|
|
62
62
|
}).onSet(this.RotationSpeedSet.bind(this))
|
|
63
|
-
} else if (this.Fan.Service.testCharacteristic(this.hap.Characteristic.RotationSpeed) && !device.
|
|
63
|
+
} else if (this.Fan.Service.testCharacteristic(this.hap.Characteristic.RotationSpeed) && !(device as irFanConfig).swing_mode) {
|
|
64
64
|
const characteristic = this.Fan.Service.getCharacteristic(this.hap.Characteristic.RotationSpeed)
|
|
65
65
|
this.Fan.Service.removeCharacteristic(characteristic)
|
|
66
66
|
this.debugLog('Rotation Speed Characteristic was removed.')
|
|
@@ -68,12 +68,12 @@ export class IRFan extends irdeviceBase {
|
|
|
68
68
|
this.debugLog(`RotationSpeed Characteristic was not removed/added, Clear Cache on ${this.accessory.displayName} to remove Chracteristic`)
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
if (device.
|
|
71
|
+
if ((device as irFanConfig).swing_mode) {
|
|
72
72
|
// handle Osolcation events using the SwingMode characteristic
|
|
73
73
|
this.Fan.Service.getCharacteristic(this.hap.Characteristic.SwingMode).onGet(() => {
|
|
74
74
|
return this.Fan.SwingMode
|
|
75
75
|
}).onSet(this.SwingModeSet.bind(this))
|
|
76
|
-
} else if (this.Fan.Service.testCharacteristic(this.hap.Characteristic.SwingMode) && !device.
|
|
76
|
+
} else if (this.Fan.Service.testCharacteristic(this.hap.Characteristic.SwingMode) && !(device as irFanConfig).swing_mode) {
|
|
77
77
|
const characteristic = this.Fan.Service.getCharacteristic(this.hap.Characteristic.SwingMode)
|
|
78
78
|
this.Fan.Service.removeCharacteristic(characteristic)
|
|
79
79
|
this.debugLog('Swing Mode Characteristic was removed.')
|
|
@@ -136,11 +136,11 @@ export class IRFan extends irdeviceBase {
|
|
|
136
136
|
if (this.Fan.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
|
|
137
137
|
const commandType: string = await this.commandType()
|
|
138
138
|
const command: string = await this.commandOn()
|
|
139
|
-
const bodyChange =
|
|
139
|
+
const bodyChange: bodyChange = {
|
|
140
140
|
command,
|
|
141
141
|
parameter: 'default',
|
|
142
142
|
commandType,
|
|
143
|
-
}
|
|
143
|
+
}
|
|
144
144
|
await this.pushChanges(bodyChange)
|
|
145
145
|
}
|
|
146
146
|
}
|
|
@@ -150,39 +150,39 @@ export class IRFan extends irdeviceBase {
|
|
|
150
150
|
if (this.Fan.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOff) {
|
|
151
151
|
const commandType: string = await this.commandType()
|
|
152
152
|
const command: string = await this.commandOff()
|
|
153
|
-
const bodyChange =
|
|
153
|
+
const bodyChange: bodyChange = {
|
|
154
154
|
command,
|
|
155
155
|
parameter: 'default',
|
|
156
156
|
commandType,
|
|
157
|
-
}
|
|
157
|
+
}
|
|
158
158
|
await this.pushChanges(bodyChange)
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
async pushFanSpeedUpChanges(): Promise<void> {
|
|
163
|
-
const bodyChange =
|
|
163
|
+
const bodyChange: bodyChange = {
|
|
164
164
|
command: 'highSpeed',
|
|
165
165
|
parameter: 'default',
|
|
166
166
|
commandType: 'command',
|
|
167
|
-
}
|
|
167
|
+
}
|
|
168
168
|
await this.pushChanges(bodyChange)
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
async pushFanSpeedDownChanges(): Promise<void> {
|
|
172
|
-
const bodyChange =
|
|
172
|
+
const bodyChange: bodyChange = {
|
|
173
173
|
command: 'lowSpeed',
|
|
174
174
|
parameter: 'default',
|
|
175
175
|
commandType: 'command',
|
|
176
|
-
}
|
|
176
|
+
}
|
|
177
177
|
await this.pushChanges(bodyChange)
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
async pushFanSwingChanges(): Promise<void> {
|
|
181
|
-
const bodyChange =
|
|
181
|
+
const bodyChange: bodyChange = {
|
|
182
182
|
command: 'swing',
|
|
183
183
|
parameter: 'default',
|
|
184
184
|
commandType: 'command',
|
|
185
|
-
}
|
|
185
|
+
}
|
|
186
186
|
await this.pushChanges(bodyChange)
|
|
187
187
|
}
|
|
188
188
|
|
|
@@ -191,14 +191,13 @@ export class IRFan extends irdeviceBase {
|
|
|
191
191
|
if (this.device.connectionType === 'OpenAPI') {
|
|
192
192
|
this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`)
|
|
193
193
|
try {
|
|
194
|
-
const { body
|
|
195
|
-
const deviceStatus: any = await body
|
|
196
|
-
await this.pushStatusCodes(
|
|
197
|
-
if (await this.successfulStatusCodes(
|
|
198
|
-
await this.successfulPushChange(
|
|
194
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
195
|
+
const deviceStatus: any = await body
|
|
196
|
+
await this.pushStatusCodes(deviceStatus)
|
|
197
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
198
|
+
await this.successfulPushChange(deviceStatus, bodyChange)
|
|
199
199
|
await this.updateHomeKitCharacteristics()
|
|
200
200
|
} else {
|
|
201
|
-
await this.statusCode(statusCode)
|
|
202
201
|
await this.statusCode(deviceStatus.statusCode)
|
|
203
202
|
}
|
|
204
203
|
} catch (e: any) {
|
package/src/irdevice/irdevice.ts
CHANGED
|
@@ -3,14 +3,10 @@
|
|
|
3
3
|
* device.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { API, CharacteristicValue, HAP, Logging, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { bodyChange, irdevice } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
|
-
import type { irDevicesConfig, SwitchBotPlatformConfig } from '../settings.js'
|
|
9
|
-
import type { irdevice } from '../types/irdevicelist.js'
|
|
10
|
-
|
|
11
|
-
import { request } from 'undici'
|
|
12
|
-
|
|
13
|
-
import { Devices } from '../settings.js'
|
|
9
|
+
import type { irAirConfig, irDevicesConfig, irFanConfig, irLightConfig, irOtherConfig, SwitchBotPlatformConfig } from '../settings.js'
|
|
14
10
|
|
|
15
11
|
export abstract class irdeviceBase {
|
|
16
12
|
public readonly api: API
|
|
@@ -82,18 +78,30 @@ export abstract class irdeviceBase {
|
|
|
82
78
|
device.disablePushOff === true && { disablePushOff: device.disablePushOff },
|
|
83
79
|
device.disablePushDetail === true && { disablePushDetail: device.disablePushDetail },
|
|
84
80
|
)
|
|
81
|
+
let deviceSpecificConfig = {}
|
|
82
|
+
switch (device.configRemoteType) {
|
|
83
|
+
case 'Fan':
|
|
84
|
+
case 'DIY Fan':
|
|
85
|
+
deviceSpecificConfig = device as irFanConfig
|
|
86
|
+
break
|
|
87
|
+
case 'Light':
|
|
88
|
+
case 'DIY Light':
|
|
89
|
+
deviceSpecificConfig = device as irLightConfig
|
|
90
|
+
break
|
|
91
|
+
case 'Air Conditioner':
|
|
92
|
+
case 'DIY Air Conditioner':
|
|
93
|
+
deviceSpecificConfig = device as irAirConfig
|
|
94
|
+
break
|
|
95
|
+
case 'Others':
|
|
96
|
+
deviceSpecificConfig = device as irOtherConfig
|
|
97
|
+
break
|
|
98
|
+
default:
|
|
99
|
+
break
|
|
100
|
+
}
|
|
85
101
|
const config = Object.assign(
|
|
86
102
|
{},
|
|
87
103
|
deviceConfig,
|
|
88
|
-
|
|
89
|
-
device.irpur,
|
|
90
|
-
device.ircam,
|
|
91
|
-
device.irfan,
|
|
92
|
-
device.irlight,
|
|
93
|
-
device.other,
|
|
94
|
-
device.irtv,
|
|
95
|
-
device.irvc,
|
|
96
|
-
device.irwh,
|
|
104
|
+
deviceSpecificConfig,
|
|
97
105
|
)
|
|
98
106
|
if (Object.keys(config).length !== 0) {
|
|
99
107
|
this.debugSuccessLog(`Config: ${JSON.stringify(config)}`)
|
|
@@ -129,16 +137,13 @@ export abstract class irdeviceBase {
|
|
|
129
137
|
this.debugSuccessLog(`version: ${accessory.context.version}`)
|
|
130
138
|
}
|
|
131
139
|
|
|
132
|
-
async pushChangeRequest(bodyChange:
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
method: 'POST',
|
|
136
|
-
headers: this.platform.generateHeaders(),
|
|
137
|
-
})
|
|
140
|
+
async pushChangeRequest(bodyChange: bodyChange): Promise<{ body: any, statusCode: number }> {
|
|
141
|
+
const { response, statusCode } = await this.platform.switchBotAPI.controlDevice(this.device.deviceId, bodyChange.command, bodyChange.parameter, bodyChange.commandType)
|
|
142
|
+
return { body: response, statusCode }
|
|
138
143
|
}
|
|
139
144
|
|
|
140
|
-
async successfulStatusCodes(
|
|
141
|
-
return (
|
|
145
|
+
async successfulStatusCodes(deviceStatus: any) {
|
|
146
|
+
return (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)
|
|
142
147
|
}
|
|
143
148
|
|
|
144
149
|
/**
|
|
@@ -163,14 +168,13 @@ export abstract class irdeviceBase {
|
|
|
163
168
|
}
|
|
164
169
|
}
|
|
165
170
|
|
|
166
|
-
async pushStatusCodes(
|
|
167
|
-
await this.debugWarnLog(`statusCode: ${statusCode}`)
|
|
171
|
+
async pushStatusCodes(deviceStatus: any) {
|
|
168
172
|
await this.debugWarnLog(`deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
169
173
|
await this.debugWarnLog(`deviceStatus statusCode: ${deviceStatus.statusCode}`)
|
|
170
174
|
}
|
|
171
175
|
|
|
172
|
-
async successfulPushChange(
|
|
173
|
-
this.debugSuccessLog(`
|
|
176
|
+
async successfulPushChange(deviceStatus: any, bodyChange: any) {
|
|
177
|
+
this.debugSuccessLog(`deviceStatus StatusCode: ${deviceStatus.statusCode}`)
|
|
174
178
|
this.successLog(`request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`)
|
|
175
179
|
}
|
|
176
180
|
|
package/src/irdevice/light.ts
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* light.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { bodyChange, irdevice } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
|
-
import type { irDevicesConfig } from '../settings.js'
|
|
9
|
-
import type { irdevice } from '../types/irdevicelist.js'
|
|
9
|
+
import type { irDevicesConfig, irLightConfig } from '../settings.js'
|
|
10
10
|
|
|
11
11
|
import { irdeviceBase } from './irdevice.js'
|
|
12
12
|
|
|
@@ -46,7 +46,7 @@ export class Light extends irdeviceBase {
|
|
|
46
46
|
// Set category
|
|
47
47
|
accessory.category = this.hap.Categories.LIGHTBULB
|
|
48
48
|
|
|
49
|
-
if (!device.
|
|
49
|
+
if (!(device as irLightConfig).stateless) {
|
|
50
50
|
// Initialize LightBulb Service
|
|
51
51
|
accessory.context.LightBulb = accessory.context.LightBulb ?? {}
|
|
52
52
|
this.LightBulb = {
|
|
@@ -170,11 +170,11 @@ export class Light extends irdeviceBase {
|
|
|
170
170
|
if (On === true && this.disablePushOn === false) {
|
|
171
171
|
const commandType: string = await this.commandType()
|
|
172
172
|
const command: string = await this.commandOn()
|
|
173
|
-
const bodyChange =
|
|
173
|
+
const bodyChange: bodyChange = {
|
|
174
174
|
command,
|
|
175
175
|
parameter: 'default',
|
|
176
176
|
commandType,
|
|
177
|
-
}
|
|
177
|
+
}
|
|
178
178
|
await this.pushChanges(bodyChange, On)
|
|
179
179
|
}
|
|
180
180
|
}
|
|
@@ -184,11 +184,11 @@ export class Light extends irdeviceBase {
|
|
|
184
184
|
if (On === false && this.disablePushOff === false) {
|
|
185
185
|
const commandType: string = await this.commandType()
|
|
186
186
|
const command: string = await this.commandOff()
|
|
187
|
-
const bodyChange =
|
|
187
|
+
const bodyChange: bodyChange = {
|
|
188
188
|
command,
|
|
189
189
|
parameter: 'default',
|
|
190
190
|
commandType,
|
|
191
|
-
}
|
|
191
|
+
}
|
|
192
192
|
await this.pushChanges(bodyChange, On)
|
|
193
193
|
}
|
|
194
194
|
}
|
|
@@ -198,15 +198,14 @@ export class Light extends irdeviceBase {
|
|
|
198
198
|
if (this.device.connectionType === 'OpenAPI') {
|
|
199
199
|
this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`)
|
|
200
200
|
try {
|
|
201
|
-
const { body
|
|
202
|
-
const deviceStatus: any = await body
|
|
203
|
-
await this.pushStatusCodes(
|
|
204
|
-
if (await this.successfulStatusCodes(
|
|
205
|
-
await this.successfulPushChange(
|
|
201
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
202
|
+
const deviceStatus: any = await body
|
|
203
|
+
await this.pushStatusCodes(deviceStatus)
|
|
204
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
205
|
+
await this.successfulPushChange(deviceStatus, bodyChange)
|
|
206
206
|
this.accessory.context.On = On
|
|
207
207
|
await this.updateHomeKitCharacteristics()
|
|
208
208
|
} else {
|
|
209
|
-
await this.statusCode(statusCode)
|
|
210
209
|
await this.statusCode(deviceStatus.statusCode)
|
|
211
210
|
}
|
|
212
211
|
} catch (e: any) {
|
|
@@ -220,7 +219,7 @@ export class Light extends irdeviceBase {
|
|
|
220
219
|
|
|
221
220
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
222
221
|
await this.debugLog('updateHomeKitCharacteristics')
|
|
223
|
-
if (!this.device.
|
|
222
|
+
if (!(this.device as irLightConfig).stateless && this.LightBulb?.Service) {
|
|
224
223
|
// On
|
|
225
224
|
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.On, this.LightBulb.On, 'On')
|
|
226
225
|
} else {
|
|
@@ -236,7 +235,7 @@ export class Light extends irdeviceBase {
|
|
|
236
235
|
}
|
|
237
236
|
|
|
238
237
|
async apiError(e: any): Promise<void> {
|
|
239
|
-
if (!this.device.
|
|
238
|
+
if (!(this.device as irLightConfig).stateless) {
|
|
240
239
|
this.LightBulb?.Service.updateCharacteristic(this.hap.Characteristic.On, e)
|
|
241
240
|
} else {
|
|
242
241
|
this.ProgrammableSwitchOn?.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e)
|