Merge pull request #154 from andig/feature/currents
Allow reading currents
This commit is contained in:
commit
4fa42e3a37
3 changed files with 23 additions and 0 deletions
|
|
@ -37,6 +37,11 @@ type MeterEnergy interface {
|
|||
TotalEnergy() (float64, error)
|
||||
}
|
||||
|
||||
// MeterCurrent is able to provide per-line current A
|
||||
type MeterCurrent interface {
|
||||
Currents() (float64, float64, float64, error)
|
||||
}
|
||||
|
||||
// Charger is able to provide current charging status and to enable/disabler charging
|
||||
type Charger interface {
|
||||
Status() (ChargeStatus, error)
|
||||
|
|
|
|||
|
|
@ -139,3 +139,13 @@ func (c *GoE) ChargedEnergy() (float64, error) {
|
|||
energy := float64(status.Dws) / 3.6e6
|
||||
return energy, err
|
||||
}
|
||||
|
||||
// Currents implements the MeterCurrent interface
|
||||
func (c *GoE) Currents() (float64, float64, float64, error) {
|
||||
var status goeStatusResponse
|
||||
_, err := c.GetJSON(c.apiURL(goeStatus), &status)
|
||||
if len(status.Nrg) == 16 {
|
||||
return float64(status.Nrg[4]) / 10, float64(status.Nrg[5]) / 10, float64(status.Nrg[6]) / 10, nil
|
||||
}
|
||||
return 0, 0, 0, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,14 @@ func dumpAPIs(v interface{}) {
|
|||
}
|
||||
}
|
||||
|
||||
if v, ok := v.(api.MeterCurrent); ok {
|
||||
if i1, i2, i3, err := v.Currents(); err != nil {
|
||||
fmt.Printf("Current L1..L3: %v\n", err)
|
||||
} else {
|
||||
fmt.Printf("Current L1..L3: %.1fA %.1fA %.1fA\n", i1, i2, i3)
|
||||
}
|
||||
}
|
||||
|
||||
if v, ok := v.(api.ChargeRater); ok {
|
||||
if energy, err := v.ChargedEnergy(); err != nil {
|
||||
fmt.Printf("Charged: %v\n", err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue