@switchbot/homebridge-switchbot 3.5.0-beta.3 → 3.5.0-beta.31

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 (166) hide show
  1. package/CHANGELOG.md +4 -1
  2. package/config.schema.json +147 -9
  3. package/dist/device/blindtilt.d.ts +21 -94
  4. package/dist/device/blindtilt.d.ts.map +1 -1
  5. package/dist/device/blindtilt.js +347 -756
  6. package/dist/device/blindtilt.js.map +1 -1
  7. package/dist/device/bot.d.ts +25 -71
  8. package/dist/device/bot.d.ts.map +1 -1
  9. package/dist/device/bot.js +582 -759
  10. package/dist/device/bot.js.map +1 -1
  11. package/dist/device/ceilinglight.d.ts +13 -67
  12. package/dist/device/ceilinglight.d.ts.map +1 -1
  13. package/dist/device/ceilinglight.js +209 -587
  14. package/dist/device/ceilinglight.js.map +1 -1
  15. package/dist/device/colorbulb.d.ts +13 -74
  16. package/dist/device/colorbulb.d.ts.map +1 -1
  17. package/dist/device/colorbulb.js +250 -632
  18. package/dist/device/colorbulb.js.map +1 -1
  19. package/dist/device/contact.d.ts +14 -65
  20. package/dist/device/contact.d.ts.map +1 -1
  21. package/dist/device/contact.js +204 -531
  22. package/dist/device/contact.js.map +1 -1
  23. package/dist/device/curtain.d.ts +17 -86
  24. package/dist/device/curtain.d.ts.map +1 -1
  25. package/dist/device/curtain.js +335 -786
  26. package/dist/device/curtain.js.map +1 -1
  27. package/dist/device/device.d.ts +59 -0
  28. package/dist/device/device.d.ts.map +1 -0
  29. package/dist/device/device.js +654 -0
  30. package/dist/device/device.js.map +1 -0
  31. package/dist/device/fan.d.ts +51 -0
  32. package/dist/device/fan.d.ts.map +1 -0
  33. package/dist/device/fan.js +499 -0
  34. package/dist/device/fan.js.map +1 -0
  35. package/dist/device/hub.d.ts +15 -59
  36. package/dist/device/hub.d.ts.map +1 -1
  37. package/dist/device/hub.js +242 -596
  38. package/dist/device/hub.js.map +1 -1
  39. package/dist/device/humidifier.d.ts +10 -65
  40. package/dist/device/humidifier.d.ts.map +1 -1
  41. package/dist/device/humidifier.js +207 -571
  42. package/dist/device/humidifier.js.map +1 -1
  43. package/dist/device/iosensor.d.ts +11 -64
  44. package/dist/device/iosensor.d.ts.map +1 -1
  45. package/dist/device/iosensor.js +174 -584
  46. package/dist/device/iosensor.js.map +1 -1
  47. package/dist/device/lightstrip.d.ts +10 -68
  48. package/dist/device/lightstrip.d.ts.map +1 -1
  49. package/dist/device/lightstrip.js +252 -568
  50. package/dist/device/lightstrip.js.map +1 -1
  51. package/dist/device/lock.d.ts +15 -62
  52. package/dist/device/lock.d.ts.map +1 -1
  53. package/dist/device/lock.js +210 -542
  54. package/dist/device/lock.js.map +1 -1
  55. package/dist/device/meter.d.ts +13 -63
  56. package/dist/device/meter.d.ts.map +1 -1
  57. package/dist/device/meter.js +170 -577
  58. package/dist/device/meter.js.map +1 -1
  59. package/dist/device/meterplus.d.ts +13 -64
  60. package/dist/device/meterplus.d.ts.map +1 -1
  61. package/dist/device/meterplus.js +159 -577
  62. package/dist/device/meterplus.js.map +1 -1
  63. package/dist/device/motion.d.ts +13 -69
  64. package/dist/device/motion.d.ts.map +1 -1
  65. package/dist/device/motion.js +136 -518
  66. package/dist/device/motion.js.map +1 -1
  67. package/dist/device/plug.d.ts +9 -57
  68. package/dist/device/plug.d.ts.map +1 -1
  69. package/dist/device/plug.js +82 -452
  70. package/dist/device/plug.js.map +1 -1
  71. package/dist/device/robotvacuumcleaner.d.ts +11 -62
  72. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  73. package/dist/device/robotvacuumcleaner.js +140 -451
  74. package/dist/device/robotvacuumcleaner.js.map +1 -1
  75. package/dist/device/waterdetector.d.ts +9 -70
  76. package/dist/device/waterdetector.d.ts.map +1 -1
  77. package/dist/device/waterdetector.js +121 -664
  78. package/dist/device/waterdetector.js.map +1 -1
  79. package/dist/index.js +1 -1
  80. package/dist/irdevice/airconditioner.d.ts +8 -48
  81. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  82. package/dist/irdevice/airconditioner.js +309 -419
  83. package/dist/irdevice/airconditioner.js.map +1 -1
  84. package/dist/irdevice/airpurifier.d.ts +7 -38
  85. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  86. package/dist/irdevice/airpurifier.js +72 -304
  87. package/dist/irdevice/airpurifier.js.map +1 -1
  88. package/dist/irdevice/camera.d.ts +6 -35
  89. package/dist/irdevice/camera.d.ts.map +1 -1
  90. package/dist/irdevice/camera.js +34 -278
  91. package/dist/irdevice/camera.js.map +1 -1
  92. package/dist/irdevice/fan.d.ts +6 -39
  93. package/dist/irdevice/fan.d.ts.map +1 -1
  94. package/dist/irdevice/fan.js +67 -311
  95. package/dist/irdevice/fan.js.map +1 -1
  96. package/dist/irdevice/irdevice.d.ts +40 -0
  97. package/dist/irdevice/irdevice.d.ts.map +1 -0
  98. package/dist/irdevice/irdevice.js +509 -0
  99. package/dist/irdevice/irdevice.js.map +1 -0
  100. package/dist/irdevice/light.d.ts +6 -34
  101. package/dist/irdevice/light.d.ts.map +1 -1
  102. package/dist/irdevice/light.js +23 -272
  103. package/dist/irdevice/light.js.map +1 -1
  104. package/dist/irdevice/other.d.ts +18 -47
  105. package/dist/irdevice/other.d.ts.map +1 -1
  106. package/dist/irdevice/other.js +352 -546
  107. package/dist/irdevice/other.js.map +1 -1
  108. package/dist/irdevice/tv.d.ts +7 -39
  109. package/dist/irdevice/tv.d.ts.map +1 -1
  110. package/dist/irdevice/tv.js +82 -321
  111. package/dist/irdevice/tv.js.map +1 -1
  112. package/dist/irdevice/vacuumcleaner.d.ts +6 -35
  113. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  114. package/dist/irdevice/vacuumcleaner.js +41 -284
  115. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  116. package/dist/irdevice/waterheater.d.ts +6 -35
  117. package/dist/irdevice/waterheater.d.ts.map +1 -1
  118. package/dist/irdevice/waterheater.js +42 -287
  119. package/dist/irdevice/waterheater.js.map +1 -1
  120. package/dist/platform.d.ts +14 -1
  121. package/dist/platform.d.ts.map +1 -1
  122. package/dist/platform.js +237 -94
  123. package/dist/platform.js.map +1 -1
  124. package/dist/settings.d.ts +40 -10
  125. package/dist/settings.d.ts.map +1 -1
  126. package/dist/settings.js +0 -552
  127. package/dist/settings.js.map +1 -1
  128. package/dist/utils.d.ts +77 -0
  129. package/dist/utils.d.ts.map +1 -1
  130. package/dist/utils.js +638 -1
  131. package/dist/utils.js.map +1 -1
  132. package/package.json +16 -15
  133. package/src/custom.d.ts +2 -1
  134. package/src/device/blindtilt.ts +373 -782
  135. package/src/device/bot.ts +616 -844
  136. package/src/device/ceilinglight.ts +222 -607
  137. package/src/device/colorbulb.ts +264 -656
  138. package/src/device/contact.ts +229 -553
  139. package/src/device/curtain.ts +355 -810
  140. package/src/device/device.ts +681 -0
  141. package/src/device/fan.ts +548 -0
  142. package/src/device/hub.ts +268 -623
  143. package/src/device/humidifier.ts +237 -618
  144. package/src/device/iosensor.ts +200 -610
  145. package/src/device/lightstrip.ts +273 -596
  146. package/src/device/lock.ts +247 -582
  147. package/src/device/meter.ts +196 -601
  148. package/src/device/meterplus.ts +184 -602
  149. package/src/device/motion.ts +156 -541
  150. package/src/device/plug.ts +92 -480
  151. package/src/device/robotvacuumcleaner.ts +161 -477
  152. package/src/device/waterdetector.ts +139 -689
  153. package/src/index.ts +1 -1
  154. package/src/irdevice/airconditioner.ts +330 -446
  155. package/src/irdevice/airpurifier.ts +89 -321
  156. package/src/irdevice/camera.ts +42 -293
  157. package/src/irdevice/fan.ts +78 -327
  158. package/src/irdevice/irdevice.ts +526 -0
  159. package/src/irdevice/light.ts +32 -287
  160. package/src/irdevice/other.ts +396 -615
  161. package/src/irdevice/tv.ts +100 -339
  162. package/src/irdevice/vacuumcleaner.ts +49 -305
  163. package/src/irdevice/waterheater.ts +50 -310
  164. package/src/platform.ts +247 -102
  165. package/src/settings.ts +56 -565
  166. package/src/utils.ts +642 -1
@@ -1,31 +1,38 @@
1
- import { CharacteristicValue, PlatformAccessory, Service, API, Logging, HAP } from 'homebridge';
1
+ /* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
2
+ *
3
+ * airpurifier.ts: @switchbot/homebridge-switchbot.
4
+ */
2
5
  import { request } from 'undici';
6
+ import { irdeviceBase } from './irdevice.js';
3
7
  import { SwitchBotPlatform } from '../platform.js';
4
- import { Devices, irDevicesConfig, irdevice, SwitchBotPlatformConfig } from '../settings.js';
8
+ import { Devices, irDevicesConfig, irdevice } from '../settings.js';
9
+ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
5
10
 
6
11
  /**
7
12
  * Platform Accessory
8
13
  * An instance of this class is created for each accessory your platform registers
9
14
  * Each accessory may expose multiple services of different service types.
10
15
  */
11
- export class AirPurifier {
12
- public readonly api: API;
13
- public readonly log: Logging;
14
- public readonly config!: SwitchBotPlatformConfig;
15
- protected readonly hap: HAP;
16
+ export class AirPurifier extends irdeviceBase {
16
17
  // Services
17
- airPurifierService!: Service;
18
+ private AirPurifier: {
19
+ Service: Service;
20
+ Active: CharacteristicValue;
21
+ RotationSpeed: CharacteristicValue;
22
+ CurrentAirPurifierState: CharacteristicValue;
23
+ TargetAirPurifierState: CharacteristicValue;
24
+ };
25
+
26
+ private TemperatureSensor: {
27
+ Service: Service;
28
+ CurrentTemperature: CharacteristicValue;
29
+ };
18
30
 
19
31
  // Characteristic Values
20
- Active!: CharacteristicValue;
21
32
  APActive!: CharacteristicValue;
22
33
  CurrentAPTemp!: CharacteristicValue;
23
34
  CurrentAPMode!: CharacteristicValue;
24
- RotationSpeed!: CharacteristicValue;
25
- FirmwareRevision!: CharacteristicValue;
26
35
  CurrentAPFanSpeed!: CharacteristicValue;
27
- CurrentTemperature!: CharacteristicValue;
28
- CurrentAirPurifierState!: CharacteristicValue;
29
36
  CurrentHeaterCoolerState!: CharacteristicValue;
30
37
 
31
38
  // Others
@@ -38,60 +45,50 @@ export class AirPurifier {
38
45
  CurrentFanSpeed!: number;
39
46
  static PURIFYING_AIR: number;
40
47
 
41
- // Config
42
- disablePushOn?: boolean;
43
- disablePushOff?: boolean;
44
- deviceLogging!: string;
45
-
46
48
  constructor(
47
- private readonly platform: SwitchBotPlatform,
48
- private accessory: PlatformAccessory,
49
- public device: irdevice & irDevicesConfig,
49
+ readonly platform: SwitchBotPlatform,
50
+ accessory: PlatformAccessory,
51
+ device: irdevice & irDevicesConfig,
50
52
  ) {
51
- this.api = this.platform.api;
52
- this.log = this.platform.log;
53
- this.config = this.platform.config;
54
- this.hap = this.api.hap;
55
- // default placeholders
56
- this.deviceLogs(device);
57
- this.deviceContext();
58
- this.disablePushOnChanges(device);
59
- this.disablePushOffChanges(device);
60
- this.deviceConfig(device);
61
-
62
- // set accessory information
63
- accessory
64
- .getService(this.hap.Service.AccessoryInformation)!
65
- .setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
66
- .setCharacteristic(this.hap.Characteristic.Model, device.remoteType)
67
- .setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
68
- .setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
53
+ super(platform, accessory, device);
54
+
55
+ // Initialize AirPurifier property
56
+ this.AirPurifier = {
57
+ Service: accessory.getService(this.hap.Service.Switch)!,
58
+ Active: accessory.context.Active || this.hap.Characteristic.Active.INACTIVE,
59
+ RotationSpeed: accessory.context.RotationSpeed || 0,
60
+ CurrentAirPurifierState: accessory.context.CurrentAirPurifierState || this.hap.Characteristic.CurrentAirPurifierState.INACTIVE,
61
+ TargetAirPurifierState: accessory.context.TargetAirPurifierState || this.hap.Characteristic.TargetAirPurifierState.AUTO,
62
+ };
63
+
64
+ // Initialize TemperatureSensor property
65
+ this.TemperatureSensor = {
66
+ Service: accessory.getService(this.hap.Service.TemperatureSensor)!,
67
+ CurrentTemperature: accessory.context.CurrentTemperature || 24,
68
+ };
69
69
 
70
70
  // get the Television service if it exists, otherwise create a new Television service
71
71
  // you can create multiple services for each accessory
72
- const airPurifierService = `${accessory.displayName} Air Purifier`;
73
- (this.airPurifierService = accessory.getService(this.hap.Service.AirPurifier)
74
- || accessory.addService(this.hap.Service.AirPurifier)), airPurifierService;
72
+ const AirPurifierService = `${accessory.displayName} Air Purifier`;
73
+ (this.AirPurifier.Service = accessory.getService(this.hap.Service.AirPurifier)
74
+ || accessory.addService(this.hap.Service.AirPurifier)), AirPurifierService;
75
75
 
76
- this.airPurifierService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
77
- if (!this.airPurifierService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
78
- this.airPurifierService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
79
- }
76
+ this.AirPurifier.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
80
77
  // handle on / off events using the Active characteristic
81
- this.airPurifierService.getCharacteristic(this.hap.Characteristic.Active).onSet(this.ActiveSet.bind(this));
78
+ this.AirPurifier.Service.getCharacteristic(this.hap.Characteristic.Active).onSet(this.ActiveSet.bind(this));
82
79
 
83
- this.airPurifierService.getCharacteristic(this.hap.Characteristic.CurrentAirPurifierState).onGet(() => {
80
+ this.AirPurifier.Service.getCharacteristic(this.hap.Characteristic.CurrentAirPurifierState).onGet(() => {
84
81
  return this.CurrentAirPurifierStateGet();
85
82
  });
86
83
 
87
- this.airPurifierService.getCharacteristic(this.hap.Characteristic.TargetAirPurifierState).onSet(this.TargetAirPurifierStateSet.bind(this));
84
+ this.AirPurifier.Service.getCharacteristic(this.hap.Characteristic.TargetAirPurifierState).onSet(this.TargetAirPurifierStateSet.bind(this));
88
85
  }
89
86
 
90
87
  async ActiveSet(value: CharacteristicValue): Promise<void> {
91
88
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Active: ${value}`);
92
89
 
93
- this.Active = value;
94
- if (this.Active === this.hap.Characteristic.Active.ACTIVE) {
90
+ this.AirPurifier.Active = value;
91
+ if (this.AirPurifier.Active === this.hap.Characteristic.Active.ACTIVE) {
95
92
  this.pushAirPurifierOnChanges();
96
93
  } else {
97
94
  this.pushAirPurifierOffChanges();
@@ -115,12 +112,12 @@ export class AirPurifier {
115
112
  }
116
113
 
117
114
  async CurrentAirPurifierStateGet(): Promise<number> {
118
- if (this.Active === 1) {
119
- this.CurrentAirPurifierState = this.hap.Characteristic.CurrentAirPurifierState.PURIFYING_AIR;
115
+ if (this.AirPurifier.Active === 1) {
116
+ this.AirPurifier.CurrentAirPurifierState = this.hap.Characteristic.CurrentAirPurifierState.PURIFYING_AIR;
120
117
  } else {
121
- this.CurrentAirPurifierState = this.hap.Characteristic.CurrentAirPurifierState.INACTIVE;
118
+ this.AirPurifier.CurrentAirPurifierState = this.hap.Characteristic.CurrentAirPurifierState.INACTIVE;
122
119
  }
123
- return this.CurrentAirPurifierState;
120
+ return this.AirPurifier.CurrentAirPurifierState;
124
121
  }
125
122
 
126
123
  /**
@@ -136,10 +133,10 @@ export class AirPurifier {
136
133
  */
137
134
  async pushAirPurifierOnChanges(): Promise<void> {
138
135
  this.debugLog(
139
- `${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierOnChanges Active: ${this.Active},` +
136
+ `${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierOnChanges Active: ${this.AirPurifier.Active},` +
140
137
  ` disablePushOn: ${this.disablePushOn}`,
141
138
  );
142
- if (this.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
139
+ if (this.AirPurifier.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
143
140
  const commandType: string = await this.commandType();
144
141
  const command: string = await this.commandOn();
145
142
  const bodyChange = JSON.stringify({
@@ -153,10 +150,10 @@ export class AirPurifier {
153
150
 
154
151
  async pushAirPurifierOffChanges(): Promise<void> {
155
152
  this.debugLog(
156
- `${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierOffChanges Active: ${this.Active},` +
153
+ `${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierOffChanges Active: ${this.AirPurifier.Active},` +
157
154
  ` disablePushOff: ${this.disablePushOff}`,
158
155
  );
159
- if (this.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOn) {
156
+ if (this.AirPurifier.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOn) {
160
157
  const commandType: string = await this.commandType();
161
158
  const command: string = await this.commandOff();
162
159
  const bodyChange = JSON.stringify({
@@ -170,7 +167,7 @@ export class AirPurifier {
170
167
 
171
168
  async pushAirPurifierStatusChanges(): Promise<void> {
172
169
  this.debugLog(
173
- `${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierStatusChanges Active: ${this.Active},` +
170
+ `${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierStatusChanges Active: ${this.AirPurifier.Active},` +
174
171
  ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`,
175
172
  );
176
173
  if (!this.Busy) {
@@ -185,21 +182,21 @@ export class AirPurifier {
185
182
 
186
183
  async pushAirPurifierDetailsChanges(): Promise<void> {
187
184
  this.debugLog(
188
- `${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierDetailsChanges Active: ${this.Active},` +
185
+ `${this.device.remoteType}: ${this.accessory.displayName} pushAirPurifierDetailsChanges Active: ${this.AirPurifier.Active},` +
189
186
  ` disablePushOff: ${this.disablePushOff}, disablePushOn: ${this.disablePushOn}`,
190
187
  );
191
- this.CurrentAPTemp = this.CurrentTemperature || 24;
188
+ this.CurrentAPTemp = this.TemperatureSensor!.CurrentTemperature || 24;
192
189
  this.CurrentAPMode = this.CurrentMode || 1;
193
190
  this.CurrentAPFanSpeed = this.CurrentFanSpeed || 1;
194
- this.APActive = this.Active === 1 ? 'on' : 'off';
191
+ this.APActive = this.AirPurifier.Active === 1 ? 'on' : 'off';
195
192
  const parameter = `${this.CurrentAPTemp},${this.CurrentAPMode},${this.CurrentAPFanSpeed},${this.APActive}`;
196
193
  const bodyChange = JSON.stringify({
197
194
  command: 'setAll',
198
195
  parameter: `${parameter}`,
199
196
  commandType: 'command',
200
197
  });
201
- if (this.Active === 1) {
202
- if ((Number(this.CurrentTemperature) || 24) < (this.LastTemperature || 30)) {
198
+ if (this.AirPurifier.Active === 1) {
199
+ if ((Number(this.TemperatureSensor!.CurrentTemperature) || 24) < (this.LastTemperature || 30)) {
203
200
  this.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.COOLING;
204
201
  } else {
205
202
  this.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.HEATING;
@@ -225,8 +222,10 @@ export class AirPurifier {
225
222
  this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
226
223
  this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
227
224
  if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
228
- this.debugErrorLog(`${this.device.remoteType}: ${this.accessory.displayName} `
225
+ this.debugSuccessLog(`${this.device.remoteType}: ${this.accessory.displayName} `
229
226
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
227
+ this.successLog(`${this.device.remoteType}: ${this.accessory.displayName}`
228
+ + ` request to SwitchBot API, body: ${JSON.stringify(bodyChange)} sent successfully`);
230
229
  this.updateHomeKitCharacteristics();
231
230
  } else {
232
231
  this.statusCode(statusCode);
@@ -249,280 +248,49 @@ export class AirPurifier {
249
248
 
250
249
  async updateHomeKitCharacteristics(): Promise<void> {
251
250
  // Active
252
- if (this.Active === undefined) {
253
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
251
+ if (this.AirPurifier.Active === undefined) {
252
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.AirPurifier.Active}`);
254
253
  } else {
255
- this.accessory.context.Active = this.Active;
256
- this.airPurifierService?.updateCharacteristic(this.hap.Characteristic.Active, this.Active);
257
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
254
+ this.accessory.context.Active = this.AirPurifier.Active;
255
+ this.AirPurifier.Service.updateCharacteristic(this.hap.Characteristic.Active, this.AirPurifier.Active);
256
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.AirPurifier.Active}`);
258
257
  }
259
258
  // CurrentAirPurifierState
260
- if (this.CurrentAirPurifierState === undefined) {
261
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentAirPurifierState: ${this.CurrentAirPurifierState}`);
259
+ if (this.AirPurifier.CurrentAirPurifierState === undefined) {
260
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentAirPurifierState: ${this.AirPurifier.CurrentAirPurifierState}`);
262
261
  } else {
263
- this.accessory.context.CurrentAirPurifierState = this.CurrentAirPurifierState;
264
- this.airPurifierService?.updateCharacteristic(this.hap.Characteristic.CurrentAirPurifierState, this.CurrentAirPurifierState);
265
- this.debugLog(
266
- `${this.device.remoteType}: ${this.accessory.displayName}` + ` updateCharacteristic CurrentAirPurifierState: ${this.CurrentAirPurifierState}`,
267
- );
262
+ this.accessory.context.CurrentAirPurifierState = this.AirPurifier.CurrentAirPurifierState;
263
+ this.AirPurifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentAirPurifierState, this.AirPurifier.CurrentAirPurifierState);
264
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
265
+ + ` CurrentAirPurifierState: ${this.AirPurifier.CurrentAirPurifierState}`);
268
266
  }
269
267
  // CurrentHeaterCoolerState
270
268
  if (this.CurrentHeaterCoolerState === undefined) {
271
269
  this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`);
272
270
  } else {
273
271
  this.accessory.context.CurrentHeaterCoolerState = this.CurrentHeaterCoolerState;
274
- this.airPurifierService?.updateCharacteristic(this.hap.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
272
+ this.AirPurifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHeaterCoolerState, this.CurrentHeaterCoolerState);
275
273
  this.debugLog(
276
274
  `${this.device.remoteType}: ${this.accessory.displayName}` +
277
275
  ` updateCharacteristic CurrentHeaterCoolerState: ${this.CurrentHeaterCoolerState}`,
278
276
  );
279
277
  }
280
- }
281
-
282
- async disablePushOnChanges(device: irdevice & irDevicesConfig): Promise<void> {
283
- if (device.disablePushOn === undefined) {
284
- this.disablePushOn = false;
285
- } else {
286
- this.disablePushOn = device.disablePushOn;
287
- }
288
- }
289
-
290
- async disablePushOffChanges(device: irdevice & irDevicesConfig): Promise<void> {
291
- if (device.disablePushOff === undefined) {
292
- this.disablePushOff = false;
278
+ // CurrentTemperature
279
+ if (this.TemperatureSensor.CurrentTemperature === undefined) {
280
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
293
281
  } else {
294
- this.disablePushOff = device.disablePushOff;
295
- }
296
- }
297
-
298
- async commandType(): Promise<string> {
299
- let commandType: string;
300
- if (this.device.customize) {
301
- commandType = 'customize';
302
- } else {
303
- commandType = 'command';
304
- }
305
- return commandType;
306
- }
307
-
308
- async commandOn(): Promise<string> {
309
- let command: string;
310
- if (this.device.customize && this.device.customOn) {
311
- command = this.device.customOn;
312
- } else {
313
- command = 'turnOn';
314
- }
315
- return command;
316
- }
317
-
318
- async commandOff(): Promise<string> {
319
- let command: string;
320
- if (this.device.customize && this.device.customOff) {
321
- command = this.device.customOff;
322
- } else {
323
- command = 'turnOff';
324
- }
325
- return command;
326
- }
327
-
328
- async statusCode(statusCode: number): Promise<void> {
329
- switch (statusCode) {
330
- case 151:
331
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
332
- break;
333
- case 152:
334
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
335
- break;
336
- case 160:
337
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
338
- break;
339
- case 161:
340
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
341
- break;
342
- case 171:
343
- this.errorLog(
344
- `${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
345
- `Hub: ${this.device.hubDeviceId}`,
346
- );
347
- break;
348
- case 190:
349
- this.errorLog(
350
- `${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
351
- ` Or command format is invalid, statusCode: ${statusCode}`,
352
- );
353
- break;
354
- case 100:
355
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
356
- break;
357
- case 200:
358
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
359
- break;
360
- case 400:
361
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
362
- + `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
363
- break;
364
- case 401:
365
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
366
- + `but the request has not been authenticated, statusCode: ${statusCode}`);
367
- break;
368
- case 403:
369
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
370
- + `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
371
- break;
372
- case 404:
373
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
374
- + `statusCode: ${statusCode}`);
375
- break;
376
- case 406:
377
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
378
- + `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
379
- break;
380
- case 415:
381
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
382
- + `header that is not supported by the server, statusCode: ${statusCode}`);
383
- break;
384
- case 422:
385
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, but `
386
- + `the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
387
- break;
388
- case 429:
389
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
390
- + `requests allowed for a given time window, statusCode: ${statusCode}`);
391
- break;
392
- case 500:
393
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
394
- + `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
395
- break;
396
- default:
397
- this.infoLog(
398
- `${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode: ` +
399
- `${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`,
400
- );
282
+ this.accessory.context.CurrentTemperature = this.TemperatureSensor.CurrentTemperature;
283
+ this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.TemperatureSensor.CurrentTemperature);
284
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic`
285
+ + ` CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
401
286
  }
402
287
  }
403
288
 
404
289
  async apiError(e: any): Promise<void> {
405
- this.airPurifierService.updateCharacteristic(this.hap.Characteristic.CurrentHeaterCoolerState, e);
406
- this.airPurifierService.updateCharacteristic(this.hap.Characteristic.CurrentAirPurifierState, e);
407
- this.airPurifierService.updateCharacteristic(this.hap.Characteristic.TargetAirPurifierState, e);
408
- this.airPurifierService.updateCharacteristic(this.hap.Characteristic.Active, e);
409
- }
410
-
411
- private deviceContext() {
412
- if (this.Active === undefined) {
413
- this.Active = this.hap.Characteristic.Active.INACTIVE;
414
- } else {
415
- this.Active = this.accessory.context.Active;
416
- }
417
- if (this.CurrentTemperature === undefined) {
418
- this.CurrentTemperature = 24;
419
- } else {
420
- this.CurrentTemperature = this.accessory.context.CurrentTemperature;
421
- }
422
- if (this.FirmwareRevision === undefined) {
423
- this.FirmwareRevision = this.platform.version;
424
- this.accessory.context.FirmwareRevision = this.FirmwareRevision;
425
- }
426
- }
427
-
428
- async deviceConfig(device: irdevice & irDevicesConfig): Promise<void> {
429
- let config = {};
430
- if (device.irpur) {
431
- config = device.irpur;
432
- }
433
- if (device.logging !== undefined) {
434
- config['logging'] = device.logging;
435
- }
436
- if (device.connectionType !== undefined) {
437
- config['connectionType'] = device.connectionType;
438
- }
439
- if (device.external !== undefined) {
440
- config['external'] = device.external;
441
- }
442
- if (device.customOn !== undefined) {
443
- config['customOn'] = device.customOn;
444
- }
445
- if (device.customOff !== undefined) {
446
- config['customOff'] = device.customOff;
447
- }
448
- if (device.customize !== undefined) {
449
- config['customize'] = device.customize;
450
- }
451
- if (device.disablePushOn !== undefined) {
452
- config['disablePushOn'] = device.disablePushOn;
453
- }
454
- if (device.disablePushOff !== undefined) {
455
- config['disablePushOff'] = device.disablePushOff;
456
- }
457
- if (Object.entries(config).length !== 0) {
458
- this.debugWarnLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
459
- }
460
- }
461
-
462
- async deviceLogs(device: irdevice & irDevicesConfig): Promise<void> {
463
- if (this.platform.debugMode) {
464
- this.deviceLogging = this.accessory.context.logging = 'debugMode';
465
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
466
- } else if (device.logging) {
467
- this.deviceLogging = this.accessory.context.logging = device.logging;
468
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
469
- } else if (this.platform.config.options?.logging) {
470
- this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
471
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
472
- } else {
473
- this.deviceLogging = this.accessory.context.logging = 'standard';
474
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
475
- }
476
- }
477
-
478
- /**
479
- * Logging for Device
480
- */
481
- infoLog(...log: any[]): void {
482
- if (this.enablingDeviceLogging()) {
483
- this.platform.log.info(String(...log));
484
- }
485
- }
486
-
487
- warnLog(...log: any[]): void {
488
- if (this.enablingDeviceLogging()) {
489
- this.platform.log.warn(String(...log));
490
- }
491
- }
492
-
493
- debugWarnLog(...log: any[]): void {
494
- if (this.enablingDeviceLogging()) {
495
- if (this.deviceLogging?.includes('debug')) {
496
- this.platform.log.warn('[DEBUG]', String(...log));
497
- }
498
- }
499
- }
500
-
501
- errorLog(...log: any[]): void {
502
- if (this.enablingDeviceLogging()) {
503
- this.platform.log.error(String(...log));
504
- }
505
- }
506
-
507
- debugErrorLog(...log: any[]): void {
508
- if (this.enablingDeviceLogging()) {
509
- if (this.deviceLogging?.includes('debug')) {
510
- this.platform.log.error('[DEBUG]', String(...log));
511
- }
512
- }
513
- }
514
-
515
- debugLog(...log: any[]): void {
516
- if (this.enablingDeviceLogging()) {
517
- if (this.deviceLogging === 'debug') {
518
- this.platform.log.info('[DEBUG]', String(...log));
519
- } else {
520
- this.platform.log.debug(String(...log));
521
- }
522
- }
523
- }
524
-
525
- enablingDeviceLogging(): boolean {
526
- return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
290
+ this.AirPurifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentHeaterCoolerState, e);
291
+ this.AirPurifier.Service.updateCharacteristic(this.hap.Characteristic.CurrentAirPurifierState, e);
292
+ this.AirPurifier.Service.updateCharacteristic(this.hap.Characteristic.TargetAirPurifierState, e);
293
+ this.AirPurifier.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
294
+ this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
527
295
  }
528
296
  }