@switchbot/homebridge-switchbot 1.3.1-beta.9 → 1.4.1-beta.2

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 (103) hide show
  1. package/CHANGELOG.md +18 -2
  2. package/config.schema.json +82 -32
  3. package/dist/devices/bots.d.ts +15 -3
  4. package/dist/devices/bots.d.ts.map +1 -1
  5. package/dist/devices/bots.js +227 -165
  6. package/dist/devices/bots.js.map +1 -1
  7. package/dist/devices/colorbulb.d.ts +14 -3
  8. package/dist/devices/colorbulb.d.ts.map +1 -1
  9. package/dist/devices/colorbulb.js +163 -105
  10. package/dist/devices/colorbulb.js.map +1 -1
  11. package/dist/devices/contact.d.ts +13 -3
  12. package/dist/devices/contact.d.ts.map +1 -1
  13. package/dist/devices/contact.js +102 -63
  14. package/dist/devices/contact.js.map +1 -1
  15. package/dist/devices/curtains.d.ts +14 -5
  16. package/dist/devices/curtains.d.ts.map +1 -1
  17. package/dist/devices/curtains.js +180 -140
  18. package/dist/devices/curtains.js.map +1 -1
  19. package/dist/devices/humidifiers.d.ts +14 -3
  20. package/dist/devices/humidifiers.d.ts.map +1 -1
  21. package/dist/devices/humidifiers.js +173 -133
  22. package/dist/devices/humidifiers.js.map +1 -1
  23. package/dist/devices/meters.d.ts +17 -13
  24. package/dist/devices/meters.d.ts.map +1 -1
  25. package/dist/devices/meters.js +150 -105
  26. package/dist/devices/meters.js.map +1 -1
  27. package/dist/devices/motion.d.ts +13 -3
  28. package/dist/devices/motion.d.ts.map +1 -1
  29. package/dist/devices/motion.js +89 -45
  30. package/dist/devices/motion.js.map +1 -1
  31. package/dist/devices/plugs.d.ts +15 -3
  32. package/dist/devices/plugs.d.ts.map +1 -1
  33. package/dist/devices/plugs.js +115 -53
  34. package/dist/devices/plugs.js.map +1 -1
  35. package/dist/irdevices/airconditioners.d.ts +13 -3
  36. package/dist/irdevices/airconditioners.d.ts.map +1 -1
  37. package/dist/irdevices/airconditioners.js +97 -46
  38. package/dist/irdevices/airconditioners.js.map +1 -1
  39. package/dist/irdevices/airpurifiers.d.ts +13 -3
  40. package/dist/irdevices/airpurifiers.d.ts.map +1 -1
  41. package/dist/irdevices/airpurifiers.js +85 -31
  42. package/dist/irdevices/airpurifiers.js.map +1 -1
  43. package/dist/irdevices/cameras.d.ts +12 -3
  44. package/dist/irdevices/cameras.d.ts.map +1 -1
  45. package/dist/irdevices/cameras.js +73 -24
  46. package/dist/irdevices/cameras.js.map +1 -1
  47. package/dist/irdevices/fans.d.ts +12 -3
  48. package/dist/irdevices/fans.d.ts.map +1 -1
  49. package/dist/irdevices/fans.js +83 -35
  50. package/dist/irdevices/fans.js.map +1 -1
  51. package/dist/irdevices/lights.d.ts +12 -3
  52. package/dist/irdevices/lights.d.ts.map +1 -1
  53. package/dist/irdevices/lights.js +74 -25
  54. package/dist/irdevices/lights.js.map +1 -1
  55. package/dist/irdevices/others.d.ts +12 -3
  56. package/dist/irdevices/others.d.ts.map +1 -1
  57. package/dist/irdevices/others.js +80 -31
  58. package/dist/irdevices/others.js.map +1 -1
  59. package/dist/irdevices/tvs.d.ts +12 -3
  60. package/dist/irdevices/tvs.d.ts.map +1 -1
  61. package/dist/irdevices/tvs.js +90 -42
  62. package/dist/irdevices/tvs.js.map +1 -1
  63. package/dist/irdevices/vacuumcleaners.d.ts +12 -3
  64. package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
  65. package/dist/irdevices/vacuumcleaners.js +73 -24
  66. package/dist/irdevices/vacuumcleaners.js.map +1 -1
  67. package/dist/irdevices/waterheaters.d.ts +12 -3
  68. package/dist/irdevices/waterheaters.d.ts.map +1 -1
  69. package/dist/irdevices/waterheaters.js +73 -24
  70. package/dist/irdevices/waterheaters.js.map +1 -1
  71. package/dist/platform.d.ts +10 -10
  72. package/dist/platform.d.ts.map +1 -1
  73. package/dist/platform.js +290 -307
  74. package/dist/platform.js.map +1 -1
  75. package/dist/settings.d.ts +9 -6
  76. package/dist/settings.d.ts.map +1 -1
  77. package/dist/settings.js.map +1 -1
  78. package/nodemon.json +1 -1
  79. package/package.json +6 -6
  80. package/src/devices/bots.ts +221 -152
  81. package/src/devices/colorbulb.ts +172 -108
  82. package/src/devices/contact.ts +109 -64
  83. package/src/devices/curtains.ts +190 -146
  84. package/src/devices/humidifiers.ts +181 -135
  85. package/src/devices/meters.ts +156 -105
  86. package/src/devices/motion.ts +95 -45
  87. package/src/devices/plugs.ts +121 -53
  88. package/src/irdevices/airconditioners.ts +102 -46
  89. package/src/irdevices/airpurifiers.ts +91 -31
  90. package/src/irdevices/cameras.ts +79 -24
  91. package/src/irdevices/fans.ts +89 -36
  92. package/src/irdevices/lights.ts +80 -25
  93. package/src/irdevices/others.ts +86 -31
  94. package/src/irdevices/tvs.ts +96 -42
  95. package/src/irdevices/vacuumcleaners.ts +79 -24
  96. package/src/irdevices/waterheaters.ts +79 -24
  97. package/src/platform.ts +285 -302
  98. package/src/settings.ts +10 -6
  99. package/dist/devices/indoorcam.d.ts +0 -64
  100. package/dist/devices/indoorcam.d.ts.map +0 -1
  101. package/dist/devices/indoorcam.js +0 -249
  102. package/dist/devices/indoorcam.js.map +0 -1
  103. package/src/devices/indoorcam.ts +0 -309
@@ -1,7 +1,7 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { SwitchBotPlatform } from '../platform';
3
3
  import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
4
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
4
+ import { CharacteristicValue, HAPStatus, PlatformAccessory, Service } from 'homebridge';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -14,16 +14,24 @@ export class VacuumCleaner {
14
14
 
15
15
  // Characteristic Values
16
16
  On!: CharacteristicValue;
17
+ OnCached!: CharacteristicValue;
17
18
 
18
19
  // Config
19
- private readonly deviceDebug = this.platform.config.options?.debug === 'device' || this.platform.debugMode;
20
- private readonly debugDebug = this.platform.config.options?.debug === 'debug' || this.platform.debugMode;
20
+ deviceLogging!: string;
21
21
 
22
22
  constructor(
23
23
  private readonly platform: SwitchBotPlatform,
24
24
  private accessory: PlatformAccessory,
25
25
  public device: irdevice & irDevicesConfig,
26
26
  ) {
27
+ // default placeholders
28
+ this.logs();
29
+ if (this.On === undefined) {
30
+ this.On = false;
31
+ } else {
32
+ this.On = this.accessory.context.On;
33
+ }
34
+
27
35
  // set accessory information
28
36
  accessory
29
37
  .getService(this.platform.Service.AccessoryInformation)!
@@ -49,8 +57,18 @@ export class VacuumCleaner {
49
57
  this.service.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
50
58
  }
51
59
 
60
+ logs() {
61
+ if (this.device.logging) {
62
+ this.deviceLogging = this.accessory.context.logging = this.device.logging;
63
+ } else if (this.platform.config.options?.logging) {
64
+ this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
65
+ } else {
66
+ this.deviceLogging = this.accessory.context.logging = 'standard';
67
+ }
68
+ }
69
+
52
70
  private OnSet(value: CharacteristicValue) {
53
- this.platform.debug(`Vacuum Cleaner: ${this.accessory.displayName} On: ${value}`);
71
+ this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} On: ${value}`);
54
72
  this.On = value;
55
73
  if (this.On) {
56
74
  this.pushOnChanges();
@@ -61,10 +79,10 @@ export class VacuumCleaner {
61
79
 
62
80
  private updateHomeKitCharacteristics() {
63
81
  if (this.On === undefined) {
64
- this.platform.debug(`Vacuum Cleaner: ${this.accessory.displayName} On: ${this.On}`);
82
+ this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} On: ${this.On}`);
65
83
  } else {
66
84
  this.service?.updateCharacteristic(this.platform.Characteristic.On, this.On);
67
- this.platform.device(`Vacuum Cleaner: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
85
+ this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
68
86
  }
69
87
  }
70
88
 
@@ -102,58 +120,95 @@ export class VacuumCleaner {
102
120
 
103
121
  public async pushChanges(payload: payload) {
104
122
  try {
105
- this.platform.log.info(`Vacuum Cleaner: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
123
+ this.infoLog(`Vacuum Cleaner: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
106
124
  + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
107
125
 
108
126
  // Make the API request
109
127
  const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
110
- this.platform.debug(`Vacuum Cleaner: ${this.accessory.displayName} pushChanges: ${push.data}`);
128
+ this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} pushChanges: ${push.data}`);
111
129
  this.statusCode(push);
130
+ this.OnCached = this.On;
131
+ this.accessory.context.On = this.OnCached;
112
132
  this.updateHomeKitCharacteristics();
113
133
  } catch (e: any) {
114
- this.platform.log.error(`Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
115
- if (this.deviceDebug) {
116
- this.platform.log.error(`Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
134
+ this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
135
+ if (this.deviceLogging === 'debug') {
136
+ this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
117
137
  + ` Error Message: ${JSON.stringify(e.message)}`);
118
138
  }
119
- if (this.debugDebug) {
120
- this.platform.log.error(`Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
139
+ if (this.platform.debugMode) {
140
+ this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
121
141
  + ` Error: ${JSON.stringify(e)}`);
122
142
  }
123
- this.apiError(e);
143
+ this.apiError();
124
144
  }
125
145
  }
126
146
 
127
147
  private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
128
148
  switch (push.data.statusCode) {
129
149
  case 151:
130
- this.platform.log.error(`Vacuum Cleaner: ${this.accessory.displayName} Command not supported by this device type.`);
150
+ this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Command not supported by this device type.`);
131
151
  break;
132
152
  case 152:
133
- this.platform.log.error(`Vacuum Cleaner: ${this.accessory.displayName} Device not found.`);
153
+ this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Device not found.`);
134
154
  break;
135
155
  case 160:
136
- this.platform.log.error(`Vacuum Cleaner: ${this.accessory.displayName} Command is not supported.`);
156
+ this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Command is not supported.`);
137
157
  break;
138
158
  case 161:
139
- this.platform.log.error(`Vacuum Cleaner: ${this.accessory.displayName} Device is offline.`);
159
+ this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Device is offline.`);
140
160
  break;
141
161
  case 171:
142
- this.platform.log.error(`Vacuum Cleaner: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
162
+ this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
143
163
  break;
144
164
  case 190:
145
- this.platform.log.error(`Vacuum Cleaner: ${this.accessory.displayName} Device internal error due to device states not synchronized`
165
+ this.errorLog(`Vacuum Cleaner: ${this.accessory.displayName} Device internal error due to device states not synchronized`
146
166
  + ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`);
147
167
  break;
148
168
  case 100:
149
- this.platform.debug(`Vacuum Cleaner: ${this.accessory.displayName} Command successfully sent.`);
169
+ this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} Command successfully sent.`);
150
170
  break;
151
171
  default:
152
- this.platform.debug(`Vacuum Cleaner: ${this.accessory.displayName} Unknown statusCode.`);
172
+ this.debugLog(`Vacuum Cleaner: ${this.accessory.displayName} Unknown statusCode.`);
173
+ }
174
+ }
175
+
176
+ public apiError() {
177
+ throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
178
+ }
179
+
180
+ /**
181
+ * Logging for Device
182
+ */
183
+ infoLog(...log: any[]) {
184
+ if (this.enablingDeviceLogging()) {
185
+ this.platform.log.info(String(...log));
186
+ }
187
+ }
188
+
189
+ warnLog(...log: any[]) {
190
+ if (this.enablingDeviceLogging()) {
191
+ this.platform.log.warn(String(...log));
192
+ }
193
+ }
194
+
195
+ errorLog(...log: any[]) {
196
+ if (this.enablingDeviceLogging()) {
197
+ this.platform.log.error(String(...log));
198
+ }
199
+ }
200
+
201
+ debugLog(...log: any[]) {
202
+ if (this.enablingDeviceLogging()) {
203
+ if (this.deviceLogging === 'debug') {
204
+ this.platform.log.info('[DEBUG]', String(...log));
205
+ } else {
206
+ this.platform.log.debug(String(...log));
207
+ }
153
208
  }
154
209
  }
155
210
 
156
- public apiError(e: any) {
157
- this.service.updateCharacteristic(this.platform.Characteristic.On, e);
211
+ enablingDeviceLogging(): boolean {
212
+ return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
158
213
  }
159
214
  }
@@ -1,7 +1,7 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { SwitchBotPlatform } from '../platform';
3
3
  import { irDevicesConfig, DeviceURL, irdevice, payload } from '../settings';
4
- import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
4
+ import { CharacteristicValue, HAPStatus, PlatformAccessory, Service } from 'homebridge';
5
5
 
6
6
  /**
7
7
  * Platform Accessory
@@ -14,16 +14,24 @@ export class WaterHeater {
14
14
 
15
15
  // Characteristic Values
16
16
  Active!: CharacteristicValue;
17
+ ActiveCached!: CharacteristicValue;
17
18
 
18
19
  // Config
19
- private readonly deviceDebug = this.platform.config.options?.debug === 'device' || this.platform.debugMode;
20
- private readonly debugDebug = this.platform.config.options?.debug === 'debug' || this.platform.debugMode;
20
+ deviceLogging!: string;
21
21
 
22
22
  constructor(
23
23
  private readonly platform: SwitchBotPlatform,
24
24
  private accessory: PlatformAccessory,
25
25
  public device: irdevice & irDevicesConfig,
26
26
  ) {
27
+ // default placeholders
28
+ this.logs();
29
+ if (this.Active === undefined) {
30
+ this.Active = this.platform.Characteristic.Active.INACTIVE;
31
+ } else {
32
+ this.Active = this.accessory.context.Active;
33
+ }
34
+
27
35
  // set accessory information
28
36
  accessory
29
37
  .getService(this.platform.Service.AccessoryInformation)!
@@ -58,8 +66,18 @@ export class WaterHeater {
58
66
  this.service.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
59
67
  }
60
68
 
69
+ logs() {
70
+ if (this.device.logging) {
71
+ this.deviceLogging = this.accessory.context.logging = this.device.logging;
72
+ } else if (this.platform.config.options?.logging) {
73
+ this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
74
+ } else {
75
+ this.deviceLogging = this.accessory.context.logging = 'standard';
76
+ }
77
+ }
78
+
61
79
  private ActiveSet(value: CharacteristicValue) {
62
- this.platform.debug(`Water Heater: ${this.accessory.displayName} Active: ${value}`);
80
+ this.debugLog(`Water Heater: ${this.accessory.displayName} Active: ${value}`);
63
81
  if (value === this.platform.Characteristic.Active.INACTIVE) {
64
82
  this.pushWaterHeaterOffChanges();
65
83
  this.service.setCharacteristic(
@@ -71,14 +89,16 @@ export class WaterHeater {
71
89
  this.service.setCharacteristic(this.platform.Characteristic.InUse, this.platform.Characteristic.InUse.IN_USE);
72
90
  }
73
91
  this.Active = value;
92
+ this.ActiveCached = this.Active;
93
+ this.accessory.context.Active = this.ActiveCached;
74
94
  }
75
95
 
76
96
  private updateHomeKitCharacteristics() {
77
97
  if (this.Active === undefined) {
78
- this.platform.debug(`Water Heater: ${this.accessory.displayName} Active: ${this.Active}`);
98
+ this.debugLog(`Water Heater: ${this.accessory.displayName} Active: ${this.Active}`);
79
99
  } else {
80
100
  this.service?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
81
- this.platform.device(`Water Heater: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
101
+ this.debugLog(`Water Heater: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
82
102
  }
83
103
  }
84
104
 
@@ -116,58 +136,93 @@ export class WaterHeater {
116
136
 
117
137
  public async pushChanges(payload: payload) {
118
138
  try {
119
- this.platform.log.info(`Water Heater: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
139
+ this.infoLog(`Water Heater: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
120
140
  + ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
121
141
 
122
142
  // Make the API request
123
143
  const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
124
- this.platform.debug(`Water Heater: ${this.accessory.displayName} pushChanges: ${push.data}`);
144
+ this.debugLog(`Water Heater: ${this.accessory.displayName} pushChanges: ${push.data}`);
125
145
  this.statusCode(push);
126
146
  this.updateHomeKitCharacteristics();
127
147
  } catch (e: any) {
128
- this.platform.log.error(`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
129
- if (this.deviceDebug) {
130
- this.platform.log.error(`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
148
+ this.errorLog(`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
149
+ if (this.deviceLogging === 'debug') {
150
+ this.errorLog(`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
131
151
  + ` Error Message: ${JSON.stringify(e.message)}`);
132
152
  }
133
- if (this.debugDebug) {
134
- this.platform.log.error(`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
153
+ if (this.platform.debugMode) {
154
+ this.errorLog(`Water Heater: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
135
155
  + ` Error: ${JSON.stringify(e)}`);
136
156
  }
137
- this.apiError(e);
157
+ this.apiError();
138
158
  }
139
159
  }
140
160
 
141
161
  private statusCode(push: AxiosResponse<{ statusCode: number; }>) {
142
162
  switch (push.data.statusCode) {
143
163
  case 151:
144
- this.platform.log.error(`Water Heater: ${this.accessory.displayName} Command not supported by this device type.`);
164
+ this.errorLog(`Water Heater: ${this.accessory.displayName} Command not supported by this device type.`);
145
165
  break;
146
166
  case 152:
147
- this.platform.log.error(`Water Heater: ${this.accessory.displayName} Device not found.`);
167
+ this.errorLog(`Water Heater: ${this.accessory.displayName} Device not found.`);
148
168
  break;
149
169
  case 160:
150
- this.platform.log.error(`Water Heater: ${this.accessory.displayName} Command is not supported.`);
170
+ this.errorLog(`Water Heater: ${this.accessory.displayName} Command is not supported.`);
151
171
  break;
152
172
  case 161:
153
- this.platform.log.error(`Water Heater: ${this.accessory.displayName} Device is offline.`);
173
+ this.errorLog(`Water Heater: ${this.accessory.displayName} Device is offline.`);
154
174
  break;
155
175
  case 171:
156
- this.platform.log.error(`Water Heater: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
176
+ this.errorLog(`Water Heater: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
157
177
  break;
158
178
  case 190:
159
- this.platform.log.error(`Water Heater: ${this.accessory.displayName} Device internal error due to device states not synchronized`
179
+ this.errorLog(`Water Heater: ${this.accessory.displayName} Device internal error due to device states not synchronized`
160
180
  + ` with server, Or command: ${JSON.stringify(push.data)} format is invalid`);
161
181
  break;
162
182
  case 100:
163
- this.platform.debug(`Water Heater: ${this.accessory.displayName} Command successfully sent.`);
183
+ this.debugLog(`Water Heater: ${this.accessory.displayName} Command successfully sent.`);
164
184
  break;
165
185
  default:
166
- this.platform.debug(`Water Heater: ${this.accessory.displayName} Unknown statusCode.`);
186
+ this.debugLog(`Water Heater: ${this.accessory.displayName} Unknown statusCode.`);
187
+ }
188
+ }
189
+
190
+ public apiError() {
191
+ throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
192
+ }
193
+
194
+ /**
195
+ * Logging for Device
196
+ */
197
+ infoLog(...log: any[]) {
198
+ if (this.enablingDeviceLogging()) {
199
+ this.platform.log.info(String(...log));
200
+ }
201
+ }
202
+
203
+ warnLog(...log: any[]) {
204
+ if (this.enablingDeviceLogging()) {
205
+ this.platform.log.warn(String(...log));
206
+ }
207
+ }
208
+
209
+ errorLog(...log: any[]) {
210
+ if (this.enablingDeviceLogging()) {
211
+ this.platform.log.error(String(...log));
212
+ }
213
+ }
214
+
215
+ debugLog(...log: any[]) {
216
+ if (this.enablingDeviceLogging()) {
217
+ if (this.deviceLogging === 'debug') {
218
+ this.platform.log.info('[DEBUG]', String(...log));
219
+ } else {
220
+ this.platform.log.debug(String(...log));
221
+ }
167
222
  }
168
223
  }
169
224
 
170
- public apiError(e: any) {
171
- this.service.updateCharacteristic(this.platform.Characteristic.Active, e);
225
+ enablingDeviceLogging(): boolean {
226
+ return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
172
227
  }
173
228
  }