@switchbot/homebridge-switchbot 3.7.1-beta.11 → 3.7.1-beta.13

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