Skip to content

Commit

Permalink
Fix invalid charge duration displayed when status changed before char…
Browse files Browse the repository at this point in the history
…ge started
  • Loading branch information
andig committed Jul 16, 2020
1 parent e34167c commit 0f02f6f
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 55 deletions.
6 changes: 4 additions & 2 deletions assets/index.html
Expand Up @@ -244,14 +244,16 @@ <h2>
<div class="col-6 col-md-2 my-4">
<div class="mb-2">Dauer</div>
<h2>
{{fmtShortDuration(state.chargeDuration)}}
{{fmtShortDuration(state.chargeDuration)}} <small
class="text-muted">{{fmtShortDurationUnit(state.chargeDuration)}}</small>
</h2>
</div>

<div class="col-6 col-md-2 my-4">
<div class="mb-2">Restzeit</div>
<h2>
{{fmtShortDuration(state.chargeEstimate)}}
{{fmtShortDuration(state.chargeEstimate)}} <small
class="text-muted">{{fmtShortDurationUnit(state.chargeEstimate)}}</small>
</h2>
</div>
</div>
Expand Down
14 changes: 12 additions & 2 deletions assets/js/app.js
Expand Up @@ -55,13 +55,23 @@ let formatter = {
var tm;
if (hours >= 1) {
minutes = "0" + minutes;
tm = hours + ":" + minutes.substr(-2) + "h";
tm = hours + ":" + minutes.substr(-2);
} else {
var seconds = "0" + (d % 60);
tm = minutes + ":" + seconds.substr(-2) + "m";
tm = minutes + ":" + seconds.substr(-2);
}
return tm;
},
fmtShortDurationUnit: function (d) {
if (d <= 0 || d == null) {
return '';
}
var hours = Math.floor(d / 3600);
if (hours >= 1) {
return "h";
}
return "m";
},
}
}

Expand Down
7 changes: 5 additions & 2 deletions core/loadpoint.go
Expand Up @@ -265,8 +265,11 @@ func (lp *LoadPoint) updateChargeStatus() error {
lp.log.INFO.Println("start charging ->")
lp.bus.Publish(evChargeStart)
} else {
lp.log.INFO.Println("stop charging <-")
lp.bus.Publish(evChargeStop)
// omit initial stop event before started
if prevStatus != api.StatusNone {
lp.log.INFO.Println("stop charging <-")
lp.bus.Publish(evChargeStop)
}
}
}

Expand Down
99 changes: 50 additions & 49 deletions server/assets.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0f02f6f

Please sign in to comment.