Tibber: pass more descriptive user agent when connecting (#20841)
Some checks failed
Release / call-build-workflow (push) Has been cancelled
Release / Publish Docker :release (push) Has been cancelled
Release / Github & APT (push) Has been cancelled
Release / Demo (push) Has been cancelled
Release / Hassio Addon (push) Has been cancelled

This commit is contained in:
Toni Juvani 2025-04-24 23:28:31 +03:00 • committed by GitHub
parent c35a62cd94
commit 8fb8efb16b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 2 deletions

View file

@ -2,7 +2,7 @@
// README at: https://github.com/devcontainers/templates/tree/main/src/go
{
"name": "evcc",
"image": "mcr.microsoft.com/devcontainers/go:1-1.23-bookworm",
"image": "mcr.microsoft.com/devcontainers/go:1-1.24-bookworm",
"features": {
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {
"moby": true,

View file

@ -3,7 +3,9 @@ package meter
import (
"context"
"encoding/json"
"fmt"
"net/http"
"runtime/debug"
"strings"
"time"
@ -19,6 +21,29 @@ func init() {
registry.AddCtx("tibber-pulse", NewTibberFromConfig)
}
func getUserAgent() string {
evccVersion := "0.203.2+unknown"
graphqlClientVersion := "0.13.2+unknown"
if info, ok := debug.ReadBuildInfo(); ok {
evccVersion = baseVersion(info.Main.Version)
for _, dep := range info.Deps {
if dep.Path == "github.com/hasura/go-graphql-client" {
graphqlClientVersion = baseVersion(dep.Version)
}
}
}
return fmt.Sprintf("evcc/%s hasura/go-graphql-client/%s", evccVersion, graphqlClientVersion)
}
func baseVersion(v string) string {
if i := strings.IndexAny(v, "-+"); i != -1 {
return v[:i]
}
return v
}
type Tibber struct {
data *util.Monitor[tibber.LiveMeasurement]
}
@ -78,7 +103,7 @@ func NewTibberFromConfig(ctx context.Context, other map[string]interface{}) (api
Transport: &transport.Decorator{
Base: http.DefaultTransport,
Decorator: transport.DecorateHeaders(map[string]string{
"User-Agent": "go-graphql-client/0.9.0",
"User-Agent": getUserAgent(),
}),
},
},