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