Skip to content

Commit

Permalink
feat: add config for username and password
Browse files Browse the repository at this point in the history
  • Loading branch information
jasper-seinhorst committed Mar 24, 2024
1 parent 617045a commit 07dbb5f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 16 deletions.
14 changes: 14 additions & 0 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
10 changes: 5 additions & 5 deletions src/Platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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');
}
}
}
21 changes: 13 additions & 8 deletions src/Utils/OmnikApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] {
Expand All @@ -19,8 +24,8 @@ export default class OmnikApi {
{
timeout: this.timeout,
auth: {
username: 'admin',
password: 'admin',
username: this.username,
password: this.password,
},
},
);
Expand All @@ -37,8 +42,8 @@ export default class OmnikApi {
{
timeout: this.timeout,
auth: {
username: 'admin',
password: 'admin',
username: this.username,
password: this.password,
},
},
);
Expand All @@ -61,8 +66,8 @@ export default class OmnikApi {
{
timeout: this.timeout,
auth: {
username: 'admin',
password: 'admin',
username: this.username,
password: this.password,
},
},
);
Expand Down

0 comments on commit 07dbb5f

Please sign in to comment.