Skip to content

Commit

Permalink
feat(mqtt): added time and area information to mqtt attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
docBliny authored May 20, 2020
1 parent 4c181ae commit 9eaf848
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/MqttClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class MqttClient {
this.last_ha_state = HA_STATES.IDLE;
this.last_state = "UNKNOWN";
this.last_attributes = {};
this.last_cleaned_area = 0;
this.last_cleaning_time = 0;

this.loadConfig();
if (this.enabled) {
Expand Down Expand Up @@ -264,6 +266,8 @@ class MqttClient {
updateAttributesTopicOnEvent(statusData) {
this.last_ha_state = HA_STATE_MAPPINGS[statusData.state];
this.last_state = statusData.state;
this.last_cleaned_area = statusData.clean_area ? parseFloat((statusData.clean_area / 1000000).toFixed(2)) : 0;
this.last_cleaning_time = statusData.clean_time ? parseFloat((statusData.clean_time / 60).toFixed(1)) : 0;

this.updateAttributesTopic();
}
Expand All @@ -290,6 +294,8 @@ class MqttClient {
response.cleanTime = round(cleanSummary.cleanTime, 1);
response.cleanArea = round(cleanSummary.cleanArea, 1);
response.cleanCount = cleanSummary.cleanCount;
response.lastCleanedArea = this.last_cleaned_area;
response.lastCleaningTime = this.last_cleaning_time;
let last_runs = cleanSummary.lastRuns;
if (last_runs.length > 0) {
try {
Expand Down Expand Up @@ -341,6 +347,8 @@ class MqttClient {
response.state = HA_STATE_MAPPINGS[statusData.state];
response.battery_level = statusData.battery;
response.fan_speed = statusData.fan_power;
response.cleaned_area = statusData.clean_area ? (statusData.clean_area / 1000000).toFixed(1) : 0;
response.cleaning_time = statusData.clean_time ? (statusData.clean_time / 60).toFixed(1) : 0;

if (statusData.error_code !== undefined && statusData.error_code !== 0) {
response.error = statusData.human_error;
Expand Down

0 comments on commit 9eaf848

Please sign in to comment.