forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhomewizard.go
63 lines (49 loc) · 1.29 KB
/
homewizard.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
54
55
56
57
58
59
60
61
62
63
package meter
import (
"time"
"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/meter/homewizard"
"github.com/evcc-io/evcc/util"
)
// HomeWizard meter implementation
type HomeWizard struct {
conn *homewizard.Connection
}
// HomeWizard meter implementation
func init() {
registry.Add("homewizard", NewHomeWizardFromConfig)
}
// NewHomeWizardFromConfig creates a HomeWizard meter from generic config
func NewHomeWizardFromConfig(other map[string]interface{}) (api.Meter, error) {
cc := struct {
URI string
Cache time.Duration
}{
Cache: time.Second,
}
if err := util.DecodeOther(other, &cc); err != nil {
return nil, err
}
return NewHomeWizard(cc.URI, cc.Cache)
}
// NewHomeWizard creates HomeWizard meter
func NewHomeWizard(uri string, cache time.Duration) (*HomeWizard, error) {
conn, err := homewizard.NewConnection(uri, cache)
if err != nil {
return nil, err
}
c := &HomeWizard{
conn: conn,
}
return c, nil
}
var _ api.Meter = (*HomeWizard)(nil)
// CurrentPower implements the api.Meter interface
func (c *HomeWizard) CurrentPower() (float64, error) {
return c.conn.CurrentPower()
}
var _ api.MeterEnergy = (*HomeWizard)(nil)
// TotalEnergy implements the api.MeterEnergy interface
func (c *HomeWizard) TotalEnergy() (float64, error) {
return c.conn.TotalEnergy()
}