Skip to content

Commit

Permalink
Mqtt: add batteryDischargeControl and smartCostLimit (#13864)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored May 11, 2024
1 parent c8b3e24 commit 5750d0d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 8 additions & 1 deletion server/mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,17 @@ func (m *MQTT) Listen(site site.API) error {

func (m *MQTT) listenSiteSetters(topic string, site site.API) error {
for _, s := range []setter{
{"/prioritySoc", floatSetter(site.SetPrioritySoc)},
{"/bufferSoc", floatSetter(site.SetBufferSoc)},
{"/bufferStartSoc", floatSetter(site.SetBufferStartSoc)},
{"/batteryDischargeControl", boolSetter(site.SetBatteryDischargeControl)},
{"/prioritySoc", floatSetter(site.SetPrioritySoc)},
{"/residualPower", floatSetter(site.SetResidualPower)},
{"/smartCostLimit", floatSetter(func(limit float64) error {
for _, lp := range site.Loadpoints() {
lp.SetSmartCostLimit(limit)
}
return nil
})},
} {
if err := m.Handler.ListenSetter(topic+s.topic, s.fun); err != nil {
return err
Expand Down
8 changes: 8 additions & 0 deletions server/mqtt_setter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package server

import (
"strconv"

"github.com/spf13/cast"
)

type setter struct {
Expand All @@ -26,3 +28,9 @@ func floatSetter(set func(float64) error) func(string) error {
func intSetter(set func(int) error) func(string) error {
return setterFunc(strconv.Atoi, set)
}

func boolSetter(set func(bool) error) func(string) error {
return setterFunc(func(v string) (bool, error) {
return cast.ToBoolE(v)
}, set)
}

1 comment on commit 5750d0d

@oskarfessel
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the prompt resolution.

Please sign in to comment.