Skip to content

Commit 07dbb5f

Browse files
feat: add config for username and password
1 parent 617045a commit 07dbb5f

File tree

5 files changed

+35
-16
lines changed

5 files changed

+35
-16
lines changed

config.schema.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@
1111
"required": true,
1212
"default": ""
1313
},
14+
"username": {
15+
"title": "Inverter username",
16+
"type": "string",
17+
"required": true,
18+
"default": "admin",
19+
"description": "The username is likely admin, unless it has been modified by the installer."
20+
},
21+
"password": {
22+
"title": "Inverter password",
23+
"type": "string",
24+
"required": true,
25+
"default": "admin",
26+
"description": "The password is likely admin, unless it has been modified by the installer."
27+
},
1428
"pollInterval": {
1529
"title": "Poll interval (in minutes)",
1630
"type": "number",

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "homebridge-omnik",
33
"displayName": "Omnik Inverter",
4-
"version": "1.1.0",
4+
"version": "1.2.0",
55
"description": "Add your Omnik-Inverter to Homekit",
66
"license": "Apache-2.0",
77
"author": "Jasper Seinhorst",

src/Platform.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ export class OmnikPlugin implements DynamicPlatformPlugin {
2727
}
2828

2929
private validateConfig(): boolean {
30-
return !!this.config.ip;
30+
return !!this.config.ip && !!this.config.username && !!this.config.password;
3131
}
3232

3333
private async initialise() {
3434
if (!this.validateConfig()) {
35-
this.log.error('Configuration error. Please provide your Omnik-inverter\'s IP address');
35+
this.log.error('Configuration error. Please provide your Omnik-inverter\'s IP address, username and password');
3636
return;
3737
}
3838

39-
this.omnikApi = new OmnikApi(this.config.ip);
39+
this.omnikApi = new OmnikApi(this.config.ip, this.config.username, this.config.password);
4040

4141
if (!await this.omnikApi.ValidateIp()) {
42-
this.log.error('Your Omnik inverter\'s IP address seems to be incorrect. No connection possible');
42+
this.log.error('Your Omnik inverter\'s IP address or credentials seem to be incorrect. No connection possible');
4343
return;
4444
}
4545

@@ -100,7 +100,7 @@ export class OmnikPlugin implements DynamicPlatformPlugin {
100100
});
101101

102102
} catch (error) {
103-
this.log.error('Failed to update data, no connection possible with your inverter');
103+
this.log.error('Failed to update data');
104104
}
105105
}
106106
}

src/Utils/OmnikApi.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@ import { PowerProduction, OmnikDevice } from '../PlatformTypes';
33

44
export default class OmnikApi {
55
private ip: string;
6-
private timeout: 5000;
6+
private username: string;
7+
private password: string;
78

8-
constructor(ip: string) {
9+
private timeout: 10000;
10+
11+
constructor(ip: string, username: string, password: string) {
912
this.ip = ip;
13+
this.username = username;
14+
this.password = password;
1015
}
1116

1217
private SplitStatusData(statusData: string): string[] {
@@ -19,8 +24,8 @@ export default class OmnikApi {
1924
{
2025
timeout: this.timeout,
2126
auth: {
22-
username: 'admin',
23-
password: 'admin',
27+
username: this.username,
28+
password: this.password,
2429
},
2530
},
2631
);
@@ -37,8 +42,8 @@ export default class OmnikApi {
3742
{
3843
timeout: this.timeout,
3944
auth: {
40-
username: 'admin',
41-
password: 'admin',
45+
username: this.username,
46+
password: this.password,
4247
},
4348
},
4449
);
@@ -61,8 +66,8 @@ export default class OmnikApi {
6166
{
6267
timeout: this.timeout,
6368
auth: {
64-
username: 'admin',
65-
password: 'admin',
69+
username: this.username,
70+
password: this.password,
6671
},
6772
},
6873
);

0 commit comments

Comments
 (0)