Tibber: pass more descriptive user agent when connecting (#20841)
Some checks failed
Some checks failed
This commit is contained in:
parent
c35a62cd94
commit
8fb8efb16b
2 changed files with 27 additions and 2 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue