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