From 07dbb5f30f42dcf6d902bf6a9148b2023114529a Mon Sep 17 00:00:00 2001 From: Jasper Seinhorst Date: Sun, 24 Mar 2024 16:41:14 +0100 Subject: [PATCH] feat: add config for username and password --- config.schema.json | 14 ++++++++++++++ package-lock.json | 4 ++-- package.json | 2 +- src/Platform.ts | 10 +++++----- src/Utils/OmnikApi.ts | 21 +++++++++++++-------- 5 files changed, 35 insertions(+), 16 deletions(-) diff --git a/config.schema.json b/config.schema.json index 84860ca..89b7654 100644 --- a/config.schema.json +++ b/config.schema.json @@ -11,6 +11,20 @@ "required": true, "default": "" }, + "username": { + "title": "Inverter username", + "type": "string", + "required": true, + "default": "admin", + "description": "The username is likely admin, unless it has been modified by the installer." + }, + "password": { + "title": "Inverter password", + "type": "string", + "required": true, + "default": "admin", + "description": "The password is likely admin, unless it has been modified by the installer." + }, "pollInterval": { "title": "Poll interval (in minutes)", "type": "number", diff --git a/package-lock.json b/package-lock.json index eb5fda4..83a8e45 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "homebridge-omnik", - "version": "1.1.0", + "version": "1.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "homebridge-omnik", - "version": "1.1.0", + "version": "1.2.0", "license": "Apache-2.0", "dependencies": { "axios": "^1.6.7" diff --git a/package.json b/package.json index 07850c2..938dcbe 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "homebridge-omnik", "displayName": "Omnik Inverter", - "version": "1.1.0", + "version": "1.2.0", "description": "Add your Omnik-Inverter to Homekit", "license": "Apache-2.0", "author": "Jasper Seinhorst", diff --git a/src/Platform.ts b/src/Platform.ts index 78846ab..f64052f 100644 --- a/src/Platform.ts +++ b/src/Platform.ts @@ -27,19 +27,19 @@ export class OmnikPlugin implements DynamicPlatformPlugin { } private validateConfig(): boolean { - return !!this.config.ip; + return !!this.config.ip && !!this.config.username && !!this.config.password; } private async initialise() { if (!this.validateConfig()) { - this.log.error('Configuration error. Please provide your Omnik-inverter\'s IP address'); + this.log.error('Configuration error. Please provide your Omnik-inverter\'s IP address, username and password'); return; } - this.omnikApi = new OmnikApi(this.config.ip); + this.omnikApi = new OmnikApi(this.config.ip, this.config.username, this.config.password); if (!await this.omnikApi.ValidateIp()) { - this.log.error('Your Omnik inverter\'s IP address seems to be incorrect. No connection possible'); + this.log.error('Your Omnik inverter\'s IP address or credentials seem to be incorrect. No connection possible'); return; } @@ -100,7 +100,7 @@ export class OmnikPlugin implements DynamicPlatformPlugin { }); } catch (error) { - this.log.error('Failed to update data, no connection possible with your inverter'); + this.log.error('Failed to update data'); } } } diff --git a/src/Utils/OmnikApi.ts b/src/Utils/OmnikApi.ts index 7a2d2f0..a3ba8b2 100644 --- a/src/Utils/OmnikApi.ts +++ b/src/Utils/OmnikApi.ts @@ -3,10 +3,15 @@ import { PowerProduction, OmnikDevice } from '../PlatformTypes'; export default class OmnikApi { private ip: string; - private timeout: 5000; + private username: string; + private password: string; - constructor(ip: string) { + private timeout: 10000; + + constructor(ip: string, username: string, password: string) { this.ip = ip; + this.username = username; + this.password = password; } private SplitStatusData(statusData: string): string[] { @@ -19,8 +24,8 @@ export default class OmnikApi { { timeout: this.timeout, auth: { - username: 'admin', - password: 'admin', + username: this.username, + password: this.password, }, }, ); @@ -37,8 +42,8 @@ export default class OmnikApi { { timeout: this.timeout, auth: { - username: 'admin', - password: 'admin', + username: this.username, + password: this.password, }, }, ); @@ -61,8 +66,8 @@ export default class OmnikApi { { timeout: this.timeout, auth: { - username: 'admin', - password: 'admin', + username: this.username, + password: this.password, }, }, );