Skip to content

Commit 5d04bc4

Browse files
committed
Working on exception caused by wrong config
1 parent 2d0fbb2 commit 5d04bc4

4 files changed

Lines changed: 28 additions & 13 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "homebridge-hsd",
33
"displayName": "Homebridge Gira Homeserver URL-Endpoint",
4-
"version": "1.1.5",
4+
"version": "1.1.6",
55
"description": "Plugin to access KNX bus via Gira Homeserver",
66
"license": "MIT",
77
"keywords": [

src/hsdAccessory.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ class HsdAccessory {
6363
public setupServices (accessory: HsdPlatformAccessory): void {
6464
for (const service of accessory.context.services) {
6565
this.logger.info('Set up service', accessory.context.accessoryName, service.serviceName);
66-
6766
switch (service.serviceType) {
68-
6967
case 'GarageDoorOpener':
7068
this.services.push(new GarageDoorOpener(this.api, this.hsd, accessory, service));
7169
break;

src/hsdPlatform.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,22 @@ import { HsdPlatformConfig } from './config';
1010
export 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);

src/hsdPlatformAccessory.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,11 @@ import { HsdAccessoryConfig, HsdPlatformConfig } from './config';
44
export type HsdPlatformAccessory = PlatformAccessory<HsdAccessoryConfig>;
55

66
export const isHsdPlatformConfig = (config: PlatformConfig): config is HsdPlatformConfig => {
7-
return 'hsIp' in config;
7+
let isConfig = true;
8+
isConfig = isConfig && 'hsIp' in config;
9+
isConfig = isConfig && 'hsUserName' in config;
10+
isConfig = isConfig && 'hsUserPw' in config;
11+
isConfig = isConfig && 'hsPort' in config;
12+
13+
return isConfig;
814
};

0 commit comments

Comments
 (0)