Skip to content

Commit

Permalink
Log error if UniFi Controller is not configured
Browse files Browse the repository at this point in the history
  • Loading branch information
DouweM committed Feb 22, 2023
1 parent 015fb37 commit b9fe185
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
15 changes: 12 additions & 3 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 ||= {};
Expand Down Expand Up @@ -104,6 +111,8 @@ export class UnifiOccupancyPlatform implements DynamicPlatformPlugin {
),
];
this.clientRules = this.config.clientRules.map(raw => new ClientRule(this, raw));

return true;
}

connect() {
Expand Down

0 comments on commit b9fe185

Please # to comment.