Skip to content

Commit

Permalink
Merge pull request #27 from bourquep/main
Browse files Browse the repository at this point in the history
feat: Added local_api_shared configuration option.
  • Loading branch information
chasenicholl authored Oct 24, 2024
2 parents 9c5c9db + 1b5add1 commit 94a6848
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
"required": true,
"default": true
},
"local_api_shared": {
"title": "Share the Local API UDP port with other processes",
"type": "boolean",
"required": false,
"default": false
},
"token": {
"title": "Token",
"type": "string",
Expand Down
8 changes: 7 additions & 1 deletion src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ export class WeatherFlowTempestPlatform implements DynamicPlatformPlugin {
this.log.info('local_api config parameter not set defaulting to false.');
}

// Backwards compatible config check for new local_api_shared variable
if (!('local_api_shared' in this.config)) {
this.config['local_api_shared'] = false;
this.log.info('local_api_shared config parameter not set defaulting to false.');
}

// For new install with local_api === true (Local API), token and station_id will be undefined and are not required

// For local_api === false (HTTP API), make sure token is provided
Expand Down Expand Up @@ -112,7 +118,7 @@ export class WeatherFlowTempestPlatform implements DynamicPlatformPlugin {

try {
this.log.info('Using Tempest Local API.');
this.tempestSocket = new TempestSocket(this.log);
this.tempestSocket = new TempestSocket(this.log, this.config.local_api_shared);
this.tempestSocket.start();

// Hold thread for first message and set values
Expand Down
4 changes: 2 additions & 2 deletions src/tempest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ export class TempestSocket {
private data: object | undefined;
private tempest_battery_level: number;

constructor(log: Logger) {
constructor(log: Logger, reuse_address: boolean) {

this.log = log;
this.data = undefined;
this.tempest_battery_level = 0;
this.s = dgram.createSocket('udp4');
this.s = dgram.createSocket({ type: 'udp4', reuseAddr: reuse_address });

this.log.info('TempestSocket initialized.');

Expand Down

0 comments on commit 94a6848

Please sign in to comment.