From d474e280e486943e7735fe388c3778b6e65f5769 Mon Sep 17 00:00:00 2001 From: Ingo Fischer Date: Tue, 10 Jan 2023 11:25:47 +0100 Subject: [PATCH] * (Apollon77) Return response body for getCharacteristics and subscribe/unsubscribe also when return code was 207 in IP mode --- README.md | 4 ++++ src/transport/ip/http-client.ts | 31 ++++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 28f87ec..7858311 100644 --- a/README.md +++ b/README.md @@ -273,6 +273,10 @@ Please feel free to open an [issue](https://github.com/Apollon77/hap-controller- For Issues please consider to directly provide debug loggins (see above). ## Changelog + +### __WORK IN PROGRESS__ +* (Apollon77) Return response body for getCharacteristics and subscribe/unsubscribe also when return code was 207 in IP mode + ### 0.9.0 (2023-01-09) * (Apollon77) BREAKING: Returned data objects partially contain BigInt values (represented by bignumber.js instances) for iid/aid fields! diff --git a/src/transport/ip/http-client.ts b/src/transport/ip/http-client.ts index 180a13b..8e177da 100644 --- a/src/transport/ip/http-client.ts +++ b/src/transport/ip/http-client.ts @@ -608,7 +608,7 @@ export default class HttpClient extends EventEmitter { * in form ["aid.iid", ...] * @returns {Promise} Promise */ - async subscribeCharacteristics(characteristics: string[]): Promise { + async subscribeCharacteristics(characteristics: string[]): Promise | null> { let connection: HttpConnection; if (this.subscriptionsUseSameConnection) { connection = await this.getDefaultVerifiedConnection(); @@ -693,7 +693,20 @@ export default class HttpClient extends EventEmitter { ); } this.subscribedCharacteristics = this.subscribedCharacteristics.concat(newSubscriptions); + + let body = {}; + try { + if (response.body) { + body = JSONBig.parse(response.body.toString()); + } + } catch (err) { + // ignore + } + + return body; } + + return null; } /** @@ -704,9 +717,9 @@ export default class HttpClient extends EventEmitter { * if ommited all currently subscribed characteristics will be unsubscribed * @returns {Promise} Promise which resolves when the procedure is done. */ - async unsubscribeCharacteristics(characteristics?: string[]): Promise { + async unsubscribeCharacteristics(characteristics?: string[]): Promise | null> { if (!this.subscriptionConnection || !this.subscribedCharacteristics.length) { - return; + return null; } if (!characteristics) { @@ -760,7 +773,19 @@ export default class HttpClient extends EventEmitter { this.subscriptionConnection?.removeAllListeners('event'); delete this.subscriptionConnection; } + + let body = {}; + try { + if (response.body) { + body = JSONBig.parse(response.body.toString()); + } + } catch (err) { + // ignore + } + + return body; } + return null; } /**