From 667978db3e8670bf0820e495eabce5a39a63cc48 Mon Sep 17 00:00:00 2001 From: andig Date: Tue, 28 Oct 2025 08:18:32 +0100 Subject: [PATCH] Mqtt: marshal solar forecast as JSON (#24810) --- api/rates.go | 2 +- core/site_tariffs.go | 2 +- core/solar.go | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/api/rates.go b/api/rates.go index e1682da51..66695ef83 100644 --- a/api/rates.go +++ b/api/rates.go @@ -47,7 +47,7 @@ func (rr Rates) At(ts time.Time) (Rate, error) { return Rate{}, ErrNotAvailable } -var _ BytesMarshaler = Rates{} +var _ BytesMarshaler = (*Rates)(nil) // MarshalBytes implements server.BytesMarshaler func (r Rates) MarshalBytes() ([]byte, error) { diff --git a/core/site_tariffs.go b/core/site_tariffs.go index fb92a8667..0bd2d247b 100644 --- a/core/site_tariffs.go +++ b/core/site_tariffs.go @@ -20,7 +20,7 @@ type solarDetails struct { Today dailyDetails `json:"today,omitempty"` // tomorrow Tomorrow dailyDetails `json:"tomorrow,omitempty"` // tomorrow DayAfterTomorrow dailyDetails `json:"dayAfterTomorrow,omitempty"` // day after tomorrow - Timeseries []tsEntry `json:"timeseries,omitempty"` // timeseries of forecasted energy + Timeseries timeseries `json:"timeseries,omitempty"` // timeseries of forecasted energy } type dailyDetails struct { diff --git a/core/solar.go b/core/solar.go index 38f959c60..b409c4111 100644 --- a/core/solar.go +++ b/core/solar.go @@ -1,6 +1,7 @@ package core import ( + "encoding/json" "slices" "time" @@ -8,6 +9,14 @@ import ( "github.com/samber/lo" ) +type timeseries []tsEntry + +var _ api.BytesMarshaler = (*timeseries)(nil) + +func (ts timeseries) MarshalBytes() ([]byte, error) { + return json.Marshal(ts) +} + type tsEntry struct { Timestamp time.Time `json:"ts"` Value float64 `json:"val"`