diff --git a/gateway.go b/gateway.go index f44ce43c48235c75df36a794fa887428f9289c0e..82ca332f2c8e4be359ed75e6c3103dfdeeca8d68 100644 --- a/gateway.go +++ b/gateway.go @@ -74,7 +74,7 @@ func (gw *Gateway) MQTTHandler(client mqtt.Client, msg mqtt.Message) { gw.Z2MParseDevices(msg) } else { zDev := gw.GetZDeviceByTopic(msg.Topic()) - // mqttDumpMsg(msg) + // MQTTDumpMsg(msg) if zDev != nil { zDev.HandleMessage(msg) } diff --git a/mqtt.go b/mqtt.go index 557869a4032e461eda6c5556672f8fa37057a2b0..3745509aa04060bfe863a0915d70951713bad0f6 100644 --- a/mqtt.go +++ b/mqtt.go @@ -4,10 +4,8 @@ import ( "encoding/json" "fmt" "log/slog" - "sort" mqtt "github.com/eclipse/paho.mqtt.golang" - "github.com/jedib0t/go-pretty/v6/table" ) // MQTTSetup creates a new MQTT client @@ -36,21 +34,5 @@ func MQTTDumpMsg(msg mqtt.Message) { if err != nil { slog.Error("Error decoding JSON %v", "topic", msg.Topic(), "err", err) } - - // 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()) + jsonDump(data) } diff --git a/utils.go b/utils.go index 011a9246bff18e0f0253df77d59bbcf5d033e2bc..acc2eb591a3ca9b2894f154ac231c0af1d5b3998 100644 --- a/utils.go +++ b/utils.go @@ -3,8 +3,10 @@ package main import ( "fmt" "math" + "sort" "strconv" + "github.com/jedib0t/go-pretty/v6/table" "github.com/lucasb-eyer/go-colorful" ) @@ -22,6 +24,25 @@ func hexStringToInteger(hexString string) (uint64, error) { 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. // https://github.com/Koenkk/zigbee2mqtt/issues/3497 func xyToColor(x, y, brightness float64) colorful.Color { diff --git a/xaal.go b/xaal.go index c45cf4dfa6bf219ee94e5fdd8f68da5e91fc67c3..7a5c91490f4702dea6bf04c0e5c455ba27a67bad 100644 --- a/xaal.go +++ b/xaal.go @@ -503,4 +503,5 @@ func NewDebugDevice(addr uuid.UUID, zDev *Z2MDevice, exp *Expose) XAALDeviceInte func (dev *DebugDevice) update(payload map[string]interface{}) { slog.Info("Debug Device update", "payload", payload) + jsonDump(payload) }