forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhomematic.go
72 lines (57 loc) · 1.75 KB
/
homematic.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
64
65
66
67
68
69
70
71
72
package charger
import (
"time"
"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/meter/homematic"
"github.com/evcc-io/evcc/util"
)
// Homematic CCU charger implementation
type CCU struct {
conn *homematic.Connection
*switchSocket
}
func init() {
registry.Add("homematic", NewCCUFromConfig)
}
// NewCCUFromConfig creates a Homematic charger from generic config
func NewCCUFromConfig(other map[string]interface{}) (api.Charger, error) {
cc := struct {
embed `mapstructure:",squash"`
URI string
Device string
MeterChannel string
SwitchChannel string
User string
Password string
StandbyPower float64
Cache time.Duration
}{
Cache: time.Second,
}
if err := util.DecodeOther(other, &cc); err != nil {
return nil, err
}
return NewCCU(cc.embed, cc.URI, cc.Device, cc.MeterChannel, cc.SwitchChannel, cc.User, cc.Password, cc.StandbyPower, cc.Cache)
}
// NewCCU creates a new connection with standbypower for charger
func NewCCU(embed embed, uri, deviceid, meterid, switchid, user, password string, standbypower float64, cache time.Duration) (*CCU, error) {
conn, err := homematic.NewConnection(uri, deviceid, meterid, switchid, user, password, cache)
c := &CCU{
conn: conn,
}
c.switchSocket = NewSwitchSocket(&embed, c.Enabled, c.conn.CurrentPower, standbypower)
return c, err
}
// Enabled implements the api.Charger interface
func (c *CCU) Enabled() (bool, error) {
return c.conn.Enabled()
}
// Enable implements the api.Charger interface
func (c *CCU) Enable(enable bool) error {
return c.conn.Enable(enable)
}
var _ api.MeterEnergy = (*CCU)(nil)
// TotalEnergy implements the api.MeterEnergy interface
func (c *CCU) TotalEnergy() (float64, error) {
return c.conn.TotalEnergy()
}