MCPcopy Create free account
hub / github.com/evcc-io/evcc / createSession

Method createSession

core/loadpoint_session.go:36–65  ·  view source on GitHub ↗

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.

()

Source from the content-addressed store, hash-verified

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.
36func (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.
68func (lp *Loadpoint) applyEnergyMetrics(s *session.Session) {

Callers 5

resetHeatingSessionMethod · 0.95
TestSessionFunction · 0.95
TestResetHeatingSessionFunction · 0.95

Calls 13

chargeMeterTotalMethod · 0.95
GetVehicleMethod · 0.95
chargerHasFeatureMethod · 0.95
GetTitleMethod · 0.95
publishMethod · 0.95
GetChargedEnergyMethod · 0.95
AverageRateFunction · 0.92
NewMethod · 0.65
GetTitleMethod · 0.65
IdentifyMethod · 0.65
GetTariffMethod · 0.65
ResetMethod · 0.65

Tested by 3

TestSessionFunction · 0.76
TestResetHeatingSessionFunction · 0.76