Viessmann: discover installation id and gateway serial (#32308)
This commit is contained in:
parent
f70a33e466
commit
3c75a65651
8 changed files with 305 additions and 54 deletions
|
|
@ -1,50 +0,0 @@
|
|||
package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"dario.cat/mergo"
|
||||
"github.com/evcc-io/evcc/util"
|
||||
"github.com/evcc-io/evcc/util/request"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
const OAuthURI = "https://iam.viessmann-climatesolutions.com/idp/v3"
|
||||
|
||||
var oauthConfig = oauth2.Config{
|
||||
Endpoint: oauth2.Endpoint{
|
||||
AuthURL: OAuthURI + "/authorize",
|
||||
TokenURL: OAuthURI + "/token",
|
||||
AuthStyle: oauth2.AuthStyleInHeader,
|
||||
},
|
||||
Scopes: []string{"IoT User", "offline_access"},
|
||||
}
|
||||
|
||||
func init() {
|
||||
registry.AddCtx("viessmann", NewViessmannFromConfig)
|
||||
}
|
||||
|
||||
func NewViessmannFromConfig(ctx context.Context, other map[string]any) (oauth2.TokenSource, error) {
|
||||
var cc struct {
|
||||
ClientID string
|
||||
RedirectURI string
|
||||
Gateway string `mapstructure:"gateway_serial"`
|
||||
}
|
||||
|
||||
if err := util.DecodeOther(other, &cc); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log := util.NewLogger("viessmann").Redact(cc.ClientID)
|
||||
ctx = context.WithValue(ctx, oauth2.HTTPClient, request.NewClient(log))
|
||||
|
||||
oc := oauth2.Config{
|
||||
ClientID: cc.ClientID,
|
||||
RedirectURL: cc.RedirectURI,
|
||||
}
|
||||
if err := mergo.Merge(&oc, oauthConfig); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return NewOAuth(ctx, "Viessmann", cc.Gateway, &oc)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue