@switchbot/homebridge-switchbot 1.8.3-beta.0 → 1.10.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/.eslintrc +14 -45
  2. package/.github/ISSUE_TEMPLATE/bug-report.yml +3 -3
  3. package/.github/ISSUE_TEMPLATE/feature-request.yml +2 -2
  4. package/.github/ISSUE_TEMPLATE/support-request.yml +3 -3
  5. package/.github/labeler.yml +1 -1
  6. package/.github/workflows/codeql-analysis.yml +29 -29
  7. package/.github/workflows/nodejs-beta.yml +1 -1
  8. package/.github/workflows/prerelease-beta.js +1 -1
  9. package/.github/workflows/stale.yml +1 -1
  10. package/.prettierrc +9 -0
  11. package/.vscode/extensions.json +2 -4
  12. package/.vscode/settings.json +14 -2
  13. package/CHANGELOG.md +16 -0
  14. package/README.md +100 -99
  15. package/SECURITY.md +2 -2
  16. package/config.schema.json +17 -0
  17. package/dist/devices/bots.d.ts +35 -32
  18. package/dist/devices/bots.d.ts.map +1 -1
  19. package/dist/devices/bots.js +168 -210
  20. package/dist/devices/bots.js.map +1 -1
  21. package/dist/devices/colorbulb.d.ts +35 -35
  22. package/dist/devices/colorbulb.d.ts.map +1 -1
  23. package/dist/devices/colorbulb.js +83 -108
  24. package/dist/devices/colorbulb.js.map +1 -1
  25. package/dist/devices/contact.d.ts +27 -25
  26. package/dist/devices/contact.d.ts.map +1 -1
  27. package/dist/devices/contact.js +110 -131
  28. package/dist/devices/contact.js.map +1 -1
  29. package/dist/devices/curtains.d.ts +29 -27
  30. package/dist/devices/curtains.d.ts.map +1 -1
  31. package/dist/devices/curtains.js +147 -182
  32. package/dist/devices/curtains.js.map +1 -1
  33. package/dist/devices/humidifiers.d.ts +31 -31
  34. package/dist/devices/humidifiers.d.ts.map +1 -1
  35. package/dist/devices/humidifiers.js +154 -181
  36. package/dist/devices/humidifiers.js.map +1 -1
  37. package/dist/devices/meters.d.ts +29 -28
  38. package/dist/devices/meters.d.ts.map +1 -1
  39. package/dist/devices/meters.js +98 -120
  40. package/dist/devices/meters.js.map +1 -1
  41. package/dist/devices/motion.d.ts +24 -23
  42. package/dist/devices/motion.d.ts.map +1 -1
  43. package/dist/devices/motion.js +97 -113
  44. package/dist/devices/motion.js.map +1 -1
  45. package/dist/devices/plugs.d.ts +16 -16
  46. package/dist/devices/plugs.d.ts.map +1 -1
  47. package/dist/devices/plugs.js +48 -71
  48. package/dist/devices/plugs.js.map +1 -1
  49. package/dist/index.d.ts +2 -2
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +3 -22
  52. package/dist/index.js.map +1 -1
  53. package/dist/irdevices/airconditioners.d.ts +7 -4
  54. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  55. package/dist/irdevices/airconditioners.js +72 -93
  56. package/dist/irdevices/airconditioners.js.map +1 -1
  57. package/dist/irdevices/airpurifiers.d.ts +3 -3
  58. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  59. package/dist/irdevices/airpurifiers.js +32 -51
  60. package/dist/irdevices/airpurifiers.js.map +1 -1
  61. package/dist/irdevices/cameras.d.ts +3 -3
  62. package/dist/irdevices/cameras.d.ts.map +1 -1
  63. package/dist/irdevices/cameras.js +19 -26
  64. package/dist/irdevices/cameras.js.map +1 -1
  65. package/dist/irdevices/fans.d.ts +3 -3
  66. package/dist/irdevices/fans.d.ts.map +1 -1
  67. package/dist/irdevices/fans.js +35 -44
  68. package/dist/irdevices/fans.js.map +1 -1
  69. package/dist/irdevices/lights.d.ts +3 -3
  70. package/dist/irdevices/lights.d.ts.map +1 -1
  71. package/dist/irdevices/lights.js +25 -32
  72. package/dist/irdevices/lights.js.map +1 -1
  73. package/dist/irdevices/others.d.ts +3 -3
  74. package/dist/irdevices/others.d.ts.map +1 -1
  75. package/dist/irdevices/others.js +21 -29
  76. package/dist/irdevices/others.js.map +1 -1
  77. package/dist/irdevices/tvs.d.ts +3 -3
  78. package/dist/irdevices/tvs.d.ts.map +1 -1
  79. package/dist/irdevices/tvs.js +66 -89
  80. package/dist/irdevices/tvs.js.map +1 -1
  81. package/dist/irdevices/vacuumcleaners.d.ts +3 -3
  82. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  83. package/dist/irdevices/vacuumcleaners.js +18 -24
  84. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  85. package/dist/irdevices/waterheaters.d.ts +3 -3
  86. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  87. package/dist/irdevices/waterheaters.js +19 -26
  88. package/dist/irdevices/waterheaters.js.map +1 -1
  89. package/dist/platform.d.ts +10 -10
  90. package/dist/platform.d.ts.map +1 -1
  91. package/dist/platform.js +163 -233
  92. package/dist/platform.js.map +1 -1
  93. package/dist/settings.d.ts +3 -1
  94. package/dist/settings.d.ts.map +1 -1
  95. package/dist/settings.js +4 -4
  96. package/dist/settings.js.map +1 -1
  97. package/homebridge-ui/public/index.html +231 -245
  98. package/homebridge-ui/server.js +2 -4
  99. package/nodemon.json +2 -4
  100. package/package.json +17 -12
  101. package/src/devices/bots.ts +411 -854
  102. package/src/devices/colorbulb.ts +187 -408
  103. package/src/devices/contact.ts +210 -376
  104. package/src/devices/curtains.ts +288 -563
  105. package/src/devices/humidifiers.ts +291 -537
  106. package/src/devices/meters.ts +189 -331
  107. package/src/devices/motion.ts +188 -322
  108. package/src/devices/plugs.ts +88 -160
  109. package/src/index.ts +5 -5
  110. package/src/irdevices/airconditioners.ts +139 -318
  111. package/src/irdevices/airpurifiers.ts +71 -170
  112. package/src/irdevices/cameras.ts +44 -103
  113. package/src/irdevices/fans.ts +70 -165
  114. package/src/irdevices/lights.ts +49 -104
  115. package/src/irdevices/others.ts +55 -131
  116. package/src/irdevices/tvs.ts +114 -247
  117. package/src/irdevices/vacuumcleaners.ts +44 -104
  118. package/src/irdevices/waterheaters.ts +49 -121
  119. package/src/platform.ts +341 -753
  120. package/src/settings.ts +8 -11
  121. package/tsconfig.json +5 -14
  122. package/.github/PULL_REQUEST_TEMPLATE/pull_requests.md +0 -27
@@ -1,7 +1,7 @@
1
- import { AxiosResponse } from "axios";
2
- import { SwitchBotPlatform } from "../platform";
3
- import { irDevicesConfig, DeviceURL, irdevice, payload } from "../settings";
4
- import { CharacteristicValue, PlatformAccessory, Service } from "homebridge";
1
+ import { AxiosResponse } from 'axios';
2
+ import { SwitchBotPlatform } from '../platform';
3
+ import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
4
+ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -19,11 +19,7 @@ export class Camera {
19
19
  // Config
20
20
  deviceLogging!: string;
21
21
 
22
- constructor(
23
- private readonly platform: SwitchBotPlatform,
24
- private accessory: PlatformAccessory,
25
- public device: irdevice & irDevicesConfig,
26
- ) {
22
+ constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: irdevice & irDevicesConfig) {
27
23
  // default placeholders
28
24
  this.logs(device);
29
25
  this.config(device);
@@ -36,18 +32,13 @@ export class Camera {
36
32
  // set accessory information
37
33
  accessory
38
34
  .getService(this.platform.Service.AccessoryInformation)!
39
- .setCharacteristic(this.platform.Characteristic.Manufacturer, "SwitchBot")
35
+ .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
40
36
  .setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
41
- .setCharacteristic(
42
- this.platform.Characteristic.SerialNumber,
43
- device.deviceId!,
44
- );
37
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
45
38
 
46
39
  // get the Television service if it exists, otherwise create a new Television service
47
40
  // you can create multiple services for each accessory
48
- (this.service =
49
- accessory.getService(this.platform.Service.Switch) ||
50
- accessory.addService(this.platform.Service.Switch)),
41
+ (this.service = accessory.getService(this.platform.Service.Switch) || accessory.addService(this.platform.Service.Switch)),
51
42
  `${accessory.displayName} Camera`;
52
43
 
53
44
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
@@ -56,15 +47,10 @@ export class Camera {
56
47
 
57
48
  // set the service name, this is what is displayed as the default name on the Home app
58
49
  // in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
59
- this.service.setCharacteristic(
60
- this.platform.Characteristic.Name,
61
- accessory.displayName,
62
- );
50
+ this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
63
51
 
64
52
  // handle on / off events using the On characteristic
65
- this.service
66
- .getCharacteristic(this.platform.Characteristic.On)
67
- .onSet(this.OnSet.bind(this));
53
+ this.service.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
68
54
  }
69
55
 
70
56
  private OnSet(value: CharacteristicValue) {
@@ -81,13 +67,8 @@ export class Camera {
81
67
  if (this.On === undefined) {
82
68
  this.debugLog(`Camera: ${this.accessory.displayName} On: ${this.On}`);
83
69
  } else {
84
- this.service?.updateCharacteristic(
85
- this.platform.Characteristic.On,
86
- this.On,
87
- );
88
- this.debugLog(
89
- `Camera: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`,
90
- );
70
+ this.service?.updateCharacteristic(this.platform.Characteristic.On, this.On);
71
+ this.debugLog(`Camera: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
91
72
  }
92
73
  }
93
74
 
@@ -104,9 +85,9 @@ export class Camera {
104
85
  async pushOnChanges() {
105
86
  if (this.On) {
106
87
  const payload = {
107
- commandType: "command",
108
- parameter: "default",
109
- command: "turnOn",
88
+ commandType: 'command',
89
+ parameter: 'default',
90
+ command: 'turnOn',
110
91
  } as payload;
111
92
  await this.pushChanges(payload);
112
93
  }
@@ -115,9 +96,9 @@ export class Camera {
115
96
  async pushOffChanges() {
116
97
  if (!this.On) {
117
98
  const payload = {
118
- commandType: "command",
119
- parameter: "default",
120
- command: "turnOff",
99
+ commandType: 'command',
100
+ parameter: 'default',
101
+ command: 'turnOff',
121
102
  } as payload;
122
103
  await this.pushChanges(payload);
123
104
  }
@@ -131,32 +112,21 @@ export class Camera {
131
112
  );
132
113
 
133
114
  // Make the API request
134
- const push = await this.platform.axios.post(
135
- `${DeviceURL}/${this.device.deviceId}/commands`,
136
- payload,
137
- );
138
- this.debugLog(
139
- `Camera: ${this.accessory.displayName} pushChanges: ${push.data}`,
140
- );
115
+ const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
116
+ this.debugLog(`Camera: ${this.accessory.displayName} pushChanges: ${push.data}`);
141
117
  this.statusCode(push);
142
118
  this.updateHomeKitCharacteristics();
143
119
  this.OnCached = this.On;
144
120
  this.accessory.context.On = this.OnCached;
145
121
  } catch (e: any) {
146
- this.errorLog(
147
- `Camera: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`,
148
- );
149
- if (this.deviceLogging === "debug") {
122
+ this.errorLog(`Camera: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
123
+ if (this.deviceLogging === 'debug') {
150
124
  this.errorLog(
151
- `Camera: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
152
- ` Error Message: ${JSON.stringify(e.message)}`,
125
+ `Camera: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
153
126
  );
154
127
  }
155
128
  if (this.platform.debugMode) {
156
- this.errorLog(
157
- `Camera: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
158
- ` Error: ${JSON.stringify(e)}`,
159
- );
129
+ this.errorLog(`Camera: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
160
130
  }
161
131
  this.apiError(e);
162
132
  }
@@ -165,47 +135,31 @@ export class Camera {
165
135
  private statusCode(push: AxiosResponse<{ statusCode: number }>) {
166
136
  switch (push.data.statusCode) {
167
137
  case 151:
168
- this.errorLog(
169
- `Camera: ${this.accessory.displayName} Command not supported by this device type.`,
170
- );
138
+ this.errorLog(`Camera: ${this.accessory.displayName} Command not supported by this device type.`);
171
139
  break;
172
140
  case 152:
173
- this.errorLog(
174
- `Camera: ${this.accessory.displayName} Device not found.`,
175
- );
141
+ this.errorLog(`Camera: ${this.accessory.displayName} Device not found.`);
176
142
  break;
177
143
  case 160:
178
- this.errorLog(
179
- `Camera: ${this.accessory.displayName} Command is not supported.`,
180
- );
144
+ this.errorLog(`Camera: ${this.accessory.displayName} Command is not supported.`);
181
145
  break;
182
146
  case 161:
183
- this.errorLog(
184
- `Camera: ${this.accessory.displayName} Device is offline.`,
185
- );
147
+ this.errorLog(`Camera: ${this.accessory.displayName} Device is offline.`);
186
148
  break;
187
149
  case 171:
188
- this.errorLog(
189
- `Camera: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`,
190
- );
150
+ this.errorLog(`Camera: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
191
151
  break;
192
152
  case 190:
193
153
  this.errorLog(
194
154
  `Camera: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
195
- ` with server, Or command: ${JSON.stringify(
196
- push.data,
197
- )} format is invalid`,
155
+ ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`,
198
156
  );
199
157
  break;
200
158
  case 100:
201
- this.debugLog(
202
- `Camera: ${this.accessory.displayName} Command successfully sent.`,
203
- );
159
+ this.debugLog(`Camera: ${this.accessory.displayName} Command successfully sent.`);
204
160
  break;
205
161
  default:
206
- this.debugLog(
207
- `Camera: ${this.accessory.displayName} Unknown statusCode.`,
208
- );
162
+ this.debugLog(`Camera: ${this.accessory.displayName} Unknown statusCode.`);
209
163
  }
210
164
  }
211
165
 
@@ -220,39 +174,26 @@ export class Camera {
220
174
  config = device.ircam;
221
175
  }
222
176
  if (device.logging !== undefined) {
223
- config["logging"] = device.logging;
177
+ config['logging'] = device.logging;
224
178
  }
225
179
  if (Object.entries(config).length !== 0) {
226
- this.warnLog(
227
- `Camera: ${this.accessory.displayName} Config: ${JSON.stringify(
228
- config,
229
- )}`,
230
- );
180
+ this.warnLog(`Camera: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
231
181
  }
232
182
  }
233
183
 
234
184
  logs(device: irdevice & irDevicesConfig) {
235
185
  if (this.platform.debugMode) {
236
- this.deviceLogging = this.accessory.context.logging = "debugMode";
237
- this.debugLog(
238
- `Camera: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`,
239
- );
186
+ this.deviceLogging = this.accessory.context.logging = 'debugMode';
187
+ this.debugLog(`Camera: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
240
188
  } else if (device.logging) {
241
189
  this.deviceLogging = this.accessory.context.logging = device.logging;
242
- this.debugLog(
243
- `Camera: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`,
244
- );
190
+ this.debugLog(`Camera: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
245
191
  } else if (this.platform.config.options?.logging) {
246
- this.deviceLogging = this.accessory.context.logging =
247
- this.platform.config.options?.logging;
248
- this.debugLog(
249
- `Camera: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`,
250
- );
192
+ this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
193
+ this.debugLog(`Camera: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
251
194
  } else {
252
- this.deviceLogging = this.accessory.context.logging = "standard";
253
- this.debugLog(
254
- `Camera: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`,
255
- );
195
+ this.deviceLogging = this.accessory.context.logging = 'standard';
196
+ this.debugLog(`Camera: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
256
197
  }
257
198
  }
258
199
 
@@ -279,8 +220,8 @@ export class Camera {
279
220
 
280
221
  debugLog(...log: any[]) {
281
222
  if (this.enablingDeviceLogging()) {
282
- if (this.deviceLogging === "debug") {
283
- this.platform.log.info("[DEBUG]", String(...log));
223
+ if (this.deviceLogging === 'debug') {
224
+ this.platform.log.info('[DEBUG]', String(...log));
284
225
  } else {
285
226
  this.platform.log.debug(String(...log));
286
227
  }
@@ -288,6 +229,6 @@ export class Camera {
288
229
  }
289
230
 
290
231
  enablingDeviceLogging(): boolean {
291
- return this.deviceLogging.includes("debug") || this.deviceLogging === "standard";
232
+ return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
292
233
  }
293
234
  }
@@ -1,13 +1,7 @@
1
- import { AxiosResponse } from "axios";
2
- import { SwitchBotPlatform } from "../platform";
3
- import { CharacteristicValue, PlatformAccessory, Service } from "homebridge";
4
- import {
5
- DeviceURL,
6
- irdevice,
7
- deviceStatusResponse,
8
- irDevicesConfig,
9
- payload,
10
- } from "../settings";
1
+ import { AxiosResponse } from 'axios';
2
+ import { SwitchBotPlatform } from '../platform';
3
+ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
4
+ import { DeviceURL, irdevice, deviceStatusResponse, irDevicesConfig, payload } from '../settings';
11
5
 
12
6
  /**
13
7
  * Platform Accessory
@@ -35,11 +29,7 @@ export class Fan {
35
29
  maxValue?: number;
36
30
  deviceLogging!: string;
37
31
 
38
- constructor(
39
- private readonly platform: SwitchBotPlatform,
40
- private accessory: PlatformAccessory,
41
- public device: irdevice & irDevicesConfig,
42
- ) {
32
+ constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: irdevice & irDevicesConfig) {
43
33
  // default placeholders
44
34
  this.logs(device);
45
35
  this.config(device);
@@ -52,18 +42,13 @@ export class Fan {
52
42
  // set accessory information
53
43
  accessory
54
44
  .getService(this.platform.Service.AccessoryInformation)!
55
- .setCharacteristic(this.platform.Characteristic.Manufacturer, "SwitchBot")
45
+ .setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
56
46
  .setCharacteristic(this.platform.Characteristic.Model, device.remoteType)
57
- .setCharacteristic(
58
- this.platform.Characteristic.SerialNumber,
59
- device.deviceId!,
60
- );
47
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
61
48
 
62
49
  // get the Television service if it exists, otherwise create a new Television service
63
50
  // you can create multiple services for each accessory
64
- (this.service =
65
- accessory.getService(this.platform.Service.Fanv2) ||
66
- accessory.addService(this.platform.Service.Fanv2)),
51
+ (this.service = accessory.getService(this.platform.Service.Fanv2) || accessory.addService(this.platform.Service.Fanv2)),
67
52
  `${accessory.displayName} Fan`;
68
53
 
69
54
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
@@ -72,15 +57,10 @@ export class Fan {
72
57
 
73
58
  // set the service name, this is what is displayed as the default name on the Home app
74
59
  // in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
75
- this.service.setCharacteristic(
76
- this.platform.Characteristic.Name,
77
- accessory.displayName,
78
- );
60
+ this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
79
61
 
80
62
  // handle on / off events using the Active characteristic
81
- this.service
82
- .getCharacteristic(this.platform.Characteristic.Active)
83
- .onSet(this.ActiveSet.bind(this));
63
+ this.service.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
84
64
 
85
65
  if (device.irfan?.rotation_speed) {
86
66
  if (device.irfan?.set_minStep) {
@@ -107,46 +87,30 @@ export class Fan {
107
87
  maxValue: this.maxValue,
108
88
  })
109
89
  .onSet(this.RotationSpeedSet.bind(this));
110
- } else if (
111
- this.service.testCharacteristic(
112
- this.platform.Characteristic.RotationSpeed,
113
- ) &&
114
- !device.irfan?.swing_mode
115
- ) {
116
- const characteristic = this.service.getCharacteristic(
117
- this.platform.Characteristic.RotationSpeed,
118
- );
90
+ } else if (this.service.testCharacteristic(this.platform.Characteristic.RotationSpeed) && !device.irfan?.swing_mode) {
91
+ const characteristic = this.service.getCharacteristic(this.platform.Characteristic.RotationSpeed);
119
92
  this.service.removeCharacteristic(characteristic);
120
- this.debugLog(
121
- `Fan: ${this.accessory.displayName} Rotation Speed Characteristic was removed.`,
122
- );
93
+ this.debugLog(`Fan: ${this.accessory.displayName} Rotation Speed Characteristic was removed.`);
123
94
  } else {
124
95
  // eslint-disable-next-line max-len
125
96
  this.debugLog(
126
- `Fan: ${this.accessory.displayName} Rotation Speed Characteristic was not removed or not added. To Remove Chracteristic, Clear Cache on this Accessory.`,
97
+ `Fan: ${this.accessory.displayName} RotationSpeed Characteristic was not removed/added, ` +
98
+ `Clear Cache on ${this.accessory.displayName} to remove Chracteristic`,
127
99
  );
128
100
  }
129
101
 
130
102
  if (device.irfan?.swing_mode) {
131
103
  // handle Osolcation events using the SwingMode characteristic
132
- this.service
133
- .getCharacteristic(this.platform.Characteristic.SwingMode)
134
- .onSet(this.SwingModeSet.bind(this));
135
- } else if (
136
- this.service.testCharacteristic(this.platform.Characteristic.SwingMode) &&
137
- !device.irfan?.swing_mode
138
- ) {
139
- const characteristic = this.service.getCharacteristic(
140
- this.platform.Characteristic.SwingMode,
141
- );
104
+ this.service.getCharacteristic(this.platform.Characteristic.SwingMode).onSet(this.SwingModeSet.bind(this));
105
+ } else if (this.service.testCharacteristic(this.platform.Characteristic.SwingMode) && !device.irfan?.swing_mode) {
106
+ const characteristic = this.service.getCharacteristic(this.platform.Characteristic.SwingMode);
142
107
  this.service.removeCharacteristic(characteristic);
143
- this.debugLog(
144
- `Fan: ${this.accessory.displayName} Swing Mode Characteristic was removed.`,
145
- );
108
+ this.debugLog(`Fan: ${this.accessory.displayName} Swing Mode Characteristic was removed.`);
146
109
  } else {
147
110
  // eslint-disable-next-line max-len
148
111
  this.debugLog(
149
- `Fan: ${this.accessory.displayName} Swing Mode Characteristic was not removed or not added. To Remove Chracteristic, Clear Cache on this Accessory.`,
112
+ `Fan: ${this.accessory.displayName} Swing Mode Characteristic was not removed/added, ` +
113
+ `Clear Cache on ${this.accessory.displayName} To Remove Chracteristic`,
150
114
  );
151
115
  }
152
116
  }
@@ -167,43 +131,22 @@ export class Fan {
167
131
 
168
132
  private updateHomeKitCharacteristics() {
169
133
  if (this.Active === undefined) {
170
- this.debugLog(
171
- `Fan: ${this.accessory.displayName} Active: ${this.Active}`,
172
- );
134
+ this.debugLog(`Fan: ${this.accessory.displayName} Active: ${this.Active}`);
173
135
  } else {
174
- this.service?.updateCharacteristic(
175
- this.platform.Characteristic.Active,
176
- this.Active,
177
- );
178
- this.debugLog(
179
- `Fan: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`,
180
- );
136
+ this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
137
+ this.debugLog(`Fan: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
181
138
  }
182
139
  if (this.SwingMode === undefined) {
183
- this.debugLog(
184
- `Fan: ${this.accessory.displayName} SwingMode: ${this.SwingMode}`,
185
- );
140
+ this.debugLog(`Fan: ${this.accessory.displayName} SwingMode: ${this.SwingMode}`);
186
141
  } else {
187
- this.service?.updateCharacteristic(
188
- this.platform.Characteristic.SwingMode,
189
- this.SwingMode,
190
- );
191
- this.debugLog(
192
- `Fan: ${this.accessory.displayName} updateCharacteristic SwingMode: ${this.SwingMode}`,
193
- );
142
+ this.service?.updateCharacteristic(this.platform.Characteristic.SwingMode, this.SwingMode);
143
+ this.debugLog(`Fan: ${this.accessory.displayName} updateCharacteristic SwingMode: ${this.SwingMode}`);
194
144
  }
195
145
  if (this.RotationSpeed === undefined) {
196
- this.debugLog(
197
- `Fan: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`,
198
- );
146
+ this.debugLog(`Fan: ${this.accessory.displayName} RotationSpeed: ${this.RotationSpeed}`);
199
147
  } else {
200
- this.service?.updateCharacteristic(
201
- this.platform.Characteristic.RotationSpeed,
202
- this.RotationSpeed,
203
- );
204
- this.debugLog(
205
- `Fan: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`,
206
- );
148
+ this.service?.updateCharacteristic(this.platform.Characteristic.RotationSpeed, this.RotationSpeed);
149
+ this.debugLog(`Fan: ${this.accessory.displayName} updateCharacteristic RotationSpeed: ${this.RotationSpeed}`);
207
150
  }
208
151
  }
209
152
 
@@ -244,9 +187,9 @@ export class Fan {
244
187
  async pushFanOnChanges() {
245
188
  if (this.Active !== 1) {
246
189
  const payload = {
247
- commandType: "command",
248
- parameter: "default",
249
- command: "turnOn",
190
+ commandType: 'command',
191
+ parameter: 'default',
192
+ command: 'turnOn',
250
193
  } as payload;
251
194
  await this.pushTVChanges(payload);
252
195
  }
@@ -254,36 +197,36 @@ export class Fan {
254
197
 
255
198
  async pushFanOffChanges() {
256
199
  const payload = {
257
- commandType: "command",
258
- parameter: "default",
259
- command: "turnOff",
200
+ commandType: 'command',
201
+ parameter: 'default',
202
+ command: 'turnOff',
260
203
  } as payload;
261
204
  await this.pushTVChanges(payload);
262
205
  }
263
206
 
264
207
  async pushFanSpeedUpChanges() {
265
208
  const payload = {
266
- commandType: "command",
267
- parameter: "default",
268
- command: "highSpeed",
209
+ commandType: 'command',
210
+ parameter: 'default',
211
+ command: 'highSpeed',
269
212
  } as payload;
270
213
  await this.pushTVChanges(payload);
271
214
  }
272
215
 
273
216
  async pushFanSpeedDownChanges() {
274
217
  const payload = {
275
- commandType: "command",
276
- parameter: "default",
277
- command: "lowSpeed",
218
+ commandType: 'command',
219
+ parameter: 'default',
220
+ command: 'lowSpeed',
278
221
  } as payload;
279
222
  await this.pushTVChanges(payload);
280
223
  }
281
224
 
282
225
  async pushFanSwingChanges() {
283
226
  const payload = {
284
- commandType: "command",
285
- parameter: "default",
286
- command: "swing",
227
+ commandType: 'command',
228
+ parameter: 'default',
229
+ command: 'swing',
287
230
  } as payload;
288
231
  await this.pushTVChanges(payload);
289
232
  }
@@ -296,30 +239,19 @@ export class Fan {
296
239
  );
297
240
 
298
241
  // Make the API request
299
- const push = await this.platform.axios.post(
300
- `${DeviceURL}/${this.device.deviceId}/commands`,
301
- payload,
302
- );
303
- this.debugLog(
304
- `Fan: ${this.accessory.displayName} pushTVChanges: ${push.data}`,
305
- );
242
+ const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
243
+ this.debugLog(`Fan: ${this.accessory.displayName} pushTVChanges: ${push.data}`);
306
244
  this.statusCode(push);
307
245
  this.updateHomeKitCharacteristics();
308
246
  } catch (e: any) {
309
- this.errorLog(
310
- `Fan: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`,
311
- );
312
- if (this.deviceLogging === "debug") {
247
+ this.errorLog(`Fan: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
248
+ if (this.deviceLogging === 'debug') {
313
249
  this.errorLog(
314
- `Fan: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
315
- ` Error Message: ${JSON.stringify(e.message)}`,
250
+ `Fan: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
316
251
  );
317
252
  }
318
253
  if (this.platform.debugMode) {
319
- this.errorLog(
320
- `Fan: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
321
- ` Error: ${JSON.stringify(e)}`,
322
- );
254
+ this.errorLog(`Fan: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
323
255
  }
324
256
  this.apiError(e);
325
257
  }
@@ -328,38 +260,28 @@ export class Fan {
328
260
  private statusCode(push: AxiosResponse<{ statusCode: number }>) {
329
261
  switch (push.data.statusCode) {
330
262
  case 151:
331
- this.errorLog(
332
- `Fan: ${this.accessory.displayName} Command not supported by this device type.`,
333
- );
263
+ this.errorLog(`Fan: ${this.accessory.displayName} Command not supported by this device type.`);
334
264
  break;
335
265
  case 152:
336
266
  this.errorLog(`Fan: ${this.accessory.displayName} Device not found.`);
337
267
  break;
338
268
  case 160:
339
- this.errorLog(
340
- `Fan: ${this.accessory.displayName} Command is not supported.`,
341
- );
269
+ this.errorLog(`Fan: ${this.accessory.displayName} Command is not supported.`);
342
270
  break;
343
271
  case 161:
344
272
  this.errorLog(`Fan: ${this.accessory.displayName} Device is offline.`);
345
273
  break;
346
274
  case 171:
347
- this.errorLog(
348
- `Fan: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`,
349
- );
275
+ this.errorLog(`Fan: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
350
276
  break;
351
277
  case 190:
352
278
  this.errorLog(
353
279
  `Fan: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
354
- ` with server, Or command: ${JSON.stringify(
355
- push.data,
356
- )} format is invalid`,
280
+ ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`,
357
281
  );
358
282
  break;
359
283
  case 100:
360
- this.debugLog(
361
- `Fan: ${this.accessory.displayName} Command successfully sent.`,
362
- );
284
+ this.debugLog(`Fan: ${this.accessory.displayName} Command successfully sent.`);
363
285
  break;
364
286
  default:
365
287
  this.debugLog(`Fan: ${this.accessory.displayName} Unknown statusCode.`);
@@ -368,14 +290,8 @@ export class Fan {
368
290
 
369
291
  public apiError(e: any) {
370
292
  this.service.updateCharacteristic(this.platform.Characteristic.Active, e);
371
- this.service.updateCharacteristic(
372
- this.platform.Characteristic.RotationSpeed,
373
- e,
374
- );
375
- this.service.updateCharacteristic(
376
- this.platform.Characteristic.SwingMode,
377
- e,
378
- );
293
+ this.service.updateCharacteristic(this.platform.Characteristic.RotationSpeed, e);
294
+ this.service.updateCharacteristic(this.platform.Characteristic.SwingMode, e);
379
295
  //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
380
296
  }
381
297
 
@@ -385,37 +301,26 @@ export class Fan {
385
301
  config = device.irfan;
386
302
  }
387
303
  if (device.logging !== undefined) {
388
- config["logging"] = device.logging;
304
+ config['logging'] = device.logging;
389
305
  }
390
306
  if (Object.entries(config).length !== 0) {
391
- this.warnLog(
392
- `Fan: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`,
393
- );
307
+ this.warnLog(`Fan: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
394
308
  }
395
309
  }
396
310
 
397
311
  logs(device: irdevice & irDevicesConfig) {
398
312
  if (this.platform.debugMode) {
399
- this.deviceLogging = this.accessory.context.logging = "debugMode";
400
- this.debugLog(
401
- `Fan: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`,
402
- );
313
+ this.deviceLogging = this.accessory.context.logging = 'debugMode';
314
+ this.debugLog(`Fan: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
403
315
  } else if (device.logging) {
404
316
  this.deviceLogging = this.accessory.context.logging = device.logging;
405
- this.debugLog(
406
- `Fan: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`,
407
- );
317
+ this.debugLog(`Fan: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
408
318
  } else if (this.platform.config.options?.logging) {
409
- this.deviceLogging = this.accessory.context.logging =
410
- this.platform.config.options?.logging;
411
- this.debugLog(
412
- `Fan: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`,
413
- );
319
+ this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
320
+ this.debugLog(`Fan: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
414
321
  } else {
415
- this.deviceLogging = this.accessory.context.logging = "standard";
416
- this.debugLog(
417
- `Fan: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`,
418
- );
322
+ this.deviceLogging = this.accessory.context.logging = 'standard';
323
+ this.debugLog(`Fan: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
419
324
  }
420
325
  }
421
326
 
@@ -442,8 +347,8 @@ export class Fan {
442
347
 
443
348
  debugLog(...log: any[]) {
444
349
  if (this.enablingDeviceLogging()) {
445
- if (this.deviceLogging === "debug") {
446
- this.platform.log.info("[DEBUG]", String(...log));
350
+ if (this.deviceLogging === 'debug') {
351
+ this.platform.log.info('[DEBUG]', String(...log));
447
352
  } else {
448
353
  this.platform.log.debug(String(...log));
449
354
  }
@@ -451,6 +356,6 @@ export class Fan {
451
356
  }
452
357
 
453
358
  enablingDeviceLogging(): boolean {
454
- return this.deviceLogging.includes("debug") || this.deviceLogging === "standard";
359
+ return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
455
360
  }
456
361
  }