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