@@ -10,15 +10,22 @@ import { HsdPlatformConfig } from './config';
1010export class HsdPlatform implements DynamicPlatformPlugin {
1111 private cachedAccessories : Map < string , HsdPlatformAccessory > = new Map ( ) ;
1212 private hsdAccessories : Map < string , HsdAccessory > = new Map ( ) ;
13- private config : HsdPlatformConfig ;
13+ private config : HsdPlatformConfig = {
14+ hsIp : '' ,
15+ hsUserName : '' ,
16+ hsUserPw : '' ,
17+ hsPort : 0 ,
18+ accessories : [ ] , // Assuming you have an array of HsdAccessoryConfig objects
19+ platform : '' ,
20+ } ;
1421
1522 private async connect ( ) : Promise < HomeServerConnector > {
1623 const link = HomeServerConnector . getInstance ( this . api , this . logger , this . hsdAccessories ) ;
1724 link . connect ( this . config . hsIp , this . config . hsPort , this . config . hsUserName , this . config . hsUserPw ) ;
1825 this . logger . info ( `hsdPlatform.ts | HsdPlatform | HSD IP gateway ${ this . config . hsIp } connection established.` ) ;
1926
2027 this . api . on ( APIEvent . SHUTDOWN , async ( ) => {
21- await link . disconnect ( ) ;
28+ link . disconnect ( ) ;
2229 this . logger . warn ( `hsdPlatform.ts | HsdPlatform | hsd IP gateway ${ this . config . hsdIp } connection closed.` ) ;
2330 } ) ;
2431
@@ -27,10 +34,11 @@ export class HsdPlatform implements DynamicPlatformPlugin {
2734
2835 public constructor ( private logger : Logging , config : PlatformConfig , private api : API ) {
2936 this . logger . debug ( 'hsdPlatform.ts | HsdPlatform | Constructor' ) ;
30- if ( ! isHsdPlatformConfig ( config ) ) {
31- throw new Error ( 'hsdPlatform.ts | HsdPlatform | Invalid configuration' ) ;
32- } else {
37+ if ( isHsdPlatformConfig ( config ) ) {
38+
3339 this . config = config ;
40+ } else {
41+ this . logger . error ( 'hsdPlatform.ts | HsdPlatform | Invalid configuration' ) ;
3442 }
3543
3644 api . on ( APIEvent . DID_FINISH_LAUNCHING , async ( ) => {
@@ -44,9 +52,13 @@ export class HsdPlatform implements DynamicPlatformPlugin {
4452
4553 private configureAccessories ( hsd : HomeServerConnector ) : void {
4654 for ( const config of this . config . accessories ) {
47- const hsdAccessory = new HsdAccessory ( config , this . logger , hsd , this . api ) ;
48- this . hsdAccessories . set ( hsdAccessory . uuid , hsdAccessory ) ;
49- this . logger . info ( 'hsdPlatform.ts | HsdPlatform | Loaded hsd accessory' , hsdAccessory . displayName ) ;
55+ try {
56+ const hsdAccessory = new HsdAccessory ( config , this . logger , hsd , this . api ) ;
57+ this . hsdAccessories . set ( hsdAccessory . uuid , hsdAccessory ) ;
58+ this . logger . info ( 'hsdPlatform.ts | HsdPlatform | Loaded hsd accessory' , hsdAccessory . displayName ) ;
59+ } catch ( error ) {
60+ this . logger . error ( 'hsdPlatform.ts | HsdPlatform | Error loading accessory' , error ) ;
61+ }
5062 }
5163
5264 for ( const accessory of this . cachedAccessories . values ( ) ) {
@@ -61,7 +73,6 @@ export class HsdPlatform implements DynamicPlatformPlugin {
6173
6274 try {
6375 hsdAccessory . setupServices ( accessory ) ;
64-
6576 } catch ( e ) {
6677 this . api . unregisterPlatformAccessories ( PLUGIN_NAME , PLATFORM_NAME , [ accessory ] ) ;
6778 this . logger . debug ( 'hsdPlatform.ts | HsdPlatform | Unregistered hsd accessory' , accessory . displayName ) ;
0 commit comments