Mqtt: marshal solar forecast as JSON (#24810)

This commit is contained in:
andig 2025-10-28 08:18:32 +01:00 • committed by GitHub
parent 245615121c
commit 667978db3e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 2 deletions

View file

@ -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) {

View file

@ -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 {

View file

@ -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"`