Skip to content

Commit

Permalink
Updated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
NorthernMan54 committed Nov 7, 2024
1 parent 4202cc2 commit 455ad5a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to `@homebridge/hap-client` will be documented in this file. This project tries to adhere to [Semantic Versioning](http://semver.org/).

## v2.0.4 (2024-11-07)

### Changed

- Added public method destroy, to be used for testing
- Update public method monitorCharacteristics to allow passing of a filtered services array.

## v2.0.2 (2024-08-31)

### Changed
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@homebridge/hap-client",
"version": "2.0.2",
"version": "2.0.4",
"description": "A client for HAP-NodeJS.",
"main": "./dist/index.js",
"scripts": {
Expand Down Expand Up @@ -55,4 +55,4 @@
"ts-node": "^10.9.2",
"typescript": "^5.5.4"
}
}
}
26 changes: 22 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export class HapClient extends EventEmitter {
Characteristics.Name,
];

private resetInstancePoolTimeout: NodeJS.Timeout | undefined = undefined
private startDiscoveryTimeout: NodeJS.Timeout | undefined = undefined

constructor(opts: {
pin: string;
logger?: any;
Expand Down Expand Up @@ -66,7 +69,7 @@ export class HapClient extends EventEmitter {

this.instances = [];

setTimeout(() => {
this.resetInstancePoolTimeout = setTimeout(() => {
this.refreshInstances();
}, 6000);
}
Expand Down Expand Up @@ -94,7 +97,7 @@ export class HapClient extends EventEmitter {
this.debug(`[HapClient] Discovery :: Started`);

// stop discovery after 20 seconds
setTimeout(() => {
this.startDiscoveryTimeout = setTimeout(() => {
this.browser.stop();
this.debug(`[HapClient] Discovery :: Ended`);
this.discoveryInProgress = false;
Expand Down Expand Up @@ -225,8 +228,9 @@ export class HapClient extends EventEmitter {
return accessories;
}

public async monitorCharacteristics() {
const services = await this.getAllServices();
public async monitorCharacteristics(services?: ServiceType[]) {
// If `services` is not provided, retrieve all services
services = services ?? await this.getAllServices();
return new HapMonitor(this.logger, this.debug.bind(this), this.pin, services);
}

Expand Down Expand Up @@ -447,4 +451,18 @@ export class HapClient extends EventEmitter {
return titleize(decamelize(string));
}

/**
* Destroy the HapClient instance, used for testing
*/
public destroy() {
this.browser?.stop()
this.discoveryInProgress = false
if (this.resetInstancePoolTimeout) {
clearTimeout(this.resetInstancePoolTimeout)
}
if (this.startDiscoveryTimeout) {
clearTimeout(this.startDiscoveryTimeout)
}
}

}

0 comments on commit 455ad5a

Please sign in to comment.