Skip to content

Commit

Permalink
* (Apollon77) Return response body for getCharacteristics and subscri…
Browse files Browse the repository at this point in the history
…be/unsubscribe also when return code was 207 in IP mode
  • Loading branch information
Apollon77 committed Jan 10, 2023
1 parent c7c171a commit d474e28
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand Down
31 changes: 28 additions & 3 deletions src/transport/ip/http-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ export default class HttpClient extends EventEmitter {
* in form ["aid.iid", ...]
* @returns {Promise} Promise
*/
async subscribeCharacteristics(characteristics: string[]): Promise<void> {
async subscribeCharacteristics(characteristics: string[]): Promise<Record<string, unknown> | null> {
let connection: HttpConnection;
if (this.subscriptionsUseSameConnection) {
connection = await this.getDefaultVerifiedConnection();
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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<void> {
async unsubscribeCharacteristics(characteristics?: string[]): Promise<Record<any, unknown> | null> {
if (!this.subscriptionConnection || !this.subscribedCharacteristics.length) {
return;
return null;
}

if (!characteristics) {
Expand Down Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit d474e28

Please sign in to comment.