Skip to content

Commit

Permalink
chore: simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Dec 23, 2024
1 parent b16c3a5 commit 697f6c4
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 60 deletions.
10 changes: 5 additions & 5 deletions meter/fritzdect/fritzdect.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ func (c *Connection) ExecCmd(function string) (string, error) {
}

parameters := url.Values{
"sid": []string{c.SID},
"ain": []string{c.AIN},
"switchcmd": []string{function},
"sid": {c.SID},
"ain": {c.AIN},
"switchcmd": {function},
}

uri := fmt.Sprintf("%s/webservices/homeautoswitch.lua", c.URI)
Expand Down Expand Up @@ -156,8 +156,8 @@ func (c *Connection) getSessionID() error {
var challresp string
if challresp, err = createChallengeResponse(v.Challenge, c.Password); err == nil {
params := url.Values{
"username": []string{c.User},
"response": []string{challresp},
"username": {c.User},
"response": {challresp},
}

if body, err = c.GetBody(uri + "?" + params.Encode()); err == nil {
Expand Down
18 changes: 9 additions & 9 deletions meter/tasmota/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ func NewConnection(uri, user, password string, channels []int, cache time.Durati

c.statusSnsG = provider.ResettableCached(func() (StatusSNSResponse, error) {
parameters := url.Values{
"user": []string{c.user},
"password": []string{c.password},
"cmnd": []string{"Status 8"},
"user": {c.user},
"password": {c.password},
"cmnd": {"Status 8"},
}
var res StatusSNSResponse
err := c.GetJSON(fmt.Sprintf("%s/cm?%s", c.uri, parameters.Encode()), &res)
Expand All @@ -63,9 +63,9 @@ func NewConnection(uri, user, password string, channels []int, cache time.Durati

c.statusStsG = provider.ResettableCached(func() (StatusSTSResponse, error) {
parameters := url.Values{
"user": []string{c.user},
"password": []string{c.password},
"cmnd": []string{"Status 0"},
"user": {c.user},
"password": {c.password},
"cmnd": {"Status 0"},
}
var res StatusSTSResponse
err := c.GetJSON(fmt.Sprintf("%s/cm?%s", c.uri, parameters.Encode()), &res)
Expand Down Expand Up @@ -120,9 +120,9 @@ func (c *Connection) Enable(enable bool) error {
}

parameters := url.Values{
"user": []string{c.user},
"password": []string{c.password},
"cmnd": []string{cmd},
"user": {c.user},
"password": {c.password},
"cmnd": {cmd},
}

var res PowerResponse
Expand Down
8 changes: 4 additions & 4 deletions vehicle/bluelink/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ func (v *Identity) brandLogin(cookieClient *request.Helper, user, password strin

if err == nil {
data := url.Values{
"username": []string{user},
"password": []string{password},
"credentialId": []string{""},
"rememberMe": []string{"on"},
"username": {user},
"password": {password},
"credentialId": {""},
"rememberMe": {"on"},
}

req, err = request.New(http.MethodPost, action, strings.NewReader(data.Encode()), request.URLEncoding)
Expand Down
6 changes: 3 additions & 3 deletions vehicle/bmw/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ func (v *Identity) retrieveToken(data url.Values) (*oauth2.Token, error) {

func (v *Identity) RefreshToken(token *oauth2.Token) (*oauth2.Token, error) {
data := url.Values{
"redirect_uri": []string{RedirectURI},
"refresh_token": []string{token.RefreshToken},
"grant_type": []string{"refresh_token"},
"redirect_uri": {RedirectURI},
"refresh_token": {token.RefreshToken},
"grant_type": {"refresh_token"},
}

return v.retrieveToken(data)
Expand Down
4 changes: 2 additions & 2 deletions vehicle/mercedes/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ func (v *Identity) RefreshToken(token *oauth2.Token) (*oauth2.Token, error) {
defer v.mu.Unlock()

data := url.Values{
"grant_type": []string{"refresh_token"},
"refresh_token": []string{token.RefreshToken},
"grant_type": {"refresh_token"},
"refresh_token": {token.RefreshToken},
}

uri := fmt.Sprintf("%s/as/token.oauth2", IdUri)
Expand Down
10 changes: 5 additions & 5 deletions vehicle/mercedes/setupapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ func (vs *SetupAPI) RequestPin() (bool, *string, error) {

func (vs *SetupAPI) RequestAccessToken(nonce string, pin string) (*oauth2.Token, error) {
data := url.Values{
"client_id": []string{ClientId},
"grant_type": []string{"password"},
"password": []string{fmt.Sprintf("%s:%s", nonce, pin)},
"scope": []string{"openid email phone profile offline_access ciam-uid"},
"username": []string{vs.account},
"client_id": {ClientId},
"grant_type": {"password"},
"password": {fmt.Sprintf("%s:%s", nonce, pin)},
"scope": {"openid email phone profile offline_access ciam-uid"},
"username": {vs.account},
}

uri := fmt.Sprintf("%s/as/token.oauth2", IdUri)
Expand Down
10 changes: 5 additions & 5 deletions vehicle/niu.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ func (v *Niu) login() error {
md5hash := hex.EncodeToString(hash.Sum(nil))

data := url.Values{
"account": []string{v.user},
"password": []string{md5hash},
"grant_type": []string{"password"},
"scope": []string{"base"},
"app_id": []string{"niu_8xt1afu6"},
"account": {v.user},
"password": {md5hash},
"grant_type": {"password"},
"scope": {"base"},
"app_id": {"niu_8xt1afu6"},
}

uri := niu.AuthURI + "/v3/api/oauth2/token"
Expand Down
16 changes: 8 additions & 8 deletions vehicle/polestar/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ func (v *Identity) login() (*oauth2.Token, error) {
// Submit credentials directly to the login endpoint
loginURL := fmt.Sprintf("%s/as/%s/resume/as/authorization.ping", OAuthURI, resumePath)
data := url.Values{
"pf.username": []string{v.user},
"pf.pass": []string{v.password},
"client_id": []string{ClientID},
"pf.username": {v.user},
"pf.pass": {v.password},
"client_id": {ClientID},
}

req, _ = request.New(http.MethodPost, loginURL, strings.NewReader(data.Encode()), map[string]string{
Expand All @@ -120,11 +120,11 @@ func (v *Identity) login() (*oauth2.Token, error) {

// Exchange code for token
data = url.Values{
"grant_type": []string{"authorization_code"},
"code": []string{code},
"code_verifier": []string{cv},
"client_id": []string{ClientID},
"redirect_uri": []string{RedirectURI},
"grant_type": {"authorization_code"},
"code": {code},
"code_verifier": {cv},
"client_id": {ClientID},
"redirect_uri": {RedirectURI},
}

var token oauth2.Token
Expand Down
4 changes: 1 addition & 3 deletions vehicle/psa/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ func NewAPI(log *util.Logger, identity oauth2.TokenSource, realm, id string) *AP
}

func (v *API) clientID() string {
return url.Values{
"client_id": []string{v.id},
}.Encode()
return url.Values{"client_id": {v.id}}.Encode()
}

// Vehicles implements the /vehicles response
Expand Down
18 changes: 9 additions & 9 deletions vehicle/renault/gigya/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ func (v *Identity) Login(user, password string) error {

func (v *Identity) sessionCookie(user, password string) (string, error) {
data := url.Values{
"loginID": []string{user},
"password": []string{password},
"apiKey": []string{v.gigya.APIKey},
"loginID": {user},
"password": {password},
"apiKey": {v.gigya.APIKey},
}

var res gigyaResponse
Expand All @@ -76,8 +76,8 @@ func (v *Identity) sessionCookie(user, password string) (string, error) {

func (v *Identity) personID(sessionCookie string) (string, error) {
data := url.Values{
"apiKey": []string{v.gigya.APIKey},
"login_token": []string{sessionCookie},
"apiKey": {v.gigya.APIKey},
"login_token": {sessionCookie},
}

var res gigyaResponse
Expand All @@ -89,10 +89,10 @@ func (v *Identity) personID(sessionCookie string) (string, error) {

func (v *Identity) jwtToken(sessionCookie string) (string, error) {
data := url.Values{
"apiKey": []string{v.gigya.APIKey},
"login_token": []string{sessionCookie},
"fields": []string{"data.personId,data.gigyaDataCenter"},
"expiration": []string{"900"},
"apiKey": {v.gigya.APIKey},
"login_token": {sessionCookie},
"fields": {"data.personId,data.gigyaDataCenter"},
"expiration": {"900"},
}

var res gigyaResponse
Expand Down
4 changes: 2 additions & 2 deletions vehicle/saic/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ func (v *Identity) retrieveToken(data url.Values) (*oauth2.Token, error) {

func (v *Identity) RefreshToken(token *oauth2.Token) (*oauth2.Token, error) {
data := url.Values{
"refresh_token": []string{token.RefreshToken},
"grant_type": []string{"refresh_token"},
"refresh_token": {token.RefreshToken},
"grant_type": {"refresh_token"},
}

token, err := v.retrieveToken(data)
Expand Down
4 changes: 1 addition & 3 deletions vehicle/seat.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ func mbbUserId(log *util.Logger, ts oauth2.TokenSource, uid string) (string, err
Base: client.Transport,
}

data := url.Values{
"scopeId": []string{"commonMandatoryFields"},
}
data := url.Values{"scopeId": {"commonMandatoryFields"}}

var mandatoryConsentInfo struct {
MbbUserId string `json:"mbbUserId"`
Expand Down
4 changes: 2 additions & 2 deletions vehicle/vag/vwidentity/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func (v *Service) Login(uri, user, password string) (url.Values, error) {

// add nonce and state
query := url.Values{
"nonce": []string{lo.RandomString(43, lo.LettersCharset)},
"state": []string{uuid.NewString()},
"nonce": {lo.RandomString(43, lo.LettersCharset)},
"state": {uuid.NewString()},
}

var vars FormVars
Expand Down

0 comments on commit 697f6c4

Please sign in to comment.