Shelly: make optional user and password configurable (#1600)

This commit is contained in:
Markus Thierolf 2021-09-20 13:10:19 +02:00 • committed by GitHub
parent 6c97801523
commit 327cf49ec6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,7 +3,7 @@ package charger
import (
"errors"
"fmt"
"strings"
"net/url"
"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/util"
@ -41,6 +41,8 @@ func init() {
func NewShellyFromConfig(other map[string]interface{}) (api.Charger, error) {
cc := struct {
URI string
User string
Password string
Channel int
StandbyPower float64
}{}
@ -53,14 +55,19 @@ func NewShellyFromConfig(other map[string]interface{}) (api.Charger, error) {
return nil, errors.New("missing uri")
}
return NewShelly(cc.URI, cc.Channel, cc.StandbyPower)
return NewShelly(cc.URI, cc.User, cc.Password, cc.Channel, cc.StandbyPower)
}
// NewShelly creates Shelly charger
func NewShelly(uri string, channel int, standbypower float64) (*Shelly, error) {
func NewShelly(uri, user, password string, channel int, standbypower float64) (*Shelly, error) {
u, _ := url.Parse(uri)
if u.Host != "" {
uri = u.Host
}
c := &Shelly{
Helper: request.NewHelper(util.NewLogger("shelly")),
uri: strings.TrimRight(uri, "/"),
uri: fmt.Sprintf("http://%s:%s@%s", user, password, uri),
channel: channel,
standbypower: standbypower,
}