chore: minor

This commit is contained in:
andig 2026-08-11 09:54:34 +02:00
parent dc143a6dc7
commit 6fdb83fc14
10 changed files with 24 additions and 29 deletions

View file

@ -79,7 +79,7 @@ type Go struct {
type ModbusProxy struct { type ModbusProxy struct {
Port int `json:"port"` Port int `json:"port"`
ReadOnly string `yaml:",omitempty" json:"readonly,omitempty"` ReadOnly string `yaml:",omitempty" json:"readonly,omitempty"`
modbus.Settings `mapstructure:",squash" yaml:",inline,omitempty" json:"settings,omitempty"` modbus.Settings `mapstructure:",squash" yaml:",inline,omitempty" json:"settings"`
} }
var _ api.Redactor = (*Hems)(nil) var _ api.Redactor = (*Hems)(nil)

View file

@ -2,6 +2,7 @@ package prioritizer
import ( import (
"fmt" "fmt"
"strings"
"sync" "sync"
"github.com/evcc-io/evcc/api" "github.com/evcc-io/evcc/api"
@ -35,18 +36,18 @@ func (p *Prioritizer) GetChargePowerFlexibility(lp loadpoint.API) float64 {
var ( var (
reduceBy float64 reduceBy float64
msg string msg strings.Builder
) )
for lp, power := range p.demand { for lp, power := range p.demand {
if lp.EffectivePriority() < prio && power > 0 { if lp.EffectivePriority() < prio && power > 0 {
reduceBy += power reduceBy += power
msg += fmt.Sprintf("%.0fW from %s at prio %d, ", power, lp.GetTitle(), lp.EffectivePriority()) msg.WriteString(fmt.Sprintf("%.0fW from %s at prio %d, ", power, lp.GetTitle(), lp.EffectivePriority()))
} }
} }
if p.log != nil && reduceBy > 0 { if p.log != nil && reduceBy > 0 {
p.log.DEBUG.Printf("lp %s at prio %d gets additional %stotal %.0fW\n", lp.GetTitle(), lp.EffectivePriority(), msg, reduceBy) p.log.DEBUG.Printf("lp %s at prio %d gets additional %stotal %.0fW\n", lp.GetTitle(), lp.EffectivePriority(), msg.String(), reduceBy)
} }
return reduceBy return reduceBy

View file

@ -26,11 +26,11 @@ func (s forecastSeries) MarshalBytes() ([]byte, error) {
} }
type solarDetails struct { type solarDetails struct {
Scale float64 `json:"scale"` // scale factor yield/forecasted today, 1 if unscaled Scale float64 `json:"scale"` // scale factor yield/forecasted today, 1 if unscaled
Today dailyDetails `json:"today,omitempty"` // tomorrow Today dailyDetails `json:"today"` // tomorrow
Tomorrow dailyDetails `json:"tomorrow,omitempty"` // tomorrow Tomorrow dailyDetails `json:"tomorrow"` // tomorrow
DayAfterTomorrow dailyDetails `json:"dayAfterTomorrow,omitempty"` // day after tomorrow DayAfterTomorrow dailyDetails `json:"dayAfterTomorrow"` // day after tomorrow
Timeseries timeseries `json:"timeseries,omitempty"` // timeseries of forecasted energy Timeseries timeseries `json:"timeseries,omitempty"` // timeseries of forecasted energy
} }
var _ api.BytesMarshaler = (*solarDetails)(nil) var _ api.BytesMarshaler = (*solarDetails)(nil)

View file

@ -2,6 +2,7 @@ package messenger
import ( import (
"fmt" "fmt"
"maps"
"reflect" "reflect"
"strings" "strings"
"text/template" "text/template"
@ -105,9 +106,7 @@ func (h *Hub) apply(ev Event, tmpl string) (string, error) {
} }
// event-specific attributes override cache values // event-specific attributes override cache values
for k, v := range ev.Attributes { maps.Copy(attr, ev.Attributes)
attr[k] = v
}
return util.ReplaceFormatted(tmpl, attr) return util.ReplaceFormatted(tmpl, attr)
} }

View file

@ -247,8 +247,7 @@ func assertReadings(t *testing.T, m api.Meter) {
func TestDsmrTCP(t *testing.T) { func TestDsmrTCP(t *testing.T) {
addr := serveTCP(t, dsmrFrame(dsmrTelegram50)) addr := serveTCP(t, dsmrFrame(dsmrTelegram50))
ctx, cancel := context.WithCancel(context.Background()) ctx := t.Context()
defer cancel()
m, err := NewDsmr(ctx, addr, time.Second) m, err := NewDsmr(ctx, addr, time.Second)
require.NoError(t, err) require.NoError(t, err)
@ -285,8 +284,7 @@ func TestDsmrWebSocket(t *testing.T) {
uri := "ws" + strings.TrimPrefix(srv.URL, "http") uri := "ws" + strings.TrimPrefix(srv.URL, "http")
ctx, cancel := context.WithCancel(context.Background()) ctx := t.Context()
defer cancel()
m, err := NewDsmr(ctx, uri, time.Second) m, err := NewDsmr(ctx, uri, time.Second)
require.NoError(t, err) require.NoError(t, err)
@ -307,8 +305,7 @@ func TestDsmrIgnoresGarbage(t *testing.T) {
addr := serveTCP(t, payload) addr := serveTCP(t, payload)
ctx, cancel := context.WithCancel(context.Background()) ctx := t.Context()
defer cancel()
m, err := NewDsmr(ctx, addr, time.Second) m, err := NewDsmr(ctx, addr, time.Second)
require.NoError(t, err) require.NoError(t, err)
@ -398,8 +395,7 @@ func newTestDsmr(frame map[string]string) *Dsmr {
func TestDsmrADN(t *testing.T) { func TestDsmrADN(t *testing.T) {
addr := serveTCP(t, dsmrFrame(dsmrTelegramADN)) addr := serveTCP(t, dsmrFrame(dsmrTelegramADN))
ctx, cancel := context.WithCancel(context.Background()) ctx := t.Context()
defer cancel()
m, err := NewDsmr(ctx, addr, time.Second) m, err := NewDsmr(ctx, addr, time.Second)
require.NoError(t, err) require.NoError(t, err)
@ -445,8 +441,7 @@ func TestDsmrADN(t *testing.T) {
func TestDsmrExport(t *testing.T) { func TestDsmrExport(t *testing.T) {
addr := serveTCP(t, dsmrFrame(dsmrTelegramExport)) addr := serveTCP(t, dsmrFrame(dsmrTelegramExport))
ctx, cancel := context.WithCancel(context.Background()) ctx := t.Context()
defer cancel()
m, err := NewDsmr(ctx, addr, time.Second) m, err := NewDsmr(ctx, addr, time.Second)
require.NoError(t, err) require.NoError(t, err)

View file

@ -202,7 +202,7 @@ func NewStatusMap(a, b, c string) (StatusMap, error) {
{api.StatusB, b}, {api.StatusB, b},
{api.StatusC, c}, {api.StatusC, c},
} { } {
for _, s := range strings.Split(e.states, ",") { for s := range strings.SplitSeq(e.states, ",") {
if s = strings.ToLower(strings.TrimSpace(s)); s != "" { if s = strings.ToLower(strings.TrimSpace(s)); s != "" {
if status, ok := res[s]; ok { if status, ok := res[s]; ok {
return nil, fmt.Errorf("status %s: duplicate state '%s', already mapped to %s", e.status, s, status) return nil, fmt.Errorf("status %s: duplicate state '%s', already mapped to %s", e.status, s, status)

View file

@ -45,7 +45,7 @@ func TestTraceBudget(t *testing.T) {
log.Write([]byte(s2)) log.Write([]byte(s2))
for i := range 100 { for i := range 100 {
log.Write([]byte(fmt.Sprintf("[mqtt ] TRACE send %d", i))) log.Write(fmt.Appendf(nil, "[mqtt ] TRACE send %d", i))
} }
assert.Equal(t, []string{s2}, log.All(nil, jww.LevelDebug, 0)) assert.Equal(t, []string{s2}, log.All(nil, jww.LevelDebug, 0))

View file

@ -137,7 +137,7 @@ func redactToken(token string) string {
type Status struct { type Status struct {
Name string `json:"name"` Name string `json:"name"`
ExpiresAt time.Time `json:"expiresAt,omitempty"` ExpiresAt time.Time `json:"expiresAt"`
ExpiresSoon bool `json:"expiresSoon,omitempty"` ExpiresSoon bool `json:"expiresSoon,omitempty"`
Token string `json:"token,omitempty"` Token string `json:"token,omitempty"`
} }

View file

@ -38,7 +38,7 @@ func checkPulsares() (string, error) {
_ = f.Close() _ = f.Close()
}) })
var token string var token strings.Builder
b := make([]byte, 512) b := make([]byte, 512)
for { for {
@ -47,9 +47,9 @@ func checkPulsares() (string, error) {
return "", nil return "", nil
} }
token += string(b[:n]) token.WriteString(string(b[:n]))
if token, ok := strings.CutSuffix(token, "\x04"); ok { if token, ok := strings.CutSuffix(token.String(), "\x04"); ok {
return token, nil return token, nil
} }
} }

View file

@ -327,7 +327,7 @@ func (p Param) MarshalJSON() ([]byte, error) {
// Product contains naming information about a product a template supports // Product contains naming information about a product a template supports
type Product struct { type Product struct {
Brand string // product brand Brand string // product brand
Description TextLanguage `json:",omitempty"` // product name Description TextLanguage // product name
Capabilities []Capability `json:",omitempty"` // appended to template-level capabilities Capabilities []Capability `json:",omitempty"` // appended to template-level capabilities
} }