@switchbot/homebridge-switchbot 3.7.1-beta.2 → 3.7.1-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +14 -0
- package/assets/security-privacy-bluetooth.png +0 -0
- package/config.schema.json +74 -2
- package/dist/device/blindtilt.d.ts +21 -9
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +167 -96
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot-old.d.ts +132 -0
- package/dist/device/bot-old.d.ts.map +1 -0
- package/dist/device/bot-old.js +1482 -0
- package/dist/device/bot-old.js.map +1 -0
- package/dist/device/bot.d.ts +10 -9
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +186 -187
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +14 -13
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +87 -97
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +13 -12
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +92 -105
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +6 -5
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +71 -68
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +17 -5
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +184 -118
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +18 -18
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +33 -36
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +9 -8
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +94 -101
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +6 -5
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +69 -65
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +6 -5
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +89 -104
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +6 -5
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +72 -66
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +7 -6
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +85 -99
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +10 -9
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +89 -79
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +6 -5
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +72 -65
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +6 -5
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +72 -64
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +6 -5
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +65 -58
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +13 -12
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +68 -52
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +12 -11
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +93 -82
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +6 -5
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +73 -63
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/server.js +2 -2
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -4
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +8 -8
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +61 -105
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +10 -10
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +22 -42
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +9 -9
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +15 -25
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +8 -8
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +21 -40
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +11 -11
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +14 -22
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts +9 -9
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +24 -47
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +9 -9
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +40 -83
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +9 -9
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +29 -54
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +5 -5
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +11 -21
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +5 -5
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +11 -22
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +24 -23
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +509 -723
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +5 -2
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +9 -9
- package/dist/types/bledevicestatus.d.ts.map +1 -1
- package/dist/types/devicelist.d.ts +6 -6
- package/dist/types/devicelist.d.ts.map +1 -1
- package/dist/types/deviceresponse.d.ts +4 -4
- package/dist/types/deviceresponse.d.ts.map +1 -1
- package/dist/types/devicestatus.d.ts +2 -2
- package/dist/types/devicestatus.d.ts.map +1 -1
- package/dist/types/devicewebhookstatus.d.ts +5 -5
- package/dist/types/devicewebhookstatus.d.ts.map +1 -1
- package/dist/types/irdevicelist.d.ts +4 -4
- package/dist/types/irdevicelist.d.ts.map +1 -1
- package/dist/types/pushbody.d.ts +2 -2
- package/dist/types/pushbody.d.ts.map +1 -1
- package/dist/utils.d.ts +4 -4
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +9 -13
- package/dist/utils.js.map +1 -1
- package/eslint.config.js +48 -93
- package/package.json +64 -57
- package/src/device/blindtilt.ts +537 -456
- package/src/device/bot-old.ts +1540 -0
- package/src/device/bot.ts +732 -725
- package/src/device/ceilinglight.ts +359 -368
- package/src/device/colorbulb.ts +441 -453
- package/src/device/contact.ts +229 -226
- package/src/device/curtain.ts +526 -444
- package/src/device/device.ts +206 -208
- package/src/device/fan.ts +336 -345
- package/src/device/hub.ts +213 -214
- package/src/device/humidifier.ts +326 -347
- package/src/device/iosensor.ts +211 -209
- package/src/device/lightstrip.ts +391 -404
- package/src/device/lock.ts +292 -282
- package/src/device/meter.ts +212 -210
- package/src/device/meterplus.ts +212 -209
- package/src/device/motion.ts +198 -190
- package/src/device/plug.ts +203 -182
- package/src/device/robotvacuumcleaner.ts +280 -269
- package/src/device/waterdetector.ts +198 -189
- package/src/homebridge-ui/server.ts +16 -15
- package/src/index.ts +5 -6
- package/src/irdevice/airconditioner.ts +277 -326
- package/src/irdevice/airpurifier.ts +124 -143
- package/src/irdevice/camera.ts +58 -64
- package/src/irdevice/fan.ts +106 -123
- package/src/irdevice/irdevice.ts +116 -119
- package/src/irdevice/light.ts +119 -143
- package/src/irdevice/other.ts +417 -461
- package/src/irdevice/tv.ts +155 -177
- package/src/irdevice/vacuumcleaner.ts +54 -60
- package/src/irdevice/waterheater.ts +56 -63
- package/src/platform.ts +1491 -1681
- package/src/settings.ts +172 -169
- package/src/types/bledevicestatus.ts +252 -256
- package/src/types/devicelist.ts +79 -79
- package/src/types/deviceresponse.ts +12 -13
- package/src/types/devicestatus.ts +124 -124
- package/src/types/devicewebhookstatus.ts +126 -131
- package/src/types/irdevicelist.ts +10 -10
- package/src/types/pushbody.ts +5 -5
- package/src/utils.ts +64 -65
- package/tsconfig.json +10 -9
package/src/device/hub.ts
CHANGED
|
@@ -2,273 +2,273 @@
|
|
|
2
2
|
*
|
|
3
3
|
* hub.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
import type {
|
|
12
|
-
import type {
|
|
13
|
-
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
import
|
|
5
|
+
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
|
|
7
|
+
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
|
+
import type { devicesConfig } from '../settings.js'
|
|
9
|
+
import type { hub2ServiceData } from '../types/bledevicestatus.js'
|
|
10
|
+
import type { device } from '../types/devicelist.js'
|
|
11
|
+
import type { hub2Status } from '../types/devicestatus.js'
|
|
12
|
+
import type { hub2WebhookContext } from '../types/devicewebhookstatus.js'
|
|
13
|
+
|
|
14
|
+
import { Units } from 'homebridge'
|
|
15
|
+
/*
|
|
16
|
+
* For Testing Locally:
|
|
17
|
+
* import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
|
|
18
|
+
*/
|
|
19
|
+
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot'
|
|
20
|
+
import { interval, skipWhile, Subject } from 'rxjs'
|
|
21
|
+
|
|
22
|
+
import { convertUnits, validHumidity } from '../utils.js'
|
|
23
|
+
import { deviceBase } from './device.js'
|
|
18
24
|
|
|
19
25
|
export class Hub extends deviceBase {
|
|
20
26
|
// Services
|
|
21
27
|
private LightSensor?: {
|
|
22
|
-
Name: CharacteristicValue
|
|
23
|
-
Service: Service
|
|
24
|
-
CurrentAmbientLightLevel: CharacteristicValue
|
|
25
|
-
}
|
|
28
|
+
Name: CharacteristicValue
|
|
29
|
+
Service: Service
|
|
30
|
+
CurrentAmbientLightLevel: CharacteristicValue
|
|
31
|
+
}
|
|
26
32
|
|
|
27
33
|
private HumiditySensor?: {
|
|
28
|
-
Name: CharacteristicValue
|
|
29
|
-
Service: Service
|
|
30
|
-
CurrentRelativeHumidity: CharacteristicValue
|
|
31
|
-
}
|
|
34
|
+
Name: CharacteristicValue
|
|
35
|
+
Service: Service
|
|
36
|
+
CurrentRelativeHumidity: CharacteristicValue
|
|
37
|
+
}
|
|
32
38
|
|
|
33
39
|
private TemperatureSensor?: {
|
|
34
|
-
Name: CharacteristicValue
|
|
35
|
-
Service: Service
|
|
36
|
-
CurrentTemperature: CharacteristicValue
|
|
37
|
-
}
|
|
40
|
+
Name: CharacteristicValue
|
|
41
|
+
Service: Service
|
|
42
|
+
CurrentTemperature: CharacteristicValue
|
|
43
|
+
}
|
|
38
44
|
|
|
39
45
|
// OpenAPI
|
|
40
|
-
deviceStatus!: hub2Status
|
|
46
|
+
deviceStatus!: hub2Status
|
|
41
47
|
|
|
42
|
-
//Webhook
|
|
43
|
-
webhookContext!: hub2WebhookContext
|
|
48
|
+
// Webhook
|
|
49
|
+
webhookContext!: hub2WebhookContext
|
|
44
50
|
|
|
45
51
|
// BLE
|
|
46
|
-
serviceData!: hub2ServiceData
|
|
52
|
+
serviceData!: hub2ServiceData
|
|
47
53
|
|
|
48
54
|
// Updates
|
|
49
|
-
hubUpdateInProgress!: boolean
|
|
50
|
-
doHubUpdate!: Subject<void
|
|
55
|
+
hubUpdateInProgress!: boolean
|
|
56
|
+
doHubUpdate!: Subject<void>
|
|
51
57
|
|
|
52
58
|
constructor(
|
|
53
59
|
readonly platform: SwitchBotPlatform,
|
|
54
60
|
accessory: PlatformAccessory,
|
|
55
61
|
device: device & devicesConfig,
|
|
56
62
|
) {
|
|
57
|
-
super(platform, accessory, device)
|
|
63
|
+
super(platform, accessory, device)
|
|
58
64
|
// Set category
|
|
59
|
-
accessory.category = this.hap.Categories.SENSOR
|
|
65
|
+
accessory.category = this.hap.Categories.SENSOR
|
|
60
66
|
|
|
61
67
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
62
|
-
this.doHubUpdate = new Subject()
|
|
63
|
-
this.hubUpdateInProgress = false
|
|
68
|
+
this.doHubUpdate = new Subject()
|
|
69
|
+
this.hubUpdateInProgress = false
|
|
64
70
|
|
|
65
71
|
// Initialize Temperature Sensor Service
|
|
66
72
|
if (device.hub?.hide_temperature) {
|
|
67
73
|
if (this.TemperatureSensor) {
|
|
68
|
-
this.debugLog('Removing Temperature Sensor Service')
|
|
69
|
-
this.TemperatureSensor.Service = this.accessory.getService(this.hap.Service.TemperatureSensor) as Service
|
|
70
|
-
accessory.removeService(this.TemperatureSensor.Service)
|
|
74
|
+
this.debugLog('Removing Temperature Sensor Service')
|
|
75
|
+
this.TemperatureSensor.Service = this.accessory.getService(this.hap.Service.TemperatureSensor) as Service
|
|
76
|
+
accessory.removeService(this.TemperatureSensor.Service)
|
|
71
77
|
}
|
|
72
78
|
} else {
|
|
73
|
-
accessory.context.TemperatureSensor = accessory.context.TemperatureSensor ?? {}
|
|
79
|
+
accessory.context.TemperatureSensor = accessory.context.TemperatureSensor ?? {}
|
|
74
80
|
this.TemperatureSensor = {
|
|
75
81
|
Name: `${accessory.displayName} Temperature Sensor`,
|
|
76
82
|
Service: accessory.getService(this.hap.Service.TemperatureSensor) ?? this.accessory.addService(this.hap.Service.TemperatureSensor) as Service,
|
|
77
83
|
CurrentTemperature: accessory.context.CurrentTemperature ?? 0,
|
|
78
|
-
}
|
|
79
|
-
accessory.context.TemperatureSensor = this.TemperatureSensor as object
|
|
84
|
+
}
|
|
85
|
+
accessory.context.TemperatureSensor = this.TemperatureSensor as object
|
|
80
86
|
|
|
81
87
|
// Initialize Temperature Sensor Characteristic
|
|
82
|
-
this.TemperatureSensor.Service
|
|
83
|
-
.
|
|
84
|
-
.
|
|
85
|
-
.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
})
|
|
92
|
-
.onGet(() => {
|
|
93
|
-
return this.TemperatureSensor!.CurrentTemperature;
|
|
94
|
-
});
|
|
88
|
+
this.TemperatureSensor.Service.setCharacteristic(this.hap.Characteristic.Name, this.TemperatureSensor.Name).getCharacteristic(this.hap.Characteristic.CurrentTemperature).setProps({
|
|
89
|
+
unit: Units.CELSIUS,
|
|
90
|
+
validValueRanges: [-273.15, 100],
|
|
91
|
+
minValue: -273.15,
|
|
92
|
+
maxValue: 100,
|
|
93
|
+
minStep: 0.1,
|
|
94
|
+
}).onGet(() => {
|
|
95
|
+
return this.TemperatureSensor!.CurrentTemperature
|
|
96
|
+
})
|
|
95
97
|
}
|
|
96
98
|
|
|
97
99
|
// Initialize Humidity Sensor Service
|
|
98
100
|
if (device.hub?.hide_humidity) {
|
|
99
101
|
if (this.HumiditySensor) {
|
|
100
|
-
this.debugLog('Removing Humidity Sensor Service')
|
|
101
|
-
this.HumiditySensor.Service = this.accessory.getService(this.hap.Service.HumiditySensor) as Service
|
|
102
|
-
accessory.removeService(this.HumiditySensor.Service)
|
|
102
|
+
this.debugLog('Removing Humidity Sensor Service')
|
|
103
|
+
this.HumiditySensor.Service = this.accessory.getService(this.hap.Service.HumiditySensor) as Service
|
|
104
|
+
accessory.removeService(this.HumiditySensor.Service)
|
|
103
105
|
}
|
|
104
106
|
} else {
|
|
105
|
-
accessory.context.HumiditySensor = accessory.context.HumiditySensor ?? {}
|
|
107
|
+
accessory.context.HumiditySensor = accessory.context.HumiditySensor ?? {}
|
|
106
108
|
this.HumiditySensor = {
|
|
107
109
|
Name: `${accessory.displayName} Humidity Sensor`,
|
|
108
110
|
Service: accessory.getService(this.hap.Service.HumiditySensor) ?? this.accessory.addService(this.hap.Service.HumiditySensor) as Service,
|
|
109
111
|
CurrentRelativeHumidity: accessory.context.CurrentRelativeHumidity ?? 0,
|
|
110
|
-
}
|
|
111
|
-
accessory.context.HumiditySensor = this.HumiditySensor as object
|
|
112
|
+
}
|
|
113
|
+
accessory.context.HumiditySensor = this.HumiditySensor as object
|
|
112
114
|
|
|
113
115
|
// Initialize Humidity Sensor Characteristics
|
|
114
|
-
this.HumiditySensor!.Service
|
|
115
|
-
.
|
|
116
|
-
|
|
117
|
-
.
|
|
118
|
-
|
|
119
|
-
})
|
|
120
|
-
.onGet(() => {
|
|
121
|
-
return this.HumiditySensor!.CurrentRelativeHumidity;
|
|
122
|
-
});
|
|
116
|
+
this.HumiditySensor!.Service.setCharacteristic(this.hap.Characteristic.Name, this.HumiditySensor.Name).getCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity).setProps({
|
|
117
|
+
minStep: 0.1,
|
|
118
|
+
}).onGet(() => {
|
|
119
|
+
return this.HumiditySensor!.CurrentRelativeHumidity
|
|
120
|
+
})
|
|
123
121
|
}
|
|
124
122
|
|
|
125
123
|
// Initialize Light Sensor Service
|
|
126
124
|
if (device.hub?.hide_lightsensor) {
|
|
127
125
|
if (this.LightSensor) {
|
|
128
|
-
this.debugLog('Removing Light Sensor Service')
|
|
129
|
-
this.LightSensor.Service = this.accessory.getService(this.hap.Service.LightSensor) as Service
|
|
130
|
-
accessory.removeService(this.LightSensor.Service)
|
|
126
|
+
this.debugLog('Removing Light Sensor Service')
|
|
127
|
+
this.LightSensor.Service = this.accessory.getService(this.hap.Service.LightSensor) as Service
|
|
128
|
+
accessory.removeService(this.LightSensor.Service)
|
|
131
129
|
}
|
|
132
130
|
} else {
|
|
133
|
-
accessory.context.LightSensor = accessory.context.LightSensor ?? {}
|
|
131
|
+
accessory.context.LightSensor = accessory.context.LightSensor ?? {}
|
|
134
132
|
this.LightSensor = {
|
|
135
133
|
Name: `${accessory.displayName} Light Sensor`,
|
|
136
134
|
Service: accessory.getService(this.hap.Service.LightSensor) ?? this.accessory.addService(this.hap.Service.LightSensor) as Service,
|
|
137
135
|
CurrentAmbientLightLevel: accessory.context.CurrentAmbientLightLevel ?? 0.0001,
|
|
138
|
-
}
|
|
139
|
-
accessory.context.LightSensor = this.LightSensor as object
|
|
136
|
+
}
|
|
137
|
+
accessory.context.LightSensor = this.LightSensor as object
|
|
140
138
|
|
|
141
139
|
// Initialize Light Sensor Characteristics
|
|
142
|
-
this.LightSensor!.Service
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
.
|
|
146
|
-
|
|
147
|
-
})
|
|
148
|
-
.onGet(() => {
|
|
149
|
-
return this.LightSensor!.CurrentAmbientLightLevel;
|
|
150
|
-
});
|
|
140
|
+
this.LightSensor!.Service.setCharacteristic(this.hap.Characteristic.Name, this.LightSensor.Name).getCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel).setProps({
|
|
141
|
+
minStep: 1,
|
|
142
|
+
}).onGet(() => {
|
|
143
|
+
return this.LightSensor!.CurrentAmbientLightLevel
|
|
144
|
+
})
|
|
151
145
|
}
|
|
152
146
|
|
|
153
147
|
// Retrieve initial values and updateHomekit
|
|
154
|
-
|
|
155
|
-
|
|
148
|
+
try {
|
|
149
|
+
this.debugLog('Retrieve initial values and update Homekit')
|
|
150
|
+
this.refreshStatus()
|
|
151
|
+
} catch (e: any) {
|
|
152
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
153
|
+
}
|
|
156
154
|
|
|
157
|
-
//regisiter webhook event handler
|
|
158
|
-
|
|
159
|
-
|
|
155
|
+
// regisiter webhook event handler if enabled
|
|
156
|
+
try {
|
|
157
|
+
this.debugLog('Registering Webhook Event Handler')
|
|
158
|
+
this.registerWebhook()
|
|
159
|
+
} catch (e: any) {
|
|
160
|
+
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// regisiter platform BLE event handler if enabled
|
|
164
|
+
try {
|
|
165
|
+
this.debugLog('Registering Platform BLE Event Handler')
|
|
166
|
+
this.registerPlatformBLE()
|
|
167
|
+
} catch (e: any) {
|
|
168
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
169
|
+
}
|
|
160
170
|
|
|
161
171
|
// Start an update interval
|
|
162
172
|
interval(this.deviceRefreshRate * 1000)
|
|
163
173
|
.pipe(skipWhile(() => this.hubUpdateInProgress))
|
|
164
174
|
.subscribe(async () => {
|
|
165
|
-
await this.refreshStatus()
|
|
166
|
-
})
|
|
167
|
-
|
|
175
|
+
await this.refreshStatus()
|
|
176
|
+
})
|
|
168
177
|
}
|
|
169
178
|
|
|
170
179
|
async BLEparseStatus(): Promise<void> {
|
|
171
|
-
await this.debugLog('BLEparseStatus')
|
|
172
|
-
await this.debugLog(`(temperature, humidity, lightLevel) = BLE:(${this.serviceData.temperature}, ${this.serviceData.humidity}
|
|
173
|
-
+ ` ${this.serviceData.lightLevel}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity},`
|
|
174
|
-
+ ` ${this.LightSensor?.CurrentAmbientLightLevel})`);
|
|
180
|
+
await this.debugLog('BLEparseStatus')
|
|
181
|
+
await this.debugLog(`(temperature, humidity, lightLevel) = BLE:(${this.serviceData.temperature}, ${this.serviceData.humidity}, ${this.serviceData.lightLevel}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity}, ${this.LightSensor?.CurrentAmbientLightLevel})`)
|
|
175
182
|
|
|
176
183
|
// CurrentTemperature
|
|
177
184
|
if (!this.device.hub?.hide_temperature && this.TemperatureSensor?.Service) {
|
|
178
|
-
this.TemperatureSensor.CurrentTemperature = this.serviceData.temperature
|
|
179
|
-
await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}°c`)
|
|
185
|
+
this.TemperatureSensor.CurrentTemperature = this.serviceData.temperature.c
|
|
186
|
+
await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}°c`)
|
|
180
187
|
}
|
|
181
188
|
|
|
182
189
|
// CurrentRelativeHumidity
|
|
183
190
|
if (!this.device.hub?.hide_humidity && this.HumiditySensor?.Service) {
|
|
184
|
-
this.HumiditySensor!.CurrentRelativeHumidity = validHumidity(this.serviceData.humidity, 0, 100)
|
|
185
|
-
await this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`)
|
|
191
|
+
this.HumiditySensor!.CurrentRelativeHumidity = validHumidity(this.serviceData.humidity, 0, 100)
|
|
192
|
+
await this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`)
|
|
186
193
|
}
|
|
187
194
|
|
|
188
195
|
// CurrentAmbientLightLevel
|
|
189
196
|
if (!this.device.hub?.hide_lightsensor && this.LightSensor?.Service) {
|
|
190
|
-
const set_minLux = this.device.blindTilt?.set_minLux ?? 1
|
|
191
|
-
const set_maxLux = this.device.blindTilt?.set_maxLux ?? 6001
|
|
192
|
-
const lightLevel = this.serviceData.lightLevel
|
|
193
|
-
this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 19)
|
|
194
|
-
await this.debugLog(`LightLevel: ${this.serviceData.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
|
|
197
|
+
const set_minLux = this.device.blindTilt?.set_minLux ?? 1
|
|
198
|
+
const set_maxLux = this.device.blindTilt?.set_maxLux ?? 6001
|
|
199
|
+
const lightLevel = this.serviceData.lightLevel
|
|
200
|
+
this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 19)
|
|
201
|
+
await this.debugLog(`LightLevel: ${this.serviceData.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
|
|
195
202
|
}
|
|
196
203
|
}
|
|
197
204
|
|
|
198
205
|
async openAPIparseStatus(): Promise<void> {
|
|
199
|
-
await this.debugLog('openAPIparseStatus')
|
|
200
|
-
await this.debugLog(`(temperature, humidity, lightLevel) = OpenAPI:(${this.deviceStatus.temperature}, ${this.deviceStatus.humidity}
|
|
201
|
-
+ ` ${this.deviceStatus.lightLevel}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity},`
|
|
202
|
-
+ ` ${this.LightSensor?.CurrentAmbientLightLevel})`);
|
|
206
|
+
await this.debugLog('openAPIparseStatus')
|
|
207
|
+
await this.debugLog(`(temperature, humidity, lightLevel) = OpenAPI:(${this.deviceStatus.temperature}, ${this.deviceStatus.humidity}, ${this.deviceStatus.lightLevel}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity}, ${this.LightSensor?.CurrentAmbientLightLevel})`)
|
|
203
208
|
|
|
204
209
|
// CurrentRelativeHumidity
|
|
205
210
|
if (!this.device.hub?.hide_humidity && this.HumiditySensor?.Service) {
|
|
206
|
-
this.HumiditySensor.CurrentRelativeHumidity = this.deviceStatus.humidity
|
|
207
|
-
await this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`)
|
|
211
|
+
this.HumiditySensor.CurrentRelativeHumidity = this.deviceStatus.humidity
|
|
212
|
+
await this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`)
|
|
208
213
|
}
|
|
209
214
|
|
|
210
215
|
// CurrentTemperature
|
|
211
216
|
if (!this.device.hub?.hide_temperature && this.TemperatureSensor?.Service) {
|
|
212
|
-
this.TemperatureSensor.CurrentTemperature = this.deviceStatus.temperature
|
|
213
|
-
await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}°c`)
|
|
217
|
+
this.TemperatureSensor.CurrentTemperature = this.deviceStatus.temperature
|
|
218
|
+
await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}°c`)
|
|
214
219
|
}
|
|
215
220
|
|
|
216
221
|
// LightSensor
|
|
217
222
|
if (!this.device.hub?.hide_lightsensor && this.LightSensor?.Service) {
|
|
218
|
-
const set_minLux = this.device.blindTilt?.set_minLux ?? 1
|
|
219
|
-
const set_maxLux = this.device.blindTilt?.set_maxLux ?? 6001
|
|
220
|
-
const lightLevel = this.deviceStatus.lightLevel
|
|
221
|
-
this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 19)
|
|
222
|
-
await this.debugLog(`LightLevel: ${this.deviceStatus.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`)
|
|
223
|
+
const set_minLux = this.device.blindTilt?.set_minLux ?? 1
|
|
224
|
+
const set_maxLux = this.device.blindTilt?.set_maxLux ?? 6001
|
|
225
|
+
const lightLevel = this.deviceStatus.lightLevel
|
|
226
|
+
this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(lightLevel, set_minLux, set_maxLux, 19)
|
|
227
|
+
await this.debugLog(`LightLevel: ${this.deviceStatus.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor!.CurrentAmbientLightLevel}`)
|
|
223
228
|
}
|
|
224
229
|
|
|
225
230
|
// Firmware Version
|
|
226
231
|
if (this.deviceStatus.version) {
|
|
227
|
-
const version = this.deviceStatus.version.toString()
|
|
228
|
-
await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
|
|
229
|
-
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
|
|
232
|
+
const version = this.deviceStatus.version.toString()
|
|
233
|
+
await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
|
|
234
|
+
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
|
|
230
235
|
this.accessory
|
|
231
236
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
232
237
|
.setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
|
|
233
238
|
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
|
|
234
239
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
235
|
-
.updateValue(deviceVersion)
|
|
236
|
-
this.accessory.context.version = deviceVersion
|
|
237
|
-
await this.debugSuccessLog(`version: ${this.accessory.context.version}`)
|
|
240
|
+
.updateValue(deviceVersion)
|
|
241
|
+
this.accessory.context.version = deviceVersion
|
|
242
|
+
await this.debugSuccessLog(`version: ${this.accessory.context.version}`)
|
|
238
243
|
}
|
|
239
244
|
}
|
|
240
245
|
|
|
241
246
|
async parseStatusWebhook(): Promise<void> {
|
|
242
|
-
await this.debugLog('parseStatusWebhook')
|
|
243
|
-
await this.debugLog(`(scale, temperature, humidity, lightLevel) = Webhook:(${this.webhookContext.scale}
|
|
244
|
-
+ ` ${convertUnits(this.webhookContext.temperature, this.webhookContext.scale, this.device.hub?.convertUnitTo)},`
|
|
245
|
-
+ ` ${this.webhookContext.humidity}, ${this.webhookContext.lightLevel}), current:(${this.TemperatureSensor?.CurrentTemperature},`
|
|
246
|
-
+ ` ${this.HumiditySensor?.CurrentRelativeHumidity}, ${this.LightSensor?.CurrentAmbientLightLevel})`);
|
|
247
|
+
await this.debugLog('parseStatusWebhook')
|
|
248
|
+
await this.debugLog(`(scale, temperature, humidity, lightLevel) = Webhook:(${this.webhookContext.scale}, ${convertUnits(this.webhookContext.temperature, this.webhookContext.scale, this.device.hub?.convertUnitTo)}, ${this.webhookContext.humidity}, ${this.webhookContext.lightLevel}), current:(${this.TemperatureSensor?.CurrentTemperature}, ${this.HumiditySensor?.CurrentRelativeHumidity}, ${this.LightSensor?.CurrentAmbientLightLevel})`)
|
|
247
249
|
// Check if the scale is not CELSIUS
|
|
248
250
|
if (this.webhookContext.scale !== 'CELSIUS' && this.device.hub?.convertUnitTo === undefined) {
|
|
249
|
-
await this.warnLog(`received a non-CELSIUS Webhook scale: ${this.webhookContext.scale}, Use the *convertUnitsTo* config under Hub settings
|
|
250
|
-
+ ' if displaying incorrectly in HomeKit.');
|
|
251
|
+
await this.warnLog(`received a non-CELSIUS Webhook scale: ${this.webhookContext.scale}, Use the *convertUnitsTo* config under Hub settings, if displaying incorrectly in HomeKit.`)
|
|
251
252
|
}
|
|
252
253
|
|
|
253
254
|
// CurrentRelativeHumidity
|
|
254
255
|
if (!this.device.hub?.hide_humidity && this.HumiditySensor?.Service) {
|
|
255
|
-
this.HumiditySensor.CurrentRelativeHumidity = this.webhookContext.humidity
|
|
256
|
-
await this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}`)
|
|
256
|
+
this.HumiditySensor.CurrentRelativeHumidity = this.webhookContext.humidity
|
|
257
|
+
await this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}`)
|
|
257
258
|
}
|
|
258
259
|
|
|
259
260
|
// CurrentTemperature
|
|
260
261
|
if (!this.device.hub?.hide_temperature && this.TemperatureSensor?.Service) {
|
|
261
|
-
this.TemperatureSensor.CurrentTemperature = convertUnits(this.webhookContext.temperature, this.webhookContext.scale,
|
|
262
|
-
|
|
263
|
-
await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
|
|
262
|
+
this.TemperatureSensor.CurrentTemperature = convertUnits(this.webhookContext.temperature, this.webhookContext.scale, this.device.hub?.convertUnitTo)
|
|
263
|
+
await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`)
|
|
264
264
|
}
|
|
265
265
|
|
|
266
266
|
// CurrentAmbientLightLevel
|
|
267
267
|
if (!this.device.hub?.hide_lightsensor && this.LightSensor?.Service) {
|
|
268
|
-
const set_minLux = this.device.blindTilt?.set_minLux ?? 1
|
|
269
|
-
const set_maxLux = this.device.blindTilt?.set_maxLux ?? 6001
|
|
270
|
-
this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(this.webhookContext.lightLevel, set_minLux, set_maxLux, 19)
|
|
271
|
-
await this.debugLog(`CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
|
|
268
|
+
const set_minLux = this.device.blindTilt?.set_minLux ?? 1
|
|
269
|
+
const set_maxLux = this.device.blindTilt?.set_maxLux ?? 6001
|
|
270
|
+
this.LightSensor.CurrentAmbientLightLevel = await this.getLightLevel(this.webhookContext.lightLevel, set_minLux, set_maxLux, 19)
|
|
271
|
+
await this.debugLog(`CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
|
|
272
272
|
}
|
|
273
273
|
}
|
|
274
274
|
|
|
@@ -277,93 +277,97 @@ export class Hub extends deviceBase {
|
|
|
277
277
|
*/
|
|
278
278
|
async refreshStatus(): Promise<void> {
|
|
279
279
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
280
|
-
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
|
|
281
|
-
} else if (this.BLE
|
|
282
|
-
await this.BLERefreshStatus()
|
|
280
|
+
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
|
|
281
|
+
} else if (this.BLE) {
|
|
282
|
+
await this.BLERefreshStatus()
|
|
283
283
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
284
|
-
await this.openAPIRefreshStatus()
|
|
284
|
+
await this.openAPIRefreshStatus()
|
|
285
285
|
} else {
|
|
286
|
-
await this.offlineOff()
|
|
287
|
-
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
|
|
286
|
+
await this.offlineOff()
|
|
287
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
|
|
288
288
|
}
|
|
289
289
|
}
|
|
290
290
|
|
|
291
291
|
async BLERefreshStatus(): Promise<void> {
|
|
292
|
-
await this.debugLog('BLERefreshStatus')
|
|
292
|
+
await this.debugLog('BLERefreshStatus')
|
|
293
|
+
const switchbot = await this.switchbotBLE()
|
|
294
|
+
if (switchbot === undefined) {
|
|
295
|
+
await this.BLERefreshConnection(switchbot)
|
|
296
|
+
} else {
|
|
297
|
+
// Start to monitor advertisement packets
|
|
298
|
+
(async () => {
|
|
299
|
+
// Start to monitor advertisement packets
|
|
300
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as hub2ServiceData
|
|
301
|
+
// Update HomeKit
|
|
302
|
+
if (serviceData.model === SwitchBotBLEModel.Hub2 && serviceData.modelName === SwitchBotBLEModelName.Hub2) {
|
|
303
|
+
this.serviceData = serviceData
|
|
304
|
+
await this.BLEparseStatus()
|
|
305
|
+
await this.updateHomeKitCharacteristics()
|
|
306
|
+
} else {
|
|
307
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
308
|
+
await this.BLERefreshConnection(switchbot)
|
|
309
|
+
}
|
|
310
|
+
})()
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
async registerPlatformBLE(): Promise<void> {
|
|
315
|
+
await this.debugLog('registerPlatformBLE')
|
|
293
316
|
if (this.config.options?.BLE) {
|
|
294
|
-
await this.debugLog('is listening to Platform BLE.')
|
|
295
|
-
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase()
|
|
296
|
-
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
317
|
+
await this.debugLog('is listening to Platform BLE.')
|
|
318
|
+
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase()
|
|
319
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
297
320
|
this.platform.bleEventHandler[this.device.bleMac] = async (context: hub2ServiceData) => {
|
|
298
321
|
try {
|
|
299
|
-
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
300
|
-
this.serviceData = context
|
|
301
|
-
await this.BLEparseStatus()
|
|
302
|
-
await this.updateHomeKitCharacteristics()
|
|
322
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
323
|
+
this.serviceData = context
|
|
324
|
+
await this.BLEparseStatus()
|
|
325
|
+
await this.updateHomeKitCharacteristics()
|
|
303
326
|
} catch (e: any) {
|
|
304
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
327
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
305
328
|
}
|
|
306
|
-
};
|
|
307
|
-
} else {
|
|
308
|
-
await this.debugLog('is using Device BLE Scanning.');
|
|
309
|
-
const switchbot = await this.switchbotBLE();
|
|
310
|
-
if (switchbot === undefined) {
|
|
311
|
-
await this.BLERefreshConnection(switchbot);
|
|
312
|
-
} else {
|
|
313
|
-
// Start to monitor advertisement packets
|
|
314
|
-
(async () => {
|
|
315
|
-
// Start to monitor advertisement packets
|
|
316
|
-
const serviceData = await this.monitorAdvertisementPackets(switchbot) as hub2ServiceData;
|
|
317
|
-
// Update HomeKit
|
|
318
|
-
if (serviceData.model === SwitchBotBLEModel.Hub2 && serviceData.modelName === SwitchBotBLEModelName.Hub2) {
|
|
319
|
-
this.serviceData = serviceData;
|
|
320
|
-
await this.BLEparseStatus();
|
|
321
|
-
await this.updateHomeKitCharacteristics();
|
|
322
|
-
} else {
|
|
323
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
324
|
-
await this.BLERefreshConnection(switchbot);
|
|
325
|
-
}
|
|
326
|
-
})();
|
|
327
329
|
}
|
|
330
|
+
} else {
|
|
331
|
+
await this.debugLog('is not listening to Platform BLE')
|
|
328
332
|
}
|
|
329
333
|
}
|
|
330
334
|
|
|
331
335
|
async openAPIRefreshStatus(): Promise<void> {
|
|
332
|
-
await this.debugLog('openAPIRefreshStatus')
|
|
336
|
+
await this.debugLog('openAPIRefreshStatus')
|
|
333
337
|
try {
|
|
334
|
-
const { body, statusCode } = await this.deviceRefreshStatus()
|
|
335
|
-
const deviceStatus: any = await body.json()
|
|
336
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
338
|
+
const { body, statusCode } = await this.deviceRefreshStatus()
|
|
339
|
+
const deviceStatus: any = await body.json()
|
|
340
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
337
341
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
338
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
339
|
-
this.deviceStatus = deviceStatus.body
|
|
340
|
-
await this.openAPIparseStatus()
|
|
341
|
-
await this.updateHomeKitCharacteristics()
|
|
342
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
343
|
+
this.deviceStatus = deviceStatus.body
|
|
344
|
+
await this.openAPIparseStatus()
|
|
345
|
+
await this.updateHomeKitCharacteristics()
|
|
342
346
|
} else {
|
|
343
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
344
|
-
await this.debugWarnLog(statusCode, deviceStatus)
|
|
347
|
+
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
348
|
+
await this.debugWarnLog(statusCode, deviceStatus)
|
|
345
349
|
}
|
|
346
350
|
} catch (e: any) {
|
|
347
|
-
await this.apiError(e)
|
|
348
|
-
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
351
|
+
await this.apiError(e)
|
|
352
|
+
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
349
353
|
}
|
|
350
354
|
}
|
|
351
355
|
|
|
352
356
|
async registerWebhook(): Promise<void> {
|
|
353
357
|
if (this.device.webhook) {
|
|
354
|
-
await this.debugLog('is listening webhook.')
|
|
358
|
+
await this.debugLog('is listening webhook.')
|
|
355
359
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context: hub2WebhookContext) => {
|
|
356
360
|
try {
|
|
357
|
-
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
|
|
358
|
-
this.webhookContext = context
|
|
359
|
-
await this.parseStatusWebhook()
|
|
360
|
-
await this.updateHomeKitCharacteristics()
|
|
361
|
+
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
|
|
362
|
+
this.webhookContext = context
|
|
363
|
+
await this.parseStatusWebhook()
|
|
364
|
+
await this.updateHomeKitCharacteristics()
|
|
361
365
|
} catch (e: any) {
|
|
362
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
366
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
363
367
|
}
|
|
364
|
-
}
|
|
365
|
-
}else {
|
|
366
|
-
await this.debugLog('is not listening webhook.')
|
|
368
|
+
}
|
|
369
|
+
} else {
|
|
370
|
+
await this.debugLog('is not listening webhook.')
|
|
367
371
|
}
|
|
368
372
|
}
|
|
369
373
|
|
|
@@ -374,54 +378,49 @@ export class Hub extends deviceBase {
|
|
|
374
378
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
375
379
|
// CurrentRelativeHumidity
|
|
376
380
|
if (!this.device.hub?.hide_humidity && this.HumiditySensor?.Service) {
|
|
377
|
-
await this.updateCharacteristic(this.HumiditySensor.Service, this.hap.Characteristic.CurrentRelativeHumidity,
|
|
378
|
-
this.HumiditySensor.CurrentRelativeHumidity, 'CurrentRelativeHumidity');
|
|
381
|
+
await this.updateCharacteristic(this.HumiditySensor.Service, this.hap.Characteristic.CurrentRelativeHumidity, this.HumiditySensor.CurrentRelativeHumidity, 'CurrentRelativeHumidity')
|
|
379
382
|
}
|
|
380
383
|
// CurrentTemperature
|
|
381
384
|
if (!this.device.hub?.hide_temperature && this.TemperatureSensor?.Service) {
|
|
382
|
-
await this.updateCharacteristic(this.TemperatureSensor.Service, this.hap.Characteristic.CurrentTemperature,
|
|
383
|
-
this.TemperatureSensor.CurrentTemperature, 'CurrentTemperature');
|
|
385
|
+
await this.updateCharacteristic(this.TemperatureSensor.Service, this.hap.Characteristic.CurrentTemperature, this.TemperatureSensor.CurrentTemperature, 'CurrentTemperature')
|
|
384
386
|
}
|
|
385
387
|
// CurrentAmbientLightLevel
|
|
386
388
|
if (!this.device.hub?.hide_lightsensor && this.LightSensor?.Service) {
|
|
387
|
-
await this.updateCharacteristic(this.LightSensor.Service, this.hap.Characteristic.CurrentAmbientLightLevel,
|
|
388
|
-
this.LightSensor.CurrentAmbientLightLevel, 'CurrentAmbientLightLevel');
|
|
389
|
+
await this.updateCharacteristic(this.LightSensor.Service, this.hap.Characteristic.CurrentAmbientLightLevel, this.LightSensor.CurrentAmbientLightLevel, 'CurrentAmbientLightLevel')
|
|
389
390
|
}
|
|
390
391
|
}
|
|
391
392
|
|
|
392
393
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
393
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
394
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
394
395
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
395
|
-
await this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
396
|
-
await this.openAPIRefreshStatus()
|
|
396
|
+
await this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
397
|
+
await this.openAPIRefreshStatus()
|
|
397
398
|
}
|
|
398
399
|
}
|
|
399
400
|
|
|
400
401
|
async offlineOff(): Promise<void> {
|
|
401
402
|
if (this.device.offline) {
|
|
402
403
|
if (!this.device.hub?.hide_temperature && this.TemperatureSensor?.Service) {
|
|
403
|
-
this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.accessory.context.CurrentTemperature)
|
|
404
|
+
this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.accessory.context.CurrentTemperature)
|
|
404
405
|
}
|
|
405
406
|
if (!this.device.hub?.hide_humidity && this.HumiditySensor?.Service) {
|
|
406
|
-
this.HumiditySensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity,
|
|
407
|
-
this.accessory.context.CurrentRelativeHumidity);
|
|
407
|
+
this.HumiditySensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, this.accessory.context.CurrentRelativeHumidity)
|
|
408
408
|
}
|
|
409
409
|
if (!this.device.hub?.hide_lightsensor && this.LightSensor?.Service) {
|
|
410
|
-
this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel,
|
|
411
|
-
this.accessory.context.CurrentAmbientLightLevel);
|
|
410
|
+
this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, this.accessory.context.CurrentAmbientLightLevel)
|
|
412
411
|
}
|
|
413
412
|
}
|
|
414
413
|
}
|
|
415
414
|
|
|
416
415
|
async apiError(e: any): Promise<void> {
|
|
417
416
|
if (!this.device.hub?.hide_temperature && this.TemperatureSensor?.Service) {
|
|
418
|
-
this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e)
|
|
417
|
+
this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e)
|
|
419
418
|
}
|
|
420
419
|
if (!this.device.hub?.hide_humidity && this.HumiditySensor?.Service) {
|
|
421
|
-
this.HumiditySensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e)
|
|
420
|
+
this.HumiditySensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e)
|
|
422
421
|
}
|
|
423
422
|
if (!this.device.hub?.hide_lightsensor && this.LightSensor?.Service) {
|
|
424
|
-
this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, e)
|
|
423
|
+
this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, e)
|
|
425
424
|
}
|
|
426
425
|
}
|
|
427
426
|
}
|