diff --git a/package.json b/package.json index ce2ccb3..c56fba0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "displayName": "Homebridge UniFi Occupancy", "name": "homebridge-unifi-occupancy", - "version": "1.2.1", + "version": "1.2.2", "description": "Homebridge plugin that adds HomeKit occupancy sensors for for selected (types of) devices on a UniFi network to your iOS Home app.", "license": "Apache-2.0", "repository": { diff --git a/src/platform.ts b/src/platform.ts index e1f1781..a35e673 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -41,9 +41,11 @@ export class UnifiOccupancyPlatform implements DynamicPlatformPlugin { public readonly config: PlatformConfig, public readonly api: API, ) { - this.api.on('didFinishLaunching', () => { - this.setDefaultConfig(); + if (!this.parseConfig()) { + return; + } + this.api.on('didFinishLaunching', () => { this.connect(); this.loadDeviceFingerprints() @@ -54,7 +56,12 @@ export class UnifiOccupancyPlatform implements DynamicPlatformPlugin { }); } - setDefaultConfig() { + parseConfig(): boolean { + if (!this.config.unifi) { + this.log.error('ERROR: UniFi Controller is not configured.'); + return false; + } + this.config.interval ||= 180; this.config.showAsOwner ||= 'smartphone'; this.config.deviceType ||= {}; @@ -104,6 +111,8 @@ export class UnifiOccupancyPlatform implements DynamicPlatformPlugin { ), ]; this.clientRules = this.config.clientRules.map(raw => new ClientRule(this, raw)); + + return true; } connect() {