From a0fe455bcef0ce21e43b0d15ca9718bb5a4e6584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Z=C3=BCrcher?= Date: Tue, 29 Apr 2025 17:02:59 +0200 Subject: [PATCH] fix wrong return of created datapoints --- models/datapoints.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/models/datapoints.go b/models/datapoints.go index ae42c4e..4745957 100644 --- a/models/datapoints.go +++ b/models/datapoints.go @@ -122,22 +122,23 @@ func (d *Datapoint) CreateDatapoints(conns *serverModels.Connections, sets ...js existing.Publish(conns, OnChange) } } else { - // Create new - current.Datapoints[part] = &Datapoint{ + ndp := Datapoint{ Uuid: uuid.New(), CreateDateTime: time.Now().UnixMilli(), Subscriptions: InitSubscribtion(), } - publish, err := current.Datapoints[part].Set(strings.Join(parts, ":"), dp) + // Create new + current.Datapoints[part] = &ndp + publish, err := ndp.Set(strings.Join(parts, ":"), dp) if err != nil { return nil, err } created = append(created, json_dataModels.Set{ - Uuid: current.Uuid, - Path: current.Path, - Type: current.Type, - Value: current.Value, - Rights: current.ReadWrite, + Uuid: ndp.Uuid, + Path: ndp.Path, + Type: ndp.Type, + Value: ndp.Value, + Rights: ndp.ReadWrite, Driver: dp.Driver, }) if publish { @@ -246,6 +247,13 @@ func (d *Datapoint) UpdateDatapointValue(conns *serverModels.Connections, value return nil } +func (d *Datapoint) UpdateValue(conns *serverModels.Connections, value any) error { + d.Value = d.Type.ConvertValue(value) + d.UpdateDateTime = time.Now().UnixMilli() + d.Publish(conns, OnChange) + return nil +} + func (d *Datapoint) RemoveDatapoint(conns *serverModels.Connections, set json_dataModels.Set) (json_dataModels.Set, error) { parts := strings.Split(set.Path, ":")