Compare commits

..

4 Commits

Author SHA1 Message Date
ac0c417a48 small j for float 3
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2026-03-06 20:34:21 +01:00
dc965aeba6 small j for float 2
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2026-03-06 20:27:28 +01:00
b940f715c0 small j for float
Some checks failed
ci/woodpecker/tag/woodpecker Pipeline failed
2026-03-06 20:25:04 +01:00
8c5626942f fix config 3
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2026-03-06 12:30:04 +01:00
2 changed files with 134 additions and 136 deletions

View File

@@ -213,7 +213,7 @@
"attributes": {
"application": "Shellies Sensor Power",
"deviceSelector": "T:2",
"valueSelector": "J:$.percent",
"valueSelector": "J:$.battery.percent",
"unitSelector": "C:%"
}
}

View File

@@ -1,16 +1,17 @@
package svej
import (
"encoding/json"
"fmt"
"log"
"time"
"strconv"
"strings"
"fmt"
"github.com/oliveagle/jsonpath"
"encoding/json"
"time"
"udi/config"
"udi/handlers/handler"
"udi/database"
"udi/handlers/handler"
"github.com/oliveagle/jsonpath"
)
type SingleValueExtractorJsonpathHandler struct {
@@ -33,7 +34,6 @@ T:TopicPartIndex
C:ConstantValue
*/
func New(id string, config config.HandlerConfigT) handler.Handler {
t := &SingleValueExtractorJsonpathHandler{
ready: false,
@@ -76,12 +76,12 @@ func New(id string, config config.HandlerConfigT) handler.Handler {
t.Id = id
t.ready = true
t.dbh = database.NewDatabaseHandle()
log.Printf("Handler SVEJ %d initialized", id)
log.Printf("Handler SVEJ %s initialized", id)
return t
}
func (self *SingleValueExtractorJsonpathHandler) ExtractionHelper(subTopics []string, jPayload interface{}, selector string, jp *jsonpath.Compiled) (string, error) {
var res string
func (self *SingleValueExtractorJsonpathHandler) ExtractionHelper(subTopics []string, jPayload interface{}, selector string, jp *jsonpath.Compiled) (interface{}, error) {
var res interface{}
switch selector[:2] {
case "J:":
// extract using jsonpath from payload
@@ -89,7 +89,7 @@ func (self *SingleValueExtractorJsonpathHandler) ExtractionHelper(subTopics []st
if e != nil {
return "", fmt.Errorf("jp.Lookup failed with %s", e)
}
res = fmt.Sprint(r)
res = r
case "T:":
// T: extract from topic
i, e := strconv.Atoi(selector[2:])
@@ -109,7 +109,6 @@ func (self *SingleValueExtractorJsonpathHandler) ExtractionHelper(subTopics []st
return res, nil
}
func (self *SingleValueExtractorJsonpathHandler) Handle(message handler.MessageT) {
if !self.ready {
self.Lost("Handler is not marked as ready", nil, message)
@@ -149,12 +148,12 @@ func (self *SingleValueExtractorJsonpathHandler) Handle(message handler.MessageT
return
}
measurement.Device = device
measurement.Device = device.(string)
var variable database.VariableType
variable.Label = ""
variable.Variable = ""
variable.Unit = unit
variable.Unit = unit.(string)
variable.Value = value
measurement.Values = make(map[string]database.VariableType)
measurement.Values["Value"] = variable
@@ -163,4 +162,3 @@ func (self *SingleValueExtractorJsonpathHandler) Handle(message handler.MessageT
self.dbh.StoreMeasurement(&measurement)
self.S()
}