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