Skip to content

Commit

Permalink
Fix push template error stopping main process
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Jul 14, 2020
1 parent e645580 commit 318107c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Vue.component('message-toast', {
$(id).toast('show');
$(id).on('hidden.bs.toast', function () {
toasts.remove(this.item);
})
}.bind(this))
},
});

Expand Down
9 changes: 6 additions & 3 deletions core/loadpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ func (lp *LoadPoint) chargeDuration() time.Duration {
d, err := lp.chargeTimer.ChargingTime()
if err != nil {
lp.log.ERROR.Printf("charge timer error: %v", err)
return 0
}
return d
}
Expand All @@ -402,6 +403,7 @@ func (lp *LoadPoint) chargedEnergy() float64 {
f, err := lp.chargeRater.ChargedEnergy()
if err != nil {
lp.log.ERROR.Printf("charge rater error: %v", err)
return 0
}
return f
}
Expand Down Expand Up @@ -458,6 +460,10 @@ func (lp *LoadPoint) Update(mode api.ChargeMode, sitePower float64) float64 {
lp.bus.Publish(evChargeCurrent, lp.handler.TargetCurrent())
lp.bus.Publish(evChargePower, lp.chargePower)

// update progress and soc before status is updated
lp.publishChargeProgress()
lp.publishSoC()

// read and publish status
if err := retry.Do(lp.updateChargeStatus, retry.Attempts(3)); err != nil {
lp.log.ERROR.Printf("charge controller error: %v", err)
Expand Down Expand Up @@ -504,8 +510,5 @@ func (lp *LoadPoint) Update(mode api.ChargeMode, sitePower float64) float64 {
lp.log.ERROR.Println(err)
}

lp.publishChargeProgress()
lp.publishSoC()

return lp.chargePower
}
3 changes: 2 additions & 1 deletion push/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ func (h *Hub) Run(events <-chan Event) {
definition, ok := h.definitions[ev.Event]
if !ok {
log.ERROR.Printf("invalid event %v", ev.Event)
break
continue
}

msg, err := h.apply(ev, definition.Msg)
if err != nil {
log.ERROR.Printf("invalid template for %s: %v", ev.Event, err)
continue
}

for _, sender := range h.sender {
Expand Down
26 changes: 13 additions & 13 deletions server/assets.go

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

3 changes: 3 additions & 0 deletions util/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ func NewCache() *Cache {

// Run adds input channel's values to cache
func (c *Cache) Run(in <-chan Param) {
log := NewLogger("cache")

for p := range in {
log.TRACE.Printf("%s: %v", p.Key, p.Val)
c.Add(p.UniqueID(), p)
}
}
Expand Down

0 comments on commit 318107c

Please sign in to comment.