Mqtt: marshal solar forecast as JSON (#24810)
This commit is contained in:
parent
245615121c
commit
667978db3e
3 changed files with 11 additions and 2 deletions
|
|
@ -47,7 +47,7 @@ func (rr Rates) At(ts time.Time) (Rate, error) {
|
||||||
return Rate{}, ErrNotAvailable
|
return Rate{}, ErrNotAvailable
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ BytesMarshaler = Rates{}
|
var _ BytesMarshaler = (*Rates)(nil)
|
||||||
|
|
||||||
// MarshalBytes implements server.BytesMarshaler
|
// MarshalBytes implements server.BytesMarshaler
|
||||||
func (r Rates) MarshalBytes() ([]byte, error) {
|
func (r Rates) MarshalBytes() ([]byte, error) {
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ type solarDetails struct {
|
||||||
Today dailyDetails `json:"today,omitempty"` // tomorrow
|
Today dailyDetails `json:"today,omitempty"` // tomorrow
|
||||||
Tomorrow dailyDetails `json:"tomorrow,omitempty"` // tomorrow
|
Tomorrow dailyDetails `json:"tomorrow,omitempty"` // tomorrow
|
||||||
DayAfterTomorrow dailyDetails `json:"dayAfterTomorrow,omitempty"` // day after 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 {
|
type dailyDetails struct {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"slices"
|
"slices"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -8,6 +9,14 @@ import (
|
||||||
"github.com/samber/lo"
|
"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 {
|
type tsEntry struct {
|
||||||
Timestamp time.Time `json:"ts"`
|
Timestamp time.Time `json:"ts"`
|
||||||
Value float64 `json:"val"`
|
Value float64 `json:"val"`
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue