Skip to content

Commit

Permalink
Publish current refresh interval value to new topic
Browse files Browse the repository at this point in the history
  • Loading branch information
BigThunderSR committed Mar 15, 2024
1 parent f92db44 commit 52dcfc6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,15 @@ logger.info('Starting OnStar2MQTT Polling');

let refreshInterval;
const refreshIntervalTopic = mqttHA.getRefreshIntervalTopic();
const refreshIntervalCurrentValTopic = mqttHA.getRefreshIntervalCurrentValTopic();
logger.info(`refreshIntervalTopic: ${refreshIntervalTopic}`);
logger.info(`refreshIntervalCurrentValTopic: ${refreshIntervalCurrentValTopic}`);
// Subscribe to the topic
client.subscribe(refreshIntervalTopic);
// Set initial interval
refreshInterval = setInterval(main, onstarConfig.refreshInterval);
logger.info(`Initial refreshInterval: ${onstarConfig.refreshInterval}`);
client.publish(refreshIntervalCurrentValTopic, onstarConfig.refreshInterval.toString(), { retain: true });
//client.publish(refreshIntervalTopic, onstarConfig.refreshInterval.toString(), { retain: true });

client.on('message', async (topic, message) => {
Expand All @@ -428,6 +431,7 @@ logger.info('Starting OnStar2MQTT Polling');
// Start new interval with updated refresh interval
refreshInterval = setInterval(main, newRefreshInterval);
logger.info(`Updated refreshInterval to ${newRefreshInterval}`);
client.publish(refreshIntervalCurrentValTopic, newRefreshInterval.toString(), { retain: true });
}
});

Expand Down
4 changes: 4 additions & 0 deletions src/mqtt.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ class MQTT {
return `${this.prefix}/${this.instance}/refresh_interval`;
}

getRefreshIntervalCurrentValTopic() {
return `${this.prefix}/${this.instance}/refresh_interval_current_val`;
}

/**
*
* @param {DiagnosticElement} diag
Expand Down

0 comments on commit 52dcfc6

Please sign in to comment.