File tree 3 files changed +17
-3
lines changed
3 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ All notable changes to `@homebridge/hap-client` will be documented in this file.
11
11
- Added new setCharacteristic option, setCharacteristicByType which allows finding the characteristic by type.
12
12
- Added new getResource request to retrieve snapshot images from camera's
13
13
- Minor tweak to serviceName, and if the name is blank, use the name value from Accessory Information
14
+ - Fixed issue of error handler triggering error when contacting a homebridge instance that is down
15
+ - Added restart of monitor when client connections close
14
16
15
17
## v2.0.4 (2024-11-07)
16
18
Original file line number Diff line number Diff line change @@ -470,7 +470,7 @@ export class HapClient extends EventEmitter {
470
470
if ( this . logger ) {
471
471
this . logger . error ( `[HapClient] [${ service . instance . ipAddress } :${ service . instance . port } (${ service . instance . username } )] ` +
472
472
`Failed to set value for ${ service . serviceName } .` ) ;
473
- if ( e . response && e . response . status === 470 || e . response . status === 401 ) {
473
+ if ( e . response && e . response ? .status === 470 || e . response ? .status === 401 ) {
474
474
this . logger . warn ( `[HapClient] [${ service . instance . ipAddress } :${ service . instance . port } (${ service . instance . username } )] ` +
475
475
`Make sure Homebridge pin for this instance is set to ${ this . pin } .` ) ;
476
476
throw new Error ( `Failed to control accessory. Make sure the Homebridge pin for ${ service . instance . ipAddress } :${ service . instance . port } ` +
@@ -514,7 +514,7 @@ export class HapClient extends EventEmitter {
514
514
if ( this . logger ) {
515
515
this . logger . error ( `[HapClient] [${ service . instance . ipAddress } :${ service . instance . port } (${ service . instance . username } )] ` +
516
516
`Failed to request resource from accessory ${ service . serviceName } .` ) ;
517
- if ( e . response && e . response . status === 470 || e . response . status === 401 ) {
517
+ if ( e . response && e . response ? .status === 470 || e . response ? .status === 401 ) {
518
518
this . logger . warn ( `[HapClient] [${ service . instance . ipAddress } :${ service . instance . port } (${ service . instance . username } )] ` +
519
519
`Make sure Homebridge pin for this instance is set to ${ this . pin } .` ) ;
520
520
throw new Error ( `Failed to request resource from accessory. Make sure the Homebridge pin for ${ service . instance . ipAddress } :${ service . instance . port } ` +
Original file line number Diff line number Diff line change 1
1
import { EventEmitter } from 'node:events' ;
2
2
3
- import { ServiceType , HapEvInstance } from './interfaces' ;
4
3
import { createConnection , parseMessage } from './eventedHttpClient' ;
4
+ import { HapEvInstance , ServiceType } from './interfaces' ;
5
5
6
6
/**
7
7
* HapMonitor - Creates a monitor to watch for changes in accessory characteristics. And generates 'service-update' events when they change.
@@ -76,6 +76,18 @@ export class HapMonitor extends EventEmitter {
76
76
}
77
77
}
78
78
} ) ;
79
+ let closeTimeout : NodeJS . Timeout | null = null ;
80
+ instance . socket . on ( 'close' , ( data ) => {
81
+ this . emit ( 'monitor-close' , data ) ;
82
+ if ( closeTimeout ) {
83
+ clearTimeout ( closeTimeout ) ; // Clear the existing timeout
84
+ }
85
+ closeTimeout = setTimeout ( ( ) => {
86
+ this . finish ( ) ;
87
+ this . start ( ) ;
88
+ closeTimeout = null ; // Reset the timeout
89
+ } , 10000 ) ; // 10-second debounce period
90
+ } ) ;
79
91
}
80
92
}
81
93
You can’t perform that action at this time.
0 commit comments