createSession creates a charging session. The created timestamp is empty until set by evChargeStartHandler. The session is not persisted yet. That will only happen when stopSession is called.
()
| 34 | // createSession creates a charging session. The created timestamp is empty until set by evChargeStartHandler. |
| 35 | // The session is not persisted yet. That will only happen when stopSession is called. |
| 36 | func (lp *Loadpoint) createSession() { |
| 37 | // test guard |
| 38 | if lp.db == nil || lp.session != nil { |
| 39 | return |
| 40 | } |
| 41 | |
| 42 | lp.session = lp.db.New(lp.chargeMeterTotal()) |
| 43 | |
| 44 | if v := lp.GetVehicle(); v != nil { |
| 45 | lp.session.Vehicle = v.GetTitle() |
| 46 | } else if lp.chargerHasFeature(api.IntegratedDevice) { |
| 47 | lp.session.Vehicle = lp.GetTitle() |
| 48 | } |
| 49 | |
| 50 | if c, ok := api.Cap[api.Identifier](lp.charger); ok { |
| 51 | if id, err := c.Identify(); err == nil { |
| 52 | lp.session.Identifier = id |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | if lp.site != nil { |
| 57 | lp.session.ReferencePricePerKWh = tariff.AverageRate(lp.site.GetTariff(api.TariffUsageGrid), 24*time.Hour) |
| 58 | lp.session.ReferenceCo2PerKWh = tariff.AverageRate(lp.site.GetTariff(api.TariffUsageCo2), 24*time.Hour) |
| 59 | } |
| 60 | |
| 61 | // energy |
| 62 | lp.energyMetrics.Reset() |
| 63 | lp.energyMetrics.Publish("session", lp) |
| 64 | lp.publish(keys.ChargedEnergy, lp.GetChargedEnergy()) |
| 65 | } |
| 66 | |
| 67 | // applyEnergyMetrics writes current energy metrics into the session and persists it. |
| 68 | func (lp *Loadpoint) applyEnergyMetrics(s *session.Session) { |