@switchbot/homebridge-switchbot 2.0.0-beta.18 → 2.0.0-beta.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/config.schema.json +11 -2
- package/dist/device/bot.d.ts +2 -0
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +201 -163
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts +2 -0
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +250 -218
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +2 -0
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +85 -66
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +2 -0
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +166 -136
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +126 -115
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts +2 -0
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +156 -130
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +2 -0
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +85 -64
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +2 -0
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +78 -59
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +2 -0
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +76 -57
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +2 -0
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +133 -107
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts +2 -0
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +224 -195
- package/dist/device/striplight.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +2 -0
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +127 -105
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +2 -0
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +83 -66
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +8 -6
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +83 -68
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +7 -5
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +90 -75
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +8 -6
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +83 -68
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +8 -6
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +93 -78
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +8 -6
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +68 -52
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +8 -6
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +83 -69
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +2 -0
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +75 -60
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/settings.d.ts +12 -11
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +1 -1
- package/src/device/bot.ts +200 -163
- package/src/device/colorbulb.ts +252 -221
- package/src/device/contact.ts +85 -66
- package/src/device/curtain.ts +165 -136
- package/src/device/humidifier.ts +126 -115
- package/src/device/lock.ts +156 -131
- package/src/device/meter.ts +85 -64
- package/src/device/meterplus.ts +78 -59
- package/src/device/motion.ts +76 -57
- package/src/device/plug.ts +132 -107
- package/src/device/striplight.ts +226 -198
- package/src/irdevice/airconditioner.ts +126 -103
- package/src/irdevice/airpurifier.ts +84 -66
- package/src/irdevice/camera.ts +84 -68
- package/src/irdevice/fan.ts +91 -75
- package/src/irdevice/light.ts +84 -68
- package/src/irdevice/other.ts +94 -78
- package/src/irdevice/tv.ts +69 -53
- package/src/irdevice/vacuumcleaner.ts +83 -68
- package/src/irdevice/waterheater.ts +76 -60
- package/src/settings.ts +12 -11
|
@@ -21,6 +21,7 @@ export class VacuumCleaner {
|
|
|
21
21
|
|
|
22
22
|
// Config
|
|
23
23
|
deviceLogging!: string;
|
|
24
|
+
OpenAPI?: boolean;
|
|
24
25
|
|
|
25
26
|
constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: irdevice & irDevicesConfig) {
|
|
26
27
|
// default placeholders
|
|
@@ -57,7 +58,7 @@ export class VacuumCleaner {
|
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
60
|
-
this.debugLog(
|
|
61
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${value}`);
|
|
61
62
|
this.On = value;
|
|
62
63
|
if (this.On) {
|
|
63
64
|
await this.pushOnChanges();
|
|
@@ -68,22 +69,22 @@ export class VacuumCleaner {
|
|
|
68
69
|
|
|
69
70
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
70
71
|
if (this.On === undefined) {
|
|
71
|
-
this.debugLog(
|
|
72
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
72
73
|
} else {
|
|
73
74
|
this.switchService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
|
|
74
|
-
this.debugLog(
|
|
75
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
/**
|
|
79
80
|
* Pushes the requested changes to the SwitchBot API
|
|
80
81
|
* deviceType commandType Command command parameter Description
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
82
|
+
* Vacuum Cleaner - "command" "turnOff" "default" = set to OFF state
|
|
83
|
+
* Vacuum Cleaner - "command" "turnOn" "default" = set to ON state
|
|
84
|
+
* Vacuum Cleaner - "command" "volumeAdd" "default" = volume up
|
|
85
|
+
* Vacuum Cleaner - "command" "volumeSub" "default" = volume down
|
|
86
|
+
* Vacuum Cleaner - "command" "channelAdd" "default" = next channel
|
|
87
|
+
* Vacuum Cleaner - "command" "channelSub" "default" = previous channel
|
|
87
88
|
*/
|
|
88
89
|
async pushOnChanges(): Promise<void> {
|
|
89
90
|
if (this.On) {
|
|
@@ -108,87 +109,89 @@ export class VacuumCleaner {
|
|
|
108
109
|
}
|
|
109
110
|
|
|
110
111
|
async pushChanges(body): Promise<void> {
|
|
111
|
-
|
|
112
|
+
if (this.OpenAPI) {
|
|
113
|
+
try {
|
|
112
114
|
// Make Push On request to the API
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
115
|
+
const t = Date.now();
|
|
116
|
+
const nonce = 'requestID';
|
|
117
|
+
const data = this.platform.config.credentials?.token + t + nonce;
|
|
118
|
+
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
119
|
+
.update(Buffer.from(data, 'utf-8'))
|
|
120
|
+
.digest();
|
|
121
|
+
const sign = signTerm.toString('base64');
|
|
122
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
123
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
124
|
+
const options = {
|
|
125
|
+
hostname: HostDomain,
|
|
126
|
+
port: 443,
|
|
127
|
+
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
128
|
+
method: 'POST',
|
|
129
|
+
headers: {
|
|
130
|
+
'Authorization': this.platform.config.credentials?.token,
|
|
131
|
+
'sign': sign,
|
|
132
|
+
'nonce': nonce,
|
|
133
|
+
't': t,
|
|
134
|
+
'Content-Type': 'application/json',
|
|
135
|
+
'Content-Length': body.length,
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
const req = https.request(options, res => {
|
|
139
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
140
|
+
this.statusCode({ res });
|
|
141
|
+
res.on('data', d => {
|
|
142
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} d: ${d}`);
|
|
143
|
+
});
|
|
141
144
|
});
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
`Vacuum Cleaner: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
145
|
+
req.on('error', (e: any) => {
|
|
146
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
147
|
+
});
|
|
148
|
+
req.write(body);
|
|
149
|
+
req.end();
|
|
150
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
|
|
151
|
+
this.OnCached = this.On;
|
|
152
|
+
this.accessory.context.On = this.OnCached;
|
|
153
|
+
this.updateHomeKitCharacteristics();
|
|
154
|
+
} catch (e: any) {
|
|
155
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
156
|
+
if (this.deviceLogging.includes('debug')) {
|
|
157
|
+
this.errorLog(
|
|
158
|
+
`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
157
159
|
` Error Message: ${superStringify(e.message)}`,
|
|
158
|
-
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
this.apiError(e);
|
|
159
163
|
}
|
|
160
|
-
this.apiError(e);
|
|
161
164
|
}
|
|
162
165
|
}
|
|
163
166
|
|
|
164
167
|
async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
|
|
165
168
|
switch (res.statusCode) {
|
|
166
169
|
case 151:
|
|
167
|
-
this.errorLog(
|
|
170
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
168
171
|
break;
|
|
169
172
|
case 152:
|
|
170
|
-
this.errorLog(
|
|
173
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found.`);
|
|
171
174
|
break;
|
|
172
175
|
case 160:
|
|
173
|
-
this.errorLog(
|
|
176
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported.`);
|
|
174
177
|
break;
|
|
175
178
|
case 161:
|
|
176
|
-
this.errorLog(
|
|
179
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline.`);
|
|
177
180
|
break;
|
|
178
181
|
case 171:
|
|
179
|
-
this.errorLog(
|
|
182
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
|
|
180
183
|
break;
|
|
181
184
|
case 190:
|
|
182
185
|
this.errorLog(
|
|
183
|
-
|
|
186
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
|
|
184
187
|
` with server, Or command: ${superStringify(res)} format is invalid`,
|
|
185
188
|
);
|
|
186
189
|
break;
|
|
187
190
|
case 100:
|
|
188
|
-
this.debugLog(
|
|
191
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent.`);
|
|
189
192
|
break;
|
|
190
193
|
default:
|
|
191
|
-
this.debugLog(
|
|
194
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode.`);
|
|
192
195
|
}
|
|
193
196
|
}
|
|
194
197
|
|
|
@@ -197,6 +200,15 @@ export class VacuumCleaner {
|
|
|
197
200
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
198
201
|
}
|
|
199
202
|
|
|
203
|
+
async openAPI() {
|
|
204
|
+
if (!this.device.openAPI) {
|
|
205
|
+
this.OpenAPI = true;
|
|
206
|
+
} else {
|
|
207
|
+
this.OpenAPI = this.device.openAPI;
|
|
208
|
+
}
|
|
209
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using OpenAPI: ${this.OpenAPI}`);
|
|
210
|
+
}
|
|
211
|
+
|
|
200
212
|
async config(device: irdevice & irDevicesConfig): Promise<void> {
|
|
201
213
|
let config = {};
|
|
202
214
|
if (device.irvc) {
|
|
@@ -205,24 +217,27 @@ export class VacuumCleaner {
|
|
|
205
217
|
if (device.logging !== undefined) {
|
|
206
218
|
config['logging'] = device.logging;
|
|
207
219
|
}
|
|
220
|
+
if (device.openAPI !== undefined) {
|
|
221
|
+
config['openAPI'] = device.openAPI;
|
|
222
|
+
}
|
|
208
223
|
if (Object.entries(config).length !== 0) {
|
|
209
|
-
this.infoLog(
|
|
224
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
|
|
210
225
|
}
|
|
211
226
|
}
|
|
212
227
|
|
|
213
228
|
async logs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
214
229
|
if (this.platform.debugMode) {
|
|
215
230
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
216
|
-
this.debugLog(
|
|
231
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
217
232
|
} else if (device.logging) {
|
|
218
233
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
219
|
-
this.debugLog(
|
|
234
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
220
235
|
} else if (this.platform.config.options?.logging) {
|
|
221
236
|
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
222
|
-
this.debugLog(
|
|
237
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
223
238
|
} else {
|
|
224
239
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
225
|
-
this.debugLog(
|
|
240
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
226
241
|
}
|
|
227
242
|
}
|
|
228
243
|
|
|
@@ -21,6 +21,7 @@ export class WaterHeater {
|
|
|
21
21
|
|
|
22
22
|
// Config
|
|
23
23
|
deviceLogging!: string;
|
|
24
|
+
OpenAPI?: boolean;
|
|
24
25
|
|
|
25
26
|
constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: irdevice & irDevicesConfig) {
|
|
26
27
|
// default placeholders
|
|
@@ -60,7 +61,7 @@ export class WaterHeater {
|
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
63
|
-
this.debugLog(
|
|
64
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${value}`);
|
|
64
65
|
if (value === this.platform.Characteristic.Active.INACTIVE) {
|
|
65
66
|
await this.pushWaterHeaterOffChanges();
|
|
66
67
|
this.valveService.setCharacteristic(this.platform.Characteristic.InUse, this.platform.Characteristic.InUse.NOT_IN_USE);
|
|
@@ -75,10 +76,10 @@ export class WaterHeater {
|
|
|
75
76
|
|
|
76
77
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
77
78
|
if (this.Active === undefined) {
|
|
78
|
-
this.debugLog(
|
|
79
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
|
|
79
80
|
} else {
|
|
80
81
|
this.valveService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
|
|
81
|
-
this.debugLog(
|
|
82
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
85
|
|
|
@@ -115,84 +116,87 @@ export class WaterHeater {
|
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
async pushChanges(body): Promise<void> {
|
|
118
|
-
|
|
119
|
+
if (this.OpenAPI) {
|
|
120
|
+
try {
|
|
119
121
|
// Make Push On request to the API
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
122
|
+
const t = Date.now();
|
|
123
|
+
const nonce = 'requestID';
|
|
124
|
+
const data = this.platform.config.credentials?.token + t + nonce;
|
|
125
|
+
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret)
|
|
126
|
+
.update(Buffer.from(data, 'utf-8'))
|
|
127
|
+
.digest();
|
|
128
|
+
const sign = signTerm.toString('base64');
|
|
129
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
130
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
131
|
+
const options = {
|
|
132
|
+
hostname: HostDomain,
|
|
133
|
+
port: 443,
|
|
134
|
+
path: `${DevicePath}/${this.device.deviceId}/commands`,
|
|
135
|
+
method: 'POST',
|
|
136
|
+
headers: {
|
|
137
|
+
'Authorization': this.platform.config.credentials?.token,
|
|
138
|
+
'sign': sign,
|
|
139
|
+
'nonce': nonce,
|
|
140
|
+
't': t,
|
|
141
|
+
'Content-Type': 'application/json',
|
|
142
|
+
'Content-Length': body.length,
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
const req = https.request(options, res => {
|
|
146
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
147
|
+
this.statusCode({ res });
|
|
148
|
+
res.on('data', d => {
|
|
149
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} d: ${d}`);
|
|
150
|
+
});
|
|
148
151
|
});
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
152
|
+
req.on('error', (e: any) => {
|
|
153
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
154
|
+
});
|
|
155
|
+
req.write(body);
|
|
156
|
+
req.end();
|
|
157
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushchanges: ${superStringify(req)}`);
|
|
158
|
+
this.updateHomeKitCharacteristics();
|
|
159
|
+
} catch (e: any) {
|
|
160
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
161
|
+
if (this.deviceLogging.includes('debug')) {
|
|
162
|
+
this.errorLog(
|
|
163
|
+
`${this.device.remoteType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
164
|
+
+ ` Error Message: ${superStringify(e.message)}`,
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
this.apiError(e);
|
|
163
168
|
}
|
|
164
|
-
this.apiError(e);
|
|
165
169
|
}
|
|
166
170
|
}
|
|
167
171
|
|
|
168
172
|
async statusCode({ res }: { res: IncomingMessage }): Promise<void> {
|
|
169
173
|
switch (res.statusCode) {
|
|
170
174
|
case 151:
|
|
171
|
-
this.errorLog(
|
|
175
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
172
176
|
break;
|
|
173
177
|
case 152:
|
|
174
|
-
this.errorLog(
|
|
178
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device not found.`);
|
|
175
179
|
break;
|
|
176
180
|
case 160:
|
|
177
|
-
this.errorLog(
|
|
181
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Command is not supported.`);
|
|
178
182
|
break;
|
|
179
183
|
case 161:
|
|
180
|
-
this.errorLog(
|
|
184
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Device is offline.`);
|
|
181
185
|
break;
|
|
182
186
|
case 171:
|
|
183
|
-
this.errorLog(
|
|
187
|
+
this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} Hub Device is offline. Hub: ${this.device.hubDeviceId}`);
|
|
184
188
|
break;
|
|
185
189
|
case 190:
|
|
186
190
|
this.errorLog(
|
|
187
|
-
|
|
191
|
+
`${this.device.remoteType}: ${this.accessory.displayName} Device internal error due to device states not synchronized` +
|
|
188
192
|
` with server, Or command: ${superStringify(res)} format is invalid`,
|
|
189
193
|
);
|
|
190
194
|
break;
|
|
191
195
|
case 100:
|
|
192
|
-
this.debugLog(
|
|
196
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Command successfully sent.`);
|
|
193
197
|
break;
|
|
194
198
|
default:
|
|
195
|
-
this.debugLog(
|
|
199
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Unknown statusCode.`);
|
|
196
200
|
}
|
|
197
201
|
}
|
|
198
202
|
|
|
@@ -201,6 +205,15 @@ export class WaterHeater {
|
|
|
201
205
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
202
206
|
}
|
|
203
207
|
|
|
208
|
+
async openAPI() {
|
|
209
|
+
if (!this.device.openAPI) {
|
|
210
|
+
this.OpenAPI = true;
|
|
211
|
+
} else {
|
|
212
|
+
this.OpenAPI = this.device.openAPI;
|
|
213
|
+
}
|
|
214
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using OpenAPI: ${this.OpenAPI}`);
|
|
215
|
+
}
|
|
216
|
+
|
|
204
217
|
async config(device: irdevice & irDevicesConfig): Promise<void> {
|
|
205
218
|
let config = {};
|
|
206
219
|
if (device.irwh) {
|
|
@@ -209,24 +222,27 @@ export class WaterHeater {
|
|
|
209
222
|
if (device.logging !== undefined) {
|
|
210
223
|
config['logging'] = device.logging;
|
|
211
224
|
}
|
|
225
|
+
if (device.openAPI !== undefined) {
|
|
226
|
+
config['openAPI'] = device.openAPI;
|
|
227
|
+
}
|
|
212
228
|
if (Object.entries(config).length !== 0) {
|
|
213
|
-
this.infoLog(
|
|
229
|
+
this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
|
|
214
230
|
}
|
|
215
231
|
}
|
|
216
232
|
|
|
217
233
|
async logs(device: irdevice & irDevicesConfig): Promise<void> {
|
|
218
234
|
if (this.platform.debugMode) {
|
|
219
235
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
220
|
-
this.debugLog(
|
|
236
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
221
237
|
} else if (device.logging) {
|
|
222
238
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
223
|
-
this.debugLog(
|
|
239
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
224
240
|
} else if (this.platform.config.options?.logging) {
|
|
225
241
|
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
226
|
-
this.debugLog(
|
|
242
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
227
243
|
} else {
|
|
228
244
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
229
|
-
this.debugLog(
|
|
245
|
+
this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
230
246
|
}
|
|
231
247
|
}
|
|
232
248
|
|
package/src/settings.ts
CHANGED
|
@@ -45,18 +45,9 @@ export interface devicesConfig extends device {
|
|
|
45
45
|
configDeviceName?: string;
|
|
46
46
|
deviceId: string;
|
|
47
47
|
external?: boolean;
|
|
48
|
-
logging?: string;
|
|
49
48
|
refreshRate?: number;
|
|
50
49
|
firmware?: string;
|
|
51
|
-
|
|
52
|
-
meter?: meter;
|
|
53
|
-
humidifier?: humidifier;
|
|
54
|
-
curtain?: curtain;
|
|
55
|
-
contact?: contact;
|
|
56
|
-
motion?: motion;
|
|
57
|
-
colorbulb?: colorbulb;
|
|
58
|
-
plug?: Record<any, any>;
|
|
59
|
-
lock?: lock;
|
|
50
|
+
logging?: string;
|
|
60
51
|
ble?: boolean;
|
|
61
52
|
openAPI?: boolean;
|
|
62
53
|
customBLEaddress?: string;
|
|
@@ -67,6 +58,15 @@ export interface devicesConfig extends device {
|
|
|
67
58
|
mqttOptions?: IClientOptions;
|
|
68
59
|
mqttPubOptions?: IClientOptions;
|
|
69
60
|
history?: boolean;
|
|
61
|
+
bot?: bot;
|
|
62
|
+
meter?: meter;
|
|
63
|
+
humidifier?: humidifier;
|
|
64
|
+
curtain?: curtain;
|
|
65
|
+
contact?: contact;
|
|
66
|
+
motion?: motion;
|
|
67
|
+
colorbulb?: colorbulb;
|
|
68
|
+
plug?: Record<any, any>;
|
|
69
|
+
lock?: lock;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
export type meter = {
|
|
@@ -127,6 +127,8 @@ export interface irDevicesConfig extends irdevice {
|
|
|
127
127
|
deviceId: string;
|
|
128
128
|
external?: boolean;
|
|
129
129
|
logging?: string;
|
|
130
|
+
openAPI?: boolean;
|
|
131
|
+
hide_device?: boolean;
|
|
130
132
|
irfan?: irfan;
|
|
131
133
|
irair?: irair;
|
|
132
134
|
irpur?: Record<any, any>;
|
|
@@ -136,7 +138,6 @@ export interface irDevicesConfig extends irdevice {
|
|
|
136
138
|
irwh?: Record<any, any>;
|
|
137
139
|
irtv?: irtv;
|
|
138
140
|
other?: other;
|
|
139
|
-
hide_device?: boolean;
|
|
140
141
|
}
|
|
141
142
|
|
|
142
143
|
export type irfan = {
|