Skip to content

Commit be66f8d

Browse files
committed
fix -1 battery display
1 parent 7e837ca commit be66f8d

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

app/javascript/components/reading.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ class Reading {
4747
const values = response.readings.map(x => x[1]);
4848
const validTimestamps = [];
4949
this.dataTree = new BTree();
50-
this.data = values.map((value, i) => {
51-
if(value >= 0) {
52-
const timestamp = timestamps[i];
53-
this.dataTree.set(timestamp, value);
54-
validTimestamps.push(timestamp);
55-
return { value: value, time: timestamp };
56-
}
50+
this.data = values.filter((value) => {
51+
return value >= 0
52+
}).map((value, i) => {
53+
const timestamp = timestamps[i];
54+
this.dataTree.set(timestamp, value);
55+
validTimestamps.push(timestamp);
56+
return { value: value, time: timestamp };
5757
});
5858
this.minTimestamp = Math.min(...validTimestamps);
5959
this.maxTimestamp = Math.max(...validTimestamps);
@@ -148,7 +148,7 @@ class Reading {
148148
this.valueElement.innerHTML = value.toFixed(2);
149149
} else {
150150
this.dateElement.innerHTML = ""
151-
this.valueElement.innerHTML = "-.--";
151+
this.valueElement.innerHTML = "--";
152152
}
153153
}
154154
}

app/views/ui/shared/_reading.html.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
<div class="col-12 col-md-6 col-lg-2 text-md-end text-lg-start">
3939
<% if component.last_reading_at %>
4040
<div class="big-number mt-1">
41-
<span class="trend d-none"><% case component.trend %><% when 1 %><% when -1 %><% else %><strong>=</strong><% end %></span> <span class="value"><%= component.latest_value&.round(2) %></span><span class="unit"><%= component.value_unit %></span>
41+
<span class="trend d-none"><% case component.trend %><% when 1 %><% when -1 %><% else %><strong>=</strong><% end %></span> <span class="value">
42+
<%= component.latest_value >= 0 ? component.latest_value&.round(2) : "--" %></span><span class="unit"><%= component.latest_value >= 0 ? component.value_unit : "" %></span>
4243
</div>
4344
<% end %>
4445
</div>

0 commit comments

Comments
 (0)