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,6 +1,8 @@
package dbm
import (
"fmt"
json_dataModels "github.com/tecamino/tecamino-json_data/models"
)
@@ -18,7 +20,17 @@ func (d *DBMHandler) Subscribe(req *json_dataModels.Request, id string) {
resp.Id = req.Id
for _, sub := range req.Subscribe {
for _, dp := range d.DBM.QueryDatapoints(sub.Depth, sub.Uuid, sub.Path) {
dps := d.DBM.QueryDatapoints(sub.Depth, sub.Uuid, sub.Path)
if len(dps) == 0 {
resp.SetError()
if resp.Message == "" {
resp.SetMessage(fmt.Sprintf("datapoint %s not found", sub.Path))
}
continue
}
for _, dp := range dps {
if sub.Driver != "" {
if dp.Drivers == nil || dp.Drivers[sub.Driver] == nil {
continue
@@ -26,11 +38,12 @@ func (d *DBMHandler) Subscribe(req *json_dataModels.Request, id string) {
}
dp.AddSubscribtion(id, sub)
resp.AddSubscription(json_dataModels.Subscription{
Uuid: dp.Uuid,
Path: dp.Path,
Value: dp.Value,
Driver: sub.Driver,
Drivers: &dp.Drivers,
Uuid: dp.Uuid,
Path: dp.Path,
Value: dp.Value,
HasChild: dp.Datapoints != nil,
Driver: sub.Driver,
Drivers: &dp.Drivers,
})
}
}