From 006f604c3fd7e6782d6054252b2b29e090f3a1fa Mon Sep 17 00:00:00 2001 From: Martin Rinas Date: Fri, 24 Oct 2025 12:57:02 +0200 Subject: [PATCH] InfluxDB: add meter titles (#24610) --- core/site.go | 7 +++++++ server/influxdb.go | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/core/site.go b/core/site.go index 9a46cdd71..af9443e25 100644 --- a/core/site.go +++ b/core/site.go @@ -62,6 +62,13 @@ type measurement struct { Controllable *bool `json:"controllable,omitempty"` } +var _ api.TitleDescriber = (*measurement)(nil) + +// GetTitle implements api.TitleDescriber interface for InfluxDB tagging +func (m measurement) GetTitle() string { + return m.Title +} + var _ site.API = (*Site)(nil) // Site is the main configuration container. A site can host multiple loadpoints. diff --git a/server/influxdb.go b/server/influxdb.go index cd612a723..1a35be6b0 100644 --- a/server/influxdb.go +++ b/server/influxdb.go @@ -3,6 +3,7 @@ package server import ( "crypto/tls" "fmt" + "maps" "reflect" "strconv" "strings" @@ -10,6 +11,7 @@ import ( "time" "github.com/benbjohnson/clock" + "github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/core/site" "github.com/evcc-io/evcc/util" influxdb2 "github.com/influxdata/influxdb-client-go/v2" @@ -136,9 +138,20 @@ func (m *Influx) writeComplexPoint(writer pointWriter, key string, val any, tags // loop slice for i := range val.Len() { + // clone tags to prevent leakage between elements + tags := maps.Clone(tags) tags["id"] = strconv.Itoa(i + 1) - writeStruct(val.Index(i).Interface()) + + ival := val.Index(i) + // Check if element provides a title + if tp, ok := reflect.TypeAssert[api.TitleDescriber](ival); ok { + if title := tp.GetTitle(); title != "" { + tags["title"] = title + } + } + m.writeComplexPoint(writer, key, ival.Interface(), tags) } + return } return