publish charged energy and duration
()
| 1775 | |
| 1776 | // publish charged energy and duration |
| 1777 | func (lp *Loadpoint) publishChargeProgress() { |
| 1778 | if f, err := lp.chargeRater.ChargedEnergy(); err == nil { |
| 1779 | // workaround for Go-E resetting during disconnect, see |
| 1780 | // https://github.com/evcc-io/evcc/issues/5092 |
| 1781 | if f > lp.chargedAtStartup { |
| 1782 | added, addedGreen := lp.energyMetrics.Update(f - lp.chargedAtStartup) |
| 1783 | if added > 0 { |
| 1784 | lp.log.DEBUG.Printf("session energy: %.3fkWh", f) |
| 1785 | } |
| 1786 | |
| 1787 | if telemetry.Enabled() && added > 0 { |
| 1788 | telemetry.UpdateEnergy(added, addedGreen) |
| 1789 | } |
| 1790 | } |
| 1791 | } else if !errors.Is(err, api.ErrNotAvailable) { |
| 1792 | lp.log.ERROR.Printf("charge rater: %v", err) |
| 1793 | } |
| 1794 | |
| 1795 | if d, err := lp.chargeTimer.ChargeDuration(); err == nil { |
| 1796 | lp.chargeDuration = d.Round(time.Second) |
| 1797 | } else if !errors.Is(err, api.ErrNotAvailable) { |
| 1798 | lp.log.ERROR.Printf("charge timer: %v", err) |
| 1799 | } |
| 1800 | |
| 1801 | // TODO check if "session" prefix required? |
| 1802 | lp.energyMetrics.Publish("session", lp) |
| 1803 | |
| 1804 | // TODO deprecated: use sessionEnergy instead |
| 1805 | lp.publish(keys.ChargedEnergy, lp.GetChargedEnergy()) |
| 1806 | lp.publish(keys.ChargeDuration, lp.chargeDuration) |
| 1807 | |
| 1808 | // update energy, prefer totals |
| 1809 | var importTotal *float64 |
| 1810 | if api.HasCap[api.MeterEnergy](lp.chargeMeter) { |
| 1811 | if f := lp.chargeMeterTotal(); f > 0 { |
| 1812 | lp.publish(keys.ChargeTotalImport, f) |
| 1813 | importTotal = &f |
| 1814 | } |
| 1815 | } |
| 1816 | |
| 1817 | if lp.chargeEnergy != nil { |
| 1818 | lp.chargeEnergy.AddEnergy(importTotal, nil, lp.chargePower) |
| 1819 | if v := lp.GetSoc(); v > 0 { |
| 1820 | lp.chargeEnergy.SetSocTemp(v, lp.chargerHasFeature(api.Heating)) |
| 1821 | } |
| 1822 | } |
| 1823 | } |
| 1824 | |
| 1825 | // publish state of charge, remaining charge duration and range |
| 1826 | // |
no test coverage detected