@switchbot/homebridge-switchbot 3.5.0-beta.6 → 3.5.0-beta.60
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/.vscode/settings.json +4 -1
- package/CHANGELOG.md +4 -1
- package/config.schema.json +120 -17
- package/dist/device/blindtilt.d.ts +23 -96
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +408 -779
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +26 -72
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +696 -822
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +14 -68
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +237 -606
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +14 -75
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +279 -658
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +15 -66
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +242 -544
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +19 -88
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +402 -805
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +59 -0
- package/dist/device/device.d.ts.map +1 -0
- package/dist/device/device.js +684 -0
- package/dist/device/device.js.map +1 -0
- package/dist/device/fan.d.ts +51 -0
- package/dist/device/fan.d.ts.map +1 -0
- package/dist/device/fan.js +535 -0
- package/dist/device/fan.js.map +1 -0
- package/dist/device/hub.d.ts +16 -60
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +246 -613
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +11 -66
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +232 -593
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +11 -64
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +185 -600
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +11 -69
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +277 -586
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +16 -63
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +241 -560
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +14 -64
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +181 -593
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +14 -65
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +170 -593
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +13 -69
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +178 -531
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -57
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +92 -458
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +12 -63
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +197 -521
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +10 -65
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +139 -495
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/public/index.html +22 -16
- package/dist/homebridge-ui/server.js +1 -1
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +9 -49
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +309 -419
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +8 -39
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +72 -304
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +7 -36
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +34 -278
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +10 -43
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +100 -338
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +40 -0
- package/dist/irdevice/irdevice.d.ts.map +1 -0
- package/dist/irdevice/irdevice.js +330 -0
- package/dist/irdevice/irdevice.js.map +1 -0
- package/dist/irdevice/light.d.ts +12 -45
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +87 -357
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +19 -48
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +352 -546
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +8 -40
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +82 -321
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +7 -36
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +41 -284
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +7 -36
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +42 -287
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +19 -6
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +310 -169
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +62 -19
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +16 -552
- package/dist/settings.js.map +1 -1
- package/dist/utils.d.ts +77 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +638 -1
- package/dist/utils.js.map +1 -1
- package/eslint.config.js +96 -0
- package/package.json +19 -15
- package/src/custom.d.ts +2 -1
- package/src/device/blindtilt.ts +442 -814
- package/src/device/bot.ts +754 -915
- package/src/device/ceilinglight.ts +255 -633
- package/src/device/colorbulb.ts +294 -685
- package/src/device/contact.ts +277 -571
- package/src/device/curtain.ts +431 -835
- package/src/device/device.ts +709 -0
- package/src/device/fan.ts +591 -0
- package/src/device/hub.ts +286 -644
- package/src/device/humidifier.ts +266 -646
- package/src/device/iosensor.ts +220 -625
- package/src/device/lightstrip.ts +305 -620
- package/src/device/lock.ts +280 -600
- package/src/device/meter.ts +216 -617
- package/src/device/meterplus.ts +205 -619
- package/src/device/motion.ts +206 -556
- package/src/device/plug.ts +107 -490
- package/src/device/robotvacuumcleaner.ts +223 -550
- package/src/device/waterdetector.ts +160 -519
- package/src/homebridge-ui/public/index.html +22 -16
- package/src/homebridge-ui/server.ts +1 -1
- package/src/index.ts +4 -3
- package/src/irdevice/airconditioner.ts +333 -447
- package/src/irdevice/airpurifier.ts +92 -322
- package/src/irdevice/camera.ts +45 -294
- package/src/irdevice/fan.ts +115 -353
- package/src/irdevice/irdevice.ts +346 -0
- package/src/irdevice/light.ts +110 -385
- package/src/irdevice/other.ts +399 -616
- package/src/irdevice/tv.ts +103 -340
- package/src/irdevice/vacuumcleaner.ts +52 -306
- package/src/irdevice/waterheater.ts +53 -311
- package/src/platform.ts +355 -216
- package/src/settings.ts +116 -611
- package/src/utils.ts +642 -1
- package/src/device/waterdetector.json +0 -11
package/src/device/iosensor.ts
CHANGED
|
@@ -1,123 +1,96 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
1
|
+
/* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* iosensor.ts: @switchbot/homebridge-switchbot.
|
|
4
|
+
*/
|
|
5
|
+
import { Units } from 'homebridge';
|
|
6
|
+
import { deviceBase } from './device.js';
|
|
7
|
+
import { Devices } from '../settings.js';
|
|
8
|
+
import { convertUnits } from '../utils.js';
|
|
9
|
+
import { Subject, interval, skipWhile } from 'rxjs';
|
|
10
|
+
|
|
11
|
+
import type { SwitchBotPlatform } from '../platform.js';
|
|
12
|
+
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
13
|
+
import type { device, devicesConfig, serviceData, deviceStatus } from '../settings.js';
|
|
11
14
|
|
|
12
15
|
/**
|
|
13
16
|
* Platform Accessory
|
|
14
17
|
* An instance of this class is created for each accessory your platform registers
|
|
15
18
|
* Each accessory may expose multiple services of different service types.
|
|
16
19
|
*/
|
|
17
|
-
export class IOSensor {
|
|
18
|
-
public readonly api: API;
|
|
19
|
-
public readonly log: Logging;
|
|
20
|
-
public readonly config!: SwitchBotPlatformConfig;
|
|
21
|
-
protected readonly hap: HAP;
|
|
20
|
+
export class IOSensor extends deviceBase {
|
|
22
21
|
// Services
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
BLE_Celsius!: temperature['c'];
|
|
42
|
-
BLE_Fahrenheit!: temperature['f'];
|
|
43
|
-
BLE_BatteryLevel!: serviceData['battery'];
|
|
44
|
-
BLE_CurrentTemperature!: serviceData['temperature'];
|
|
45
|
-
BLE_CurrentRelativeHumidity!: serviceData['humidity'];
|
|
46
|
-
|
|
47
|
-
// BLE Others
|
|
48
|
-
BLE_IsConnected?: boolean;
|
|
49
|
-
|
|
50
|
-
//MQTT stuff
|
|
51
|
-
mqttClient: MqttClient | null = null;
|
|
52
|
-
|
|
53
|
-
// EVE history service handler
|
|
54
|
-
historyService?: any;
|
|
55
|
-
|
|
56
|
-
// Config
|
|
57
|
-
scanDuration!: number;
|
|
58
|
-
deviceLogging!: string;
|
|
59
|
-
deviceRefreshRate!: number;
|
|
22
|
+
private Battery: {
|
|
23
|
+
Name: CharacteristicValue;
|
|
24
|
+
Service: Service;
|
|
25
|
+
BatteryLevel: CharacteristicValue;
|
|
26
|
+
StatusLowBattery: CharacteristicValue;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
private HumiditySensor?: {
|
|
30
|
+
Name: CharacteristicValue;
|
|
31
|
+
Service: Service;
|
|
32
|
+
CurrentRelativeHumidity: CharacteristicValue;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
private TemperatureSensor?: {
|
|
36
|
+
Name: CharacteristicValue;
|
|
37
|
+
Service: Service;
|
|
38
|
+
CurrentTemperature: CharacteristicValue;
|
|
39
|
+
};
|
|
60
40
|
|
|
61
41
|
// Updates
|
|
62
42
|
ioSensorUpdateInProgress!: boolean;
|
|
63
43
|
doIOSensorUpdate: Subject<void>;
|
|
64
44
|
|
|
65
|
-
// Connection
|
|
66
|
-
private readonly OpenAPI: boolean;
|
|
67
|
-
private readonly BLE: boolean;
|
|
68
|
-
|
|
69
45
|
constructor(
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
46
|
+
readonly platform: SwitchBotPlatform,
|
|
47
|
+
accessory: PlatformAccessory,
|
|
48
|
+
device: device & devicesConfig,
|
|
73
49
|
) {
|
|
74
|
-
|
|
75
|
-
this.log = this.platform.log;
|
|
76
|
-
this.config = this.platform.config;
|
|
77
|
-
this.hap = this.api.hap;
|
|
78
|
-
// Connection
|
|
79
|
-
this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
80
|
-
this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
81
|
-
// default placeholders
|
|
82
|
-
this.deviceLogs(device);
|
|
83
|
-
this.scan(device);
|
|
84
|
-
this.refreshRate(device);
|
|
85
|
-
this.deviceContext();
|
|
86
|
-
this.setupHistoryService(device);
|
|
87
|
-
this.setupMqtt(device);
|
|
88
|
-
this.deviceConfig(device);
|
|
89
|
-
|
|
50
|
+
super(platform, accessory, device);
|
|
90
51
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
91
52
|
this.doIOSensorUpdate = new Subject();
|
|
92
53
|
this.ioSensorUpdateInProgress = false;
|
|
93
54
|
|
|
94
|
-
//
|
|
95
|
-
this.
|
|
55
|
+
// Initialize Battery property
|
|
56
|
+
this.Battery = {
|
|
57
|
+
Name: accessory.context.BatteryName ?? `${accessory.displayName} Battery`,
|
|
58
|
+
Service: accessory.getService(this.hap.Service.Battery) ?? accessory.addService(this.hap.Service.Battery) as Service,
|
|
59
|
+
BatteryLevel: accessory.context.BatteryLevel ?? 100,
|
|
60
|
+
StatusLowBattery: accessory.context.StatusLowBattery ?? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// Initialize Battery Characteristics
|
|
64
|
+
this.Battery.Service
|
|
65
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name)
|
|
66
|
+
.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE)
|
|
67
|
+
.getCharacteristic(this.hap.Characteristic.BatteryLevel)
|
|
68
|
+
.onGet(() => {
|
|
69
|
+
return this.Battery.BatteryLevel;
|
|
70
|
+
});
|
|
96
71
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
|
|
72
|
+
this.Battery.Service
|
|
73
|
+
.getCharacteristic(this.hap.Characteristic.StatusLowBattery)
|
|
74
|
+
.onGet(() => {
|
|
75
|
+
return this.Battery.StatusLowBattery;
|
|
76
|
+
});
|
|
77
|
+
accessory.context.BatteryName = this.Battery.Name;
|
|
104
78
|
|
|
105
|
-
//
|
|
106
|
-
if (device.
|
|
79
|
+
// InitializeTemperature Sensor Service
|
|
80
|
+
if (device.iosensor?.hide_temperature) {
|
|
107
81
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
|
|
108
|
-
this.
|
|
109
|
-
accessory.removeService(this.
|
|
110
|
-
} else
|
|
111
|
-
this.
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
this.temperatureservice
|
|
82
|
+
this.TemperatureSensor!.Service = this.accessory.getService(this.hap.Service.TemperatureSensor) as Service;
|
|
83
|
+
accessory.removeService(this.TemperatureSensor!.Service);
|
|
84
|
+
} else {
|
|
85
|
+
this.TemperatureSensor = {
|
|
86
|
+
Name: accessory.context.TemperatureSensorName ?? `${accessory.displayName} Temperature Sensor`,
|
|
87
|
+
Service: accessory.getService(this.hap.Service.TemperatureSensor) ?? this.accessory.addService(this.hap.Service.TemperatureSensor) as Service,
|
|
88
|
+
CurrentTemperature: accessory.context.CurrentTemperature ?? 30,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// Initialize Temperature Sensor Characteristics
|
|
92
|
+
this.TemperatureSensor.Service
|
|
93
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.TemperatureSensor.Name)
|
|
121
94
|
.getCharacteristic(this.hap.Characteristic.CurrentTemperature)
|
|
122
95
|
.setProps({
|
|
123
96
|
unit: Units['CELSIUS'],
|
|
@@ -127,49 +100,38 @@ export class IOSensor {
|
|
|
127
100
|
minStep: 0.1,
|
|
128
101
|
})
|
|
129
102
|
.onGet(() => {
|
|
130
|
-
return this.CurrentTemperature
|
|
103
|
+
return this.TemperatureSensor!.CurrentTemperature;
|
|
131
104
|
});
|
|
132
|
-
|
|
133
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Temperature Sensor Service Not Added`);
|
|
105
|
+
accessory.context.TemperatureSensorName = this.TemperatureSensor.Name;
|
|
134
106
|
}
|
|
135
107
|
|
|
136
|
-
// Humidity Sensor Service
|
|
137
|
-
if (device.
|
|
108
|
+
// Initialize Humidity Sensor Service
|
|
109
|
+
if (device.iosensor?.hide_humidity) {
|
|
138
110
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Humidity Sensor Service`);
|
|
139
|
-
this.
|
|
140
|
-
accessory.removeService(this.
|
|
141
|
-
} else
|
|
142
|
-
this.
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
this.humidityservice
|
|
111
|
+
this.HumiditySensor!.Service = this.accessory.getService(this.hap.Service.HumiditySensor) as Service;
|
|
112
|
+
accessory.removeService(this.HumiditySensor!.Service);
|
|
113
|
+
} else {
|
|
114
|
+
this.HumiditySensor = {
|
|
115
|
+
Name: accessory.context.HumiditySensorName ?? `${accessory.displayName} Humidity Sensor`,
|
|
116
|
+
Service: accessory.getService(this.hap.Service.HumiditySensor) ?? this.accessory.addService(this.hap.Service.HumiditySensor) as Service,
|
|
117
|
+
CurrentRelativeHumidity: accessory.context.CurrentRelativeHumidity ?? 50,
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// Initialize Humidity Sensor Characteristics
|
|
121
|
+
this.HumiditySensor.Service
|
|
122
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.HumiditySensor.Name)
|
|
152
123
|
.getCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity)
|
|
153
124
|
.setProps({
|
|
154
125
|
minStep: 0.1,
|
|
155
126
|
})
|
|
156
127
|
.onGet(() => {
|
|
157
|
-
return this.CurrentRelativeHumidity;
|
|
128
|
+
return this.HumiditySensor!.CurrentRelativeHumidity;
|
|
158
129
|
});
|
|
159
|
-
|
|
160
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Humidity Sensor Service Not Added`);
|
|
130
|
+
accessory.context.HumiditySensorName = this.HumiditySensor.Name;
|
|
161
131
|
}
|
|
162
132
|
|
|
163
|
-
//
|
|
164
|
-
|
|
165
|
-
(this.batteryService = this.accessory.getService(this.hap.Service.Battery)
|
|
166
|
-
|| accessory.addService(this.hap.Service.Battery)), batteryService;
|
|
167
|
-
|
|
168
|
-
this.batteryService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
169
|
-
if (!this.batteryService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
170
|
-
this.batteryService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
171
|
-
}
|
|
172
|
-
this.batteryService.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
133
|
+
// Retrieve initial values and updateHomekit
|
|
134
|
+
this.refreshStatus();
|
|
173
135
|
|
|
174
136
|
// Retrieve initial values and updateHomekit
|
|
175
137
|
this.updateHomeKitCharacteristics();
|
|
@@ -182,22 +144,29 @@ export class IOSensor {
|
|
|
182
144
|
});
|
|
183
145
|
|
|
184
146
|
//regisiter webhook event handler
|
|
185
|
-
if (
|
|
186
|
-
this.
|
|
147
|
+
if (device.webhook) {
|
|
148
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} is listening webhook.`);
|
|
187
149
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
188
150
|
try {
|
|
189
151
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
152
|
+
const { temperature, humidity } = context;
|
|
153
|
+
const { CurrentTemperature } = this.TemperatureSensor || { CurrentTemperature: undefined };
|
|
154
|
+
const { CurrentRelativeHumidity } = this.HumiditySensor || { CurrentRelativeHumidity: undefined };
|
|
155
|
+
if (context.scale !== 'CELCIUS' && device.iosensor?.convertUnitTo === undefined) {
|
|
156
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} received a non-CELCIUS Webhook scale: `
|
|
157
|
+
+ `${context.scale}, Use the *convertUnitsTo* config under Indoor/Outdoor Sensor settings, if displaying incorrectly in HomeKit.`);
|
|
158
|
+
}
|
|
159
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
160
|
+
'(scale, temperature, humidity) = '
|
|
161
|
+
+ `Webhook:(${context.scale}, ${convertUnits(temperature, context.scale, device.iosensor?.convertUnitTo)}, ${humidity}), `
|
|
162
|
+
+ `current:(${CurrentTemperature}, ${CurrentRelativeHumidity})`);
|
|
163
|
+
if (this.device.iosensor?.hide_humidity) {
|
|
164
|
+
this.HumiditySensor!.CurrentRelativeHumidity = humidity;
|
|
165
|
+
}
|
|
166
|
+
if (this.device.iosensor?.hide_temperature) {
|
|
167
|
+
this.TemperatureSensor!.CurrentTemperature = convertUnits(temperature, context.scale, device.iosensor?.convertUnitTo);
|
|
200
168
|
}
|
|
169
|
+
this.updateHomeKitCharacteristics();
|
|
201
170
|
} catch (e: any) {
|
|
202
171
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
203
172
|
+ `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
@@ -206,89 +175,70 @@ export class IOSensor {
|
|
|
206
175
|
}
|
|
207
176
|
}
|
|
208
177
|
|
|
209
|
-
|
|
210
|
-
* Parse the device status from the SwitchBot api
|
|
211
|
-
*/
|
|
212
|
-
async parseStatus(): Promise<void> {
|
|
213
|
-
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
214
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} parseStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
215
|
-
} else if (this.BLE) {
|
|
216
|
-
await this.BLEparseStatus();
|
|
217
|
-
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
218
|
-
await this.openAPIparseStatus();
|
|
219
|
-
} else {
|
|
220
|
-
await this.offlineOff();
|
|
221
|
-
this.debugWarnLog(
|
|
222
|
-
`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`,
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
async BLEparseStatus(): Promise<void> {
|
|
178
|
+
async BLEparseStatus(serviceData: serviceData): Promise<void> {
|
|
228
179
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
229
180
|
|
|
230
181
|
// Battery
|
|
231
|
-
this.BatteryLevel = Number(
|
|
232
|
-
if (this.BatteryLevel <
|
|
233
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
182
|
+
this.Battery.BatteryLevel = Number(serviceData.battery);
|
|
183
|
+
if (this.Battery.BatteryLevel < 10) {
|
|
184
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
234
185
|
} else {
|
|
235
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
186
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
236
187
|
}
|
|
237
|
-
this.debugLog(`${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
|
|
188
|
+
this.debugLog(`${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}, StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
238
189
|
|
|
239
190
|
// Humidity
|
|
240
|
-
if (!this.device.
|
|
241
|
-
this.CurrentRelativeHumidity =
|
|
242
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
|
|
191
|
+
if (!this.device.iosensor?.hide_humidity) {
|
|
192
|
+
this.HumiditySensor!.CurrentRelativeHumidity = serviceData.humidity!;
|
|
193
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Humidity: ${this.HumiditySensor!.CurrentRelativeHumidity}%`);
|
|
243
194
|
}
|
|
244
195
|
|
|
245
196
|
// Current Temperature
|
|
246
|
-
if (!this.device.
|
|
247
|
-
|
|
248
|
-
this.CurrentTemperature =
|
|
249
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
|
|
197
|
+
if (!this.device.iosensor?.hide_temperature) {
|
|
198
|
+
serviceData.temperature!.c < 0 ? 0 : serviceData.temperature!.c > 100 ? 100 : serviceData.temperature!.c;
|
|
199
|
+
this.TemperatureSensor!.CurrentTemperature = serviceData.temperature!.c;
|
|
200
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.TemperatureSensor!.CurrentTemperature}°c`);
|
|
250
201
|
}
|
|
251
202
|
}
|
|
252
203
|
|
|
253
|
-
async openAPIparseStatus(): Promise<void> {
|
|
204
|
+
async openAPIparseStatus(deviceStatus: deviceStatus): Promise<void> {
|
|
254
205
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
206
|
+
|
|
207
|
+
// BatteryLevel
|
|
208
|
+
this.Battery.BatteryLevel = Number(deviceStatus.body.battery);
|
|
209
|
+
if (this.Battery.BatteryLevel < 10) {
|
|
210
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
259
211
|
} else {
|
|
260
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
212
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
213
|
+
}
|
|
214
|
+
if (Number.isNaN(this.Battery.BatteryLevel)) {
|
|
215
|
+
this.Battery.BatteryLevel = 100;
|
|
261
216
|
}
|
|
262
|
-
this.debugLog(`${this.
|
|
217
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel},`
|
|
218
|
+
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
263
219
|
|
|
264
220
|
// Current Relative Humidity
|
|
265
|
-
if (!this.device.
|
|
266
|
-
this.CurrentRelativeHumidity =
|
|
267
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
|
|
221
|
+
if (!this.device.iosensor?.hide_humidity) {
|
|
222
|
+
this.HumiditySensor!.CurrentRelativeHumidity = deviceStatus.body.humidity!;
|
|
223
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Humidity: ${this.HumiditySensor!.CurrentRelativeHumidity}%`);
|
|
268
224
|
}
|
|
269
225
|
|
|
270
226
|
// Current Temperature
|
|
271
|
-
if (!this.device.
|
|
272
|
-
this.CurrentTemperature =
|
|
273
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
this.
|
|
278
|
-
if (
|
|
279
|
-
this.
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
227
|
+
if (!this.device.iosensor?.hide_temperature) {
|
|
228
|
+
this.TemperatureSensor!.CurrentTemperature = deviceStatus.body.temperature!;
|
|
229
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.TemperatureSensor!.CurrentTemperature}°c`);
|
|
230
|
+
}
|
|
231
|
+
// Firmware Version
|
|
232
|
+
const version = deviceStatus.body.version?.toString();
|
|
233
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Firmware Version: ${version?.replace(/^V|-.*$/g, '')}`);
|
|
234
|
+
if (deviceStatus.body.version) {
|
|
235
|
+
this.accessory.context.version = version?.replace(/^V|-.*$/g, '');
|
|
236
|
+
this.accessory
|
|
237
|
+
.getService(this.hap.Service.AccessoryInformation)!
|
|
238
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, this.accessory.context.version)
|
|
239
|
+
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
240
|
+
.updateValue(this.accessory.context.version);
|
|
285
241
|
}
|
|
286
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},`
|
|
287
|
-
+ ` StatusLowBattery: ${this.StatusLowBattery}`);
|
|
288
|
-
|
|
289
|
-
// FirmwareRevision
|
|
290
|
-
this.FirmwareRevision = this.OpenAPI_FirmwareRevision!;
|
|
291
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
292
242
|
}
|
|
293
243
|
|
|
294
244
|
/**
|
|
@@ -323,107 +273,43 @@ export class IOSensor {
|
|
|
323
273
|
// Start to monitor advertisement packets
|
|
324
274
|
(async () => {
|
|
325
275
|
// Start to monitor advertisement packets
|
|
326
|
-
await switchbot.startScan({
|
|
327
|
-
model: 'w',
|
|
328
|
-
id: this.device.bleMac,
|
|
329
|
-
});
|
|
276
|
+
await switchbot.startScan({ model: this.device.bleModel, id: this.device.bleMac });
|
|
330
277
|
// Set an event handler
|
|
331
278
|
switchbot.onadvertisement = (ad: any) => {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
279
|
+
if (this.device.bleMac === ad.address && ad.model === this.device.bleModel) {
|
|
280
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
|
|
281
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.model}`);
|
|
335
282
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
336
|
-
this.BLE_CurrentTemperature = ad.serviceData.temperature;
|
|
337
|
-
this.BLE_Celsius = ad.serviceData.temperature!.c;
|
|
338
|
-
this.BLE_Fahrenheit = ad.serviceData.temperature!.f;
|
|
339
|
-
this.BLE_BatteryLevel = ad.serviceData.battery;
|
|
340
283
|
} else {
|
|
341
284
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
342
285
|
}
|
|
343
286
|
};
|
|
344
|
-
// Wait
|
|
287
|
+
// Wait 10 seconds
|
|
345
288
|
await switchbot.wait(this.scanDuration * 1000);
|
|
346
289
|
// Stop to monitor
|
|
347
290
|
await switchbot.stopScan();
|
|
348
291
|
// Update HomeKit
|
|
349
|
-
await this.BLEparseStatus();
|
|
292
|
+
await this.BLEparseStatus(switchbot.onadvertisement.serviceData);
|
|
350
293
|
await this.updateHomeKitCharacteristics();
|
|
351
294
|
})();
|
|
352
|
-
|
|
353
|
-
switchbot
|
|
354
|
-
.startScan({
|
|
355
|
-
model: 'w',
|
|
356
|
-
id: this.device.bleMac,
|
|
357
|
-
})
|
|
358
|
-
.then(async () => {
|
|
359
|
-
// Set an event handler
|
|
360
|
-
switchbot.onadvertisement = async (ad: ad) => {
|
|
361
|
-
this.debugLog(
|
|
362
|
-
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
363
|
-
` BLE Address Found: ${ad.address}`,
|
|
364
|
-
);
|
|
365
|
-
if (ad.serviceData.humidity! > 0) {
|
|
366
|
-
// reject unreliable data
|
|
367
|
-
this.BLE_CurrentRelativeHumidity = ad.serviceData.humidity;
|
|
368
|
-
}
|
|
369
|
-
this.BLE_CurrentTemperature = ad.serviceData.temperature;
|
|
370
|
-
this.BLE_Celsius = ad.serviceData.temperature!.c;
|
|
371
|
-
this.BLE_Fahrenheit = ad.serviceData.temperature!.f;
|
|
372
|
-
this.BLE_BatteryLevel = ad.serviceData.battery;
|
|
373
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
374
|
-
this.debugLog(
|
|
375
|
-
`${this.device.deviceType}: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName}, ` +
|
|
376
|
-
`temperature: ${JSON.stringify(ad.serviceData.temperature?.c)}, humidity: ${ad.serviceData.humidity}, ` +
|
|
377
|
-
`battery: ${ad.serviceData.battery}`,
|
|
378
|
-
);
|
|
379
|
-
|
|
380
|
-
if (ad.serviceData) {
|
|
381
|
-
this.BLE_IsConnected = true;
|
|
382
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
383
|
-
await this.stopScanning(switchbot);
|
|
384
|
-
} else {
|
|
385
|
-
this.BLE_IsConnected = false;
|
|
386
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
387
|
-
}
|
|
388
|
-
};
|
|
389
|
-
// Wait
|
|
390
|
-
return await sleep(this.scanDuration * 1000);
|
|
391
|
-
})
|
|
392
|
-
.then(async () => {
|
|
393
|
-
// Stop to monitor
|
|
394
|
-
await this.stopScanning(switchbot);
|
|
395
|
-
})
|
|
396
|
-
.catch(async (e: any) => {
|
|
397
|
-
this.apiError(e);
|
|
398
|
-
this.errorLog(
|
|
399
|
-
`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
|
|
400
|
-
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
401
|
-
);
|
|
402
|
-
await this.BLERefreshConnection(switchbot);
|
|
403
|
-
});
|
|
404
|
-
} else {
|
|
295
|
+
if (switchbot === undefined) {
|
|
405
296
|
await this.BLERefreshConnection(switchbot);
|
|
406
|
-
}
|
|
297
|
+
}
|
|
407
298
|
}
|
|
408
299
|
|
|
409
300
|
async openAPIRefreshStatus(): Promise<void> {
|
|
410
301
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
411
302
|
try {
|
|
412
|
-
const { body, statusCode } = await
|
|
413
|
-
headers: this.platform.generateHeaders()
|
|
414
|
-
});
|
|
303
|
+
const { body, statusCode } = await this.platform.retryRequest(this.deviceMaxRetries, this.deviceDelayBetweenRetries,
|
|
304
|
+
`${Devices}/${this.device.deviceId}/status`, { headers: this.platform.generateHeaders() });
|
|
415
305
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
416
306
|
const deviceStatus: any = await body.json();
|
|
417
307
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
418
308
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
419
309
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
420
|
-
this.
|
|
310
|
+
this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
421
311
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
422
|
-
this.
|
|
423
|
-
this.OpenAPI_CurrentTemperature = deviceStatus.body.temperature!;
|
|
424
|
-
this.OpenAPI_BatteryLevel = deviceStatus.body.battery;
|
|
425
|
-
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
426
|
-
this.openAPIparseStatus();
|
|
312
|
+
this.openAPIparseStatus(deviceStatus);
|
|
427
313
|
this.updateHomeKitCharacteristics();
|
|
428
314
|
} else {
|
|
429
315
|
this.statusCode(statusCode);
|
|
@@ -444,63 +330,73 @@ export class IOSensor {
|
|
|
444
330
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
445
331
|
const mqttmessage: string[] = [];
|
|
446
332
|
const entry = { time: Math.round(new Date().valueOf() / 1000) };
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
333
|
+
|
|
334
|
+
// CurrentRelativeHumidity
|
|
335
|
+
if (!this.device.iosensor?.hide_humidity) {
|
|
336
|
+
if (this.HumiditySensor!.CurrentRelativeHumidity === undefined) {
|
|
337
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
338
|
+
+ ` CurrentRelativeHumidity: ${this.HumiditySensor!.CurrentRelativeHumidity}`);
|
|
450
339
|
} else {
|
|
451
|
-
this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
|
|
452
|
-
this.
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
`
|
|
456
|
-
);
|
|
340
|
+
this.accessory.context.CurrentRelativeHumidity = this.HumiditySensor!.CurrentRelativeHumidity;
|
|
341
|
+
this.HumiditySensor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity,
|
|
342
|
+
this.HumiditySensor!.CurrentRelativeHumidity);
|
|
343
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
344
|
+
+ ` CurrentRelativeHumidity: ${this.HumiditySensor!.CurrentRelativeHumidity}`);
|
|
457
345
|
if (this.device.mqttURL) {
|
|
458
|
-
mqttmessage.push(`"humidity": ${this.CurrentRelativeHumidity}`);
|
|
346
|
+
mqttmessage.push(`"humidity": ${this.HumiditySensor!.CurrentRelativeHumidity}`);
|
|
459
347
|
}
|
|
460
348
|
if (this.device.history) {
|
|
461
|
-
entry['humidity'] = this.CurrentRelativeHumidity;
|
|
349
|
+
entry['humidity'] = this.HumiditySensor!.CurrentRelativeHumidity;
|
|
462
350
|
}
|
|
463
351
|
}
|
|
464
352
|
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
353
|
+
|
|
354
|
+
// CurrentTemperature
|
|
355
|
+
if (!this.device.iosensor?.hide_temperature) {
|
|
356
|
+
if (this.TemperatureSensor!.CurrentTemperature === undefined) {
|
|
357
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.TemperatureSensor!.CurrentTemperature}`);
|
|
468
358
|
} else {
|
|
359
|
+
this.accessory.context.CurrentTemperature = this.TemperatureSensor!.CurrentTemperature;
|
|
360
|
+
this.TemperatureSensor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.TemperatureSensor!.CurrentTemperature);
|
|
361
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
362
|
+
+ ` CurrentTemperature: ${this.TemperatureSensor!.CurrentTemperature}`);
|
|
469
363
|
if (this.device.mqttURL) {
|
|
470
|
-
mqttmessage.push(`"temperature": ${this.CurrentTemperature}`);
|
|
364
|
+
mqttmessage.push(`"temperature": ${this.TemperatureSensor!.CurrentTemperature}`);
|
|
471
365
|
}
|
|
472
366
|
if (this.device.history) {
|
|
473
|
-
entry['temp'] = this.CurrentTemperature;
|
|
367
|
+
entry['temp'] = this.TemperatureSensor!.CurrentTemperature;
|
|
474
368
|
}
|
|
475
|
-
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
476
|
-
this.temperatureservice?.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.CurrentTemperature);
|
|
477
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
|
|
478
369
|
}
|
|
479
370
|
}
|
|
480
|
-
if (this.BatteryLevel === undefined) {
|
|
481
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
371
|
+
if (this.Battery.BatteryLevel === undefined) {
|
|
372
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
482
373
|
} else {
|
|
374
|
+
this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
|
|
375
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
|
|
376
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
483
377
|
if (this.device.mqttURL) {
|
|
484
|
-
mqttmessage.push(`"battery": ${this.BatteryLevel}`);
|
|
378
|
+
mqttmessage.push(`"battery": ${this.Battery.BatteryLevel}`);
|
|
485
379
|
}
|
|
486
|
-
this.accessory.context.BatteryLevel = this.BatteryLevel;
|
|
487
|
-
this.batteryService?.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.BatteryLevel);
|
|
488
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
489
380
|
}
|
|
490
|
-
if (this.StatusLowBattery === undefined) {
|
|
491
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
|
|
381
|
+
if (this.Battery.StatusLowBattery === undefined) {
|
|
382
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
492
383
|
} else {
|
|
384
|
+
this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
|
|
385
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
|
|
386
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
387
|
+
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
493
388
|
if (this.device.mqttURL) {
|
|
494
|
-
mqttmessage.push(`"lowBattery": ${this.StatusLowBattery}`);
|
|
389
|
+
mqttmessage.push(`"lowBattery": ${this.Battery.StatusLowBattery}`);
|
|
495
390
|
}
|
|
496
|
-
this.accessory.context.StatusLowBattery = this.StatusLowBattery;
|
|
497
|
-
this.batteryService?.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
498
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
499
391
|
}
|
|
392
|
+
|
|
393
|
+
// MQTT Publish
|
|
500
394
|
if (this.device.mqttURL) {
|
|
501
395
|
this.mqttPublish(`{${mqttmessage.join(',')}}`);
|
|
502
396
|
}
|
|
503
|
-
|
|
397
|
+
|
|
398
|
+
// History Service
|
|
399
|
+
if (!this.device.iosensor?.hide_humidity && (Number(this.HumiditySensor!.CurrentRelativeHumidity) > 0)) {
|
|
504
400
|
// reject unreliable data
|
|
505
401
|
if (this.device.history) {
|
|
506
402
|
this.historyService?.addEntry(entry);
|
|
@@ -508,84 +404,6 @@ export class IOSensor {
|
|
|
508
404
|
}
|
|
509
405
|
}
|
|
510
406
|
|
|
511
|
-
/*
|
|
512
|
-
* Publish MQTT message for topics of
|
|
513
|
-
* 'homebridge-switchbot/meter/xx:xx:xx:xx:xx:xx'
|
|
514
|
-
*/
|
|
515
|
-
mqttPublish(message: any) {
|
|
516
|
-
const mac = this.device.deviceId
|
|
517
|
-
?.toLowerCase()
|
|
518
|
-
.match(/[\s\S]{1,2}/g)
|
|
519
|
-
?.join(':');
|
|
520
|
-
const options = this.device.mqttPubOptions || {};
|
|
521
|
-
this.mqttClient?.publish(`homebridge-switchbot/meter/${mac}`, `${message}`, options);
|
|
522
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MQTT message: ${message} options:${JSON.stringify(options)}`);
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
/*
|
|
526
|
-
* Setup MQTT hadler if URL is specified.
|
|
527
|
-
*/
|
|
528
|
-
async setupMqtt(device: device & devicesConfig): Promise<void> {
|
|
529
|
-
if (device.mqttURL) {
|
|
530
|
-
try {
|
|
531
|
-
const { connectAsync } = asyncmqtt;
|
|
532
|
-
this.mqttClient = await connectAsync(device.mqttURL, device.mqttOptions || {});
|
|
533
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MQTT connection has been established successfully.`);
|
|
534
|
-
this.mqttClient.on('error', (e: Error) => {
|
|
535
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Failed to publish MQTT messages. ${e}`);
|
|
536
|
-
});
|
|
537
|
-
} catch (e) {
|
|
538
|
-
this.mqttClient = null;
|
|
539
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Failed to establish MQTT connection. ${e}`);
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
/*
|
|
545
|
-
* Setup EVE history graph feature if enabled.
|
|
546
|
-
*/
|
|
547
|
-
async setupHistoryService(device: device & devicesConfig): Promise<void> {
|
|
548
|
-
const mac = this.device
|
|
549
|
-
.deviceId!.match(/.{1,2}/g)!
|
|
550
|
-
.join(':')
|
|
551
|
-
.toLowerCase();
|
|
552
|
-
this.historyService = device.history
|
|
553
|
-
? new this.platform.fakegatoAPI('room', this.accessory, {
|
|
554
|
-
log: this.platform.log,
|
|
555
|
-
storage: 'fs',
|
|
556
|
-
filename: `${hostname().split('.')[0]}_${mac}_persist.json`,
|
|
557
|
-
})
|
|
558
|
-
: null;
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
async stopScanning(switchbot: any) {
|
|
562
|
-
switchbot.stopScan();
|
|
563
|
-
if (this.BLE_IsConnected) {
|
|
564
|
-
await this.BLEparseStatus();
|
|
565
|
-
await this.updateHomeKitCharacteristics();
|
|
566
|
-
} else {
|
|
567
|
-
await this.BLERefreshConnection(switchbot);
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
async getCustomBLEAddress(switchbot: any) {
|
|
572
|
-
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
573
|
-
(async () => {
|
|
574
|
-
// Start to monitor advertisement packets
|
|
575
|
-
await switchbot.startScan({
|
|
576
|
-
model: 'i',
|
|
577
|
-
});
|
|
578
|
-
// Set an event handler
|
|
579
|
-
switchbot.onadvertisement = (ad: any) => {
|
|
580
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
|
|
581
|
-
};
|
|
582
|
-
await sleep(10000);
|
|
583
|
-
// Stop to monitor
|
|
584
|
-
switchbot.stopScan();
|
|
585
|
-
})();
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
|
|
589
407
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
590
408
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot:`
|
|
591
409
|
+ ` ${JSON.stringify(switchbot)}`);
|
|
@@ -595,249 +413,26 @@ export class IOSensor {
|
|
|
595
413
|
}
|
|
596
414
|
}
|
|
597
415
|
|
|
598
|
-
async scan(device: device & devicesConfig): Promise<void> {
|
|
599
|
-
if (device.scanDuration) {
|
|
600
|
-
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
601
|
-
if (this.BLE) {
|
|
602
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
603
|
-
}
|
|
604
|
-
} else {
|
|
605
|
-
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
606
|
-
if (this.BLE) {
|
|
607
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
async statusCode(statusCode: number): Promise<void> {
|
|
613
|
-
switch (statusCode) {
|
|
614
|
-
case 151:
|
|
615
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
616
|
-
break;
|
|
617
|
-
case 152:
|
|
618
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
619
|
-
break;
|
|
620
|
-
case 160:
|
|
621
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
622
|
-
break;
|
|
623
|
-
case 161:
|
|
624
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
625
|
-
this.offlineOff();
|
|
626
|
-
break;
|
|
627
|
-
case 171:
|
|
628
|
-
this.errorLog(
|
|
629
|
-
`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
630
|
-
`Hub: ${this.device.hubDeviceId}`,
|
|
631
|
-
);
|
|
632
|
-
this.offlineOff();
|
|
633
|
-
break;
|
|
634
|
-
case 190:
|
|
635
|
-
this.errorLog(
|
|
636
|
-
`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
637
|
-
` Or command format is invalid, statusCode: ${statusCode}`,
|
|
638
|
-
);
|
|
639
|
-
break;
|
|
640
|
-
case 100:
|
|
641
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
642
|
-
break;
|
|
643
|
-
case 200:
|
|
644
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
645
|
-
break;
|
|
646
|
-
case 400:
|
|
647
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
|
|
648
|
-
+ `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
|
|
649
|
-
break;
|
|
650
|
-
case 401:
|
|
651
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
|
|
652
|
-
+ `but the request has not been authenticated, statusCode: ${statusCode}`);
|
|
653
|
-
break;
|
|
654
|
-
case 403:
|
|
655
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
|
|
656
|
-
+ `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
|
|
657
|
-
break;
|
|
658
|
-
case 404:
|
|
659
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
|
|
660
|
-
+ `statusCode: ${statusCode}`);
|
|
661
|
-
break;
|
|
662
|
-
case 406:
|
|
663
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
|
|
664
|
-
+ `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
|
|
665
|
-
break;
|
|
666
|
-
case 415:
|
|
667
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
|
|
668
|
-
+ `header that is not supported by the server, statusCode: ${statusCode}`);
|
|
669
|
-
break;
|
|
670
|
-
case 422:
|
|
671
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, `
|
|
672
|
-
+ `but the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
673
|
-
break;
|
|
674
|
-
case 429:
|
|
675
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
|
|
676
|
-
+ `requests allowed for a given time window, statusCode: ${statusCode}`);
|
|
677
|
-
break;
|
|
678
|
-
case 500:
|
|
679
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
|
|
680
|
-
+ `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
|
|
681
|
-
break;
|
|
682
|
-
default:
|
|
683
|
-
this.infoLog(
|
|
684
|
-
`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
685
|
-
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
|
|
686
|
-
);
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
|
|
690
416
|
async offlineOff(): Promise<void> {
|
|
691
417
|
if (this.device.offline) {
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
async apiError(e: any): Promise<void> {
|
|
698
|
-
if (!this.device.meter?.hide_humidity) {
|
|
699
|
-
this.humidityservice?.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e);
|
|
700
|
-
}
|
|
701
|
-
if (!this.device.meter?.hide_temperature) {
|
|
702
|
-
this.temperatureservice?.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
|
|
703
|
-
}
|
|
704
|
-
this.batteryService?.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
|
|
705
|
-
this.batteryService?.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
async deviceContext() {
|
|
709
|
-
if (this.CurrentRelativeHumidity === undefined) {
|
|
710
|
-
this.CurrentRelativeHumidity = 0;
|
|
711
|
-
} else {
|
|
712
|
-
this.CurrentRelativeHumidity = this.accessory.context.CurrentRelativeHumidity;
|
|
713
|
-
}
|
|
714
|
-
if (this.CurrentTemperature === undefined) {
|
|
715
|
-
this.CurrentTemperature = 0;
|
|
716
|
-
} else {
|
|
717
|
-
this.CurrentTemperature = this.accessory.context.CurrentTemperature;
|
|
718
|
-
}
|
|
719
|
-
if (this.BatteryLevel === undefined) {
|
|
720
|
-
this.BatteryLevel = 100;
|
|
721
|
-
} else {
|
|
722
|
-
this.BatteryLevel = this.accessory.context.BatteryLevel;
|
|
723
|
-
}
|
|
724
|
-
if (this.StatusLowBattery === undefined) {
|
|
725
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
726
|
-
this.accessory.context.StatusLowBattery = this.StatusLowBattery;
|
|
727
|
-
} else {
|
|
728
|
-
this.StatusLowBattery = this.accessory.context.StatusLowBattery;
|
|
729
|
-
}
|
|
730
|
-
if (this.FirmwareRevision === undefined) {
|
|
731
|
-
this.FirmwareRevision = this.platform.version;
|
|
732
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
async refreshRate(device: device & devicesConfig): Promise<void> {
|
|
737
|
-
if (device.refreshRate) {
|
|
738
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
739
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
740
|
-
} else if (this.platform.config.options!.refreshRate) {
|
|
741
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
|
|
742
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
async deviceConfig(device: device & devicesConfig): Promise<void> {
|
|
747
|
-
let config = {};
|
|
748
|
-
if (device.meter) {
|
|
749
|
-
config = device.meter;
|
|
750
|
-
}
|
|
751
|
-
if (device.connectionType !== undefined) {
|
|
752
|
-
config['connectionType'] = device.connectionType;
|
|
753
|
-
}
|
|
754
|
-
if (device.external !== undefined) {
|
|
755
|
-
config['external'] = device.external;
|
|
756
|
-
}
|
|
757
|
-
if (device.mqttURL !== undefined) {
|
|
758
|
-
config['mqttURL'] = device.mqttURL;
|
|
759
|
-
}
|
|
760
|
-
if (device.logging !== undefined) {
|
|
761
|
-
config['logging'] = device.logging;
|
|
762
|
-
}
|
|
763
|
-
if (device.refreshRate !== undefined) {
|
|
764
|
-
config['refreshRate'] = device.refreshRate;
|
|
765
|
-
}
|
|
766
|
-
if (device.scanDuration !== undefined) {
|
|
767
|
-
config['scanDuration'] = device.scanDuration;
|
|
768
|
-
}
|
|
769
|
-
if (device.webhook !== undefined) {
|
|
770
|
-
config['webhook'] = device.webhook;
|
|
771
|
-
}
|
|
772
|
-
if (Object.entries(config).length !== 0) {
|
|
773
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
async deviceLogs(device: device & devicesConfig): Promise<void> {
|
|
778
|
-
if (this.platform.debugMode) {
|
|
779
|
-
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
780
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
781
|
-
} else if (device.logging) {
|
|
782
|
-
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
783
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
784
|
-
} else if (this.platform.config.options?.logging) {
|
|
785
|
-
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
786
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
787
|
-
} else {
|
|
788
|
-
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
789
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
|
|
793
|
-
/**
|
|
794
|
-
* Logging for Device
|
|
795
|
-
*/
|
|
796
|
-
infoLog(...log: any[]): void {
|
|
797
|
-
if (this.enablingDeviceLogging()) {
|
|
798
|
-
this.platform.log.info(String(...log));
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
warnLog(...log: any[]): void {
|
|
803
|
-
if (this.enablingDeviceLogging()) {
|
|
804
|
-
this.platform.log.warn(String(...log));
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
debugWarnLog(...log: any[]): void {
|
|
809
|
-
if (this.enablingDeviceLogging()) {
|
|
810
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
811
|
-
this.platform.log.warn('[DEBUG]', String(...log));
|
|
418
|
+
if (!this.device.iosensor?.hide_humidity) {
|
|
419
|
+
this.HumiditySensor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, 50);
|
|
812
420
|
}
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
errorLog(...log: any[]): void {
|
|
817
|
-
if (this.enablingDeviceLogging()) {
|
|
818
|
-
this.platform.log.error(String(...log));
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
debugErrorLog(...log: any[]): void {
|
|
823
|
-
if (this.enablingDeviceLogging()) {
|
|
824
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
825
|
-
this.platform.log.error('[DEBUG]', String(...log));
|
|
421
|
+
if (!this.device.iosensor?.hide_temperature) {
|
|
422
|
+
this.TemperatureSensor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, 30);
|
|
826
423
|
}
|
|
424
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, 100);
|
|
827
425
|
}
|
|
828
426
|
}
|
|
829
427
|
|
|
830
|
-
|
|
831
|
-
if (this.
|
|
832
|
-
|
|
833
|
-
this.platform.log.info('[DEBUG]', String(...log));
|
|
834
|
-
} else {
|
|
835
|
-
this.platform.log.debug(String(...log));
|
|
836
|
-
}
|
|
428
|
+
async apiError(e: any): Promise<void> {
|
|
429
|
+
if (!this.device.iosensor?.hide_humidity) {
|
|
430
|
+
this.HumiditySensor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e);
|
|
837
431
|
}
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
432
|
+
if (!this.device.iosensor?.hide_temperature) {
|
|
433
|
+
this.TemperatureSensor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
|
|
434
|
+
}
|
|
435
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
|
|
436
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
|
|
842
437
|
}
|
|
843
438
|
}
|