-
-
Notifications
You must be signed in to change notification settings - Fork 534
/
helper.go
53 lines (44 loc) · 1.62 KB
/
helper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package core
import (
"time"
"github.com/cenkalti/backoff/v4"
"github.com/evcc-io/evcc/util"
)
var (
status = map[bool]string{false: "disable", true: "enable"}
presence = map[bool]string{false: "✗", true: "✓"}
// Voltage global value
Voltage float64
)
// bo returns an exponential backoff for reading meter power quickly
func bo() *backoff.ExponentialBackOff {
bo := backoff.NewExponentialBackOff()
bo.MaxElapsedTime = time.Second
return bo
}
// powerToCurrent is a helper function to convert power to per-phase current
func powerToCurrent(power float64, phases int) float64 {
if Voltage == 0 {
panic("Voltage is not set")
}
return power / (float64(phases) * Voltage)
}
// currentToPower is a helper function to convert current to sum power
func currentToPower(current float64, phases int) float64 {
if Voltage == 0 {
panic("Voltage is not set")
}
return current * float64(phases) * Voltage
}
// sitePower returns the available delta power that the charger might additionally consume
// negative value: available power (grid export), positive value: grid import
func sitePower(log *util.Logger, maxGrid, grid, battery, residual float64) float64 {
// For hybrid inverters, battery can be charged from DC power in excess of
// inverter AC rating. This battery charge must not be counted as available for AC consumption.
// https://github.com/evcc-io/evcc/issues/2734, https://github.com/evcc-io/evcc/issues/2986
if maxGrid > 0 && grid > maxGrid && battery < 0 {
log.TRACE.Printf("ignoring excess DC charging due to grid consumption: %.0fW > %.0fW", grid, maxGrid)
battery = 0
}
return grid + battery + residual
}