add new parameter hasChild and set with connection id

This commit is contained in:
Adrian Zürcher
2025-05-28 22:04:40 +02:00
parent 60b3f77e29
commit c57c22f93a
5 changed files with 62 additions and 27 deletions

View File

@@ -1,10 +1,12 @@
package dbm
import (
"fmt"
json_dataModels "github.com/tecamino/tecamino-json_data/models"
)
func (d *DBMHandler) Set(req *json_dataModels.Request) {
func (d *DBMHandler) Set(req *json_dataModels.Request, id string) {
if req == nil {
return
} else if len(req.Set) == 0 {
@@ -13,9 +15,28 @@ func (d *DBMHandler) Set(req *json_dataModels.Request) {
d.RLock()
defer d.RUnlock()
resp := json_dataModels.NewResponse()
resp.Id = req.Id
for _, set := range req.Set {
for _, dp := range d.DBM.QueryDatapoints(1, set.Uuid, set.Path) {
dps := d.DBM.QueryDatapoints(1, set.Uuid, set.Path)
if len(dps) == 0 {
resp.SetError()
if resp.Message == "" {
resp.SetMessage(fmt.Sprintf("datapoint %s not found", set.Path))
}
continue
}
for _, dp := range dps {
dp.UpdateValue(d.Conns, set.Value)
resp.AddSet(json_dataModels.Set{
Uuid: dp.Uuid,
Path: dp.Path,
Value: dp.Value,
})
}
}
if err := d.Conns.SendResponse(id, resp); err != nil {
d.Log.Error("get.Set", err.Error())
}
}