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