Skip to content
Snippets Groups Projects
Commit f23dfab3 authored by KERDREUX Jerome's avatar KERDREUX Jerome
Browse files

Refactoring

parent 4afbc623
No related branches found
No related tags found
No related merge requests found
...@@ -74,7 +74,7 @@ func (gw *Gateway) MQTTHandler(client mqtt.Client, msg mqtt.Message) { ...@@ -74,7 +74,7 @@ func (gw *Gateway) MQTTHandler(client mqtt.Client, msg mqtt.Message) {
gw.Z2MParseDevices(msg) gw.Z2MParseDevices(msg)
} else { } else {
zDev := gw.GetZDeviceByTopic(msg.Topic()) zDev := gw.GetZDeviceByTopic(msg.Topic())
// mqttDumpMsg(msg) // MQTTDumpMsg(msg)
if zDev != nil { if zDev != nil {
zDev.HandleMessage(msg) zDev.HandleMessage(msg)
} }
......
...@@ -4,10 +4,8 @@ import ( ...@@ -4,10 +4,8 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"log/slog" "log/slog"
"sort"
mqtt "github.com/eclipse/paho.mqtt.golang" mqtt "github.com/eclipse/paho.mqtt.golang"
"github.com/jedib0t/go-pretty/v6/table"
) )
// MQTTSetup creates a new MQTT client // MQTTSetup creates a new MQTT client
...@@ -36,21 +34,5 @@ func MQTTDumpMsg(msg mqtt.Message) { ...@@ -36,21 +34,5 @@ func MQTTDumpMsg(msg mqtt.Message) {
if err != nil { if err != nil {
slog.Error("Error decoding JSON %v", "topic", msg.Topic(), "err", err) slog.Error("Error decoding JSON %v", "topic", msg.Topic(), "err", err)
} }
jsonDump(data)
// sort keys
keys := make([]string, 0, len(data))
for key := range data {
keys = append(keys, key)
}
sort.Strings(keys)
// dump keys
tab := table.NewWriter()
tab.SetTitle("MQTT update")
tab.SetStyle(table.StyleRounded)
for _, key := range keys {
if key != "update" {
tab.AppendRow(table.Row{key, data[key]})
}
}
fmt.Println(tab.Render())
} }
...@@ -3,8 +3,10 @@ package main ...@@ -3,8 +3,10 @@ package main
import ( import (
"fmt" "fmt"
"math" "math"
"sort"
"strconv" "strconv"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/lucasb-eyer/go-colorful" "github.com/lucasb-eyer/go-colorful"
) )
...@@ -22,6 +24,25 @@ func hexStringToInteger(hexString string) (uint64, error) { ...@@ -22,6 +24,25 @@ func hexStringToInteger(hexString string) (uint64, error) {
return integerValue, nil return integerValue, nil
} }
func jsonDump(data map[string]interface{}) {
// sort keys
keys := make([]string, 0)
for key := range data {
keys = append(keys, key)
}
sort.Strings(keys)
// dump keys
tab := table.NewWriter()
tab.SetTitle("MQTT update")
tab.SetStyle(table.StyleRounded)
for _, key := range keys {
if key != "update" {
tab.AppendRow(table.Row{key, data[key]})
}
}
fmt.Println(tab.Render())
}
// xyToColor converts CIE XY color coordinates and brightness to an RGB color using the go-colorful library. // xyToColor converts CIE XY color coordinates and brightness to an RGB color using the go-colorful library.
// https://github.com/Koenkk/zigbee2mqtt/issues/3497 // https://github.com/Koenkk/zigbee2mqtt/issues/3497
func xyToColor(x, y, brightness float64) colorful.Color { func xyToColor(x, y, brightness float64) colorful.Color {
......
...@@ -503,4 +503,5 @@ func NewDebugDevice(addr uuid.UUID, zDev *Z2MDevice, exp *Expose) XAALDeviceInte ...@@ -503,4 +503,5 @@ func NewDebugDevice(addr uuid.UUID, zDev *Z2MDevice, exp *Expose) XAALDeviceInte
func (dev *DebugDevice) update(payload map[string]interface{}) { func (dev *DebugDevice) update(payload map[string]interface{}) {
slog.Info("Debug Device update", "payload", payload) slog.Info("Debug Device update", "payload", payload)
jsonDump(payload)
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment