Compare commits

..

6 Commits
0.3.3 ... 0.3.9

Author SHA1 Message Date
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
6d0dc12ac1 fix config 2
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2026-03-06 11:28:28 +01:00
6a4aac4140 fix config
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2026-03-06 11:24:02 +01:00
77d23e39cf add new shellies 2
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2026-03-04 23:27:48 +01:00
2 changed files with 158 additions and 142 deletions

View File

@@ -183,23 +183,37 @@
"config": {
"databaseConnStr": "",
"attributes": {
"application": "Temperature Shellies",
"deviceSelector": "T:1",
"valueSelector": "J:$.tC",
"application": "Shellies Sensor Temperature",
"deviceSelector": "T:2",
"valueSelector": "j:$.tC",
"unitSelector": "C:°C"
}
}
},
{
"topics": [ "shellies/sensor+/status/humidity:0" ],
"topics": [ "shellies/sensor/+/status/humidity:0" ],
"handler": "SVEJ",
"id": "SVEJ5",
"config": {
"databaseConnStr": "",
"attributes": {
"application": "Humidity Shellies",
"deviceSelector": "T:1",
"valueSelector": "J:$.rh",
"application": "Shellies Sensor Humidity",
"deviceSelector": "T:2",
"valueSelector": "j:$.rh",
"unitSelector": "C:%"
}
}
},
{
"topics": [ "shellies/sensor/+/status/devicepower:0" ],
"handler": "SVEJ",
"id": "SVEJ6",
"config": {
"databaseConnStr": "",
"attributes": {
"application": "Shellies Sensor Power",
"deviceSelector": "T:2",
"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,
@@ -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:" {
if t.deviceSelector[:2] == "J:" || 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:" {
if t.valueSelector[:2] == "J:" || 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:" {
if t.unitSelector[:2] == "J:" || 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)
@@ -76,20 +76,24 @@ 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:":
case "J:", "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)
}
case "T:":
// T: extract from topic
i, e := strconv.Atoi(selector[2:])
@@ -109,7 +113,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 +152,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 +166,3 @@ func (self *SingleValueExtractorJsonpathHandler) Handle(message handler.MessageT
self.dbh.StoreMeasurement(&measurement)
self.S()
}