From ac0c417a4811ad18f195fc20c4d322bc7eaa3350 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Fri, 6 Mar 2026 20:34:21 +0100 Subject: [PATCH] small j for float 3 --- .../instances/udi-influx/default/config.json | 6 +++--- src/udi/handlers/svej/svej.go | 14 +++++--------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/deployment/instances/udi-influx/default/config.json b/deployment/instances/udi-influx/default/config.json index 0c25906..d774402 100644 --- a/deployment/instances/udi-influx/default/config.json +++ b/deployment/instances/udi-influx/default/config.json @@ -185,7 +185,7 @@ "attributes": { "application": "Shellies Sensor Temperature", "deviceSelector": "T:2", - "valueSelector": "j:$.tC", + "valueSelector": "J:$.tC", "unitSelector": "C:°C" } } @@ -199,7 +199,7 @@ "attributes": { "application": "Shellies Sensor Humidity", "deviceSelector": "T:2", - "valueSelector": "j:$.rh", + "valueSelector": "J:$.rh", "unitSelector": "C:%" } } @@ -213,7 +213,7 @@ "attributes": { "application": "Shellies Sensor Power", "deviceSelector": "T:2", - "valueSelector": "j:$.battery.percent", + "valueSelector": "J:$.battery.percent", "unitSelector": "C:%" } } diff --git a/src/udi/handlers/svej/svej.go b/src/udi/handlers/svej/svej.go index f3577f2..12fb6f6 100644 --- a/src/udi/handlers/svej/svej.go +++ b/src/udi/handlers/svej/svej.go @@ -46,7 +46,7 @@ func New(id string, config config.HandlerConfigT) handler.Handler { t.application = config.Attributes["application"] t.deviceSelector = config.Attributes["deviceSelector"] - if t.deviceSelector[:2] == "J:" || t.deviceSelector[:2] == "j:" { + if t.deviceSelector[:2] == "J:" { jp, err := jsonpath.Compile(t.deviceSelector[2:]) if err != nil { log.Printf("Unable to compile deviceJsonpath: %s, %s", t.deviceSelector[2:], err) @@ -55,7 +55,7 @@ func New(id string, config config.HandlerConfigT) handler.Handler { t.deviceJsonpath = jp } t.valueSelector = config.Attributes["valueSelector"] - if t.valueSelector[:2] == "J:" || t.valueSelector[:2] == "j:" { + if t.valueSelector[:2] == "J:" { jp, err := jsonpath.Compile(t.valueSelector[2:]) if err != nil { log.Printf("Unable to compile valueJsonpath: %s, %s", t.valueSelector[2:], err) @@ -64,7 +64,7 @@ func New(id string, config config.HandlerConfigT) handler.Handler { t.valueJsonpath = jp } t.unitSelector = config.Attributes["unitSelector"] - if t.unitSelector[:2] == "J:" || t.unitSelector[:2] == "j:" { + if t.unitSelector[:2] == "J:" { jp, err := jsonpath.Compile(t.unitSelector[2:]) if err != nil { log.Printf("Unable to compile unitJsonpath: %s, %s", t.unitSelector[2:], err) @@ -83,17 +83,13 @@ func New(id string, config config.HandlerConfigT) handler.Handler { func (self *SingleValueExtractorJsonpathHandler) ExtractionHelper(subTopics []string, jPayload interface{}, selector string, jp *jsonpath.Compiled) (interface{}, error) { var res interface{} switch selector[:2] { - case "J:", "j:": + case "J:": // extract using jsonpath from payload r, e := jp.Lookup(jPayload) if e != nil { return "", fmt.Errorf("jp.Lookup failed with %s", e) } - if selector[:2] == "j:" { - res = r.(float64) - } else { - res = fmt.Sprint(r) - } + res = r case "T:": // T: extract from topic i, e := strconv.Atoi(selector[2:])