forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tapo.go
31 lines (25 loc) · 654 Bytes
/
tapo.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
package meter
import (
"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/meter/tapo"
"github.com/evcc-io/evcc/util"
)
// TP-Link Tapo meter implementation
func init() {
registry.Add("tapo", NewTapoFromConfig)
}
// NewTapoFromConfig creates a tapo meter from generic config
func NewTapoFromConfig(other map[string]interface{}) (api.Meter, error) {
var cc struct {
URI string
User string
Password string
}
if err := util.DecodeOther(other, &cc); err != nil {
return nil, err
}
if cc.User == "" || cc.Password == "" {
return nil, api.ErrMissingCredentials
}
return tapo.NewConnection(cc.URI, cc.User, cc.Password)
}