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

Update display

parent 44b546c8
No related branches found
No related tags found
No related merge requests found
......@@ -14,7 +14,7 @@ func setupDevice(dev *xaal.Device, bDevice *BridgeDevice) {
dev.ProductID = bDevice.Definition.Model
dev.HWID = bDevice.IeeeAddress
dev.Version = bDevice.SwBuildID
dev.Info = "z2m: " + bDevice.FriendlyName
dev.Info = "z2m:" + bDevice.Type + ":" + bDevice.FriendlyName
}
func newDevices(gw *gateway, bDevice *BridgeDevice) {
......
......@@ -6,6 +6,7 @@ import (
"log/slog"
"slices"
"sort"
"strings"
MQTT "github.com/eclipse/paho.mqtt.golang"
"github.com/jedib0t/go-pretty/v6/table"
......@@ -74,9 +75,20 @@ func (bDevices *BridgeDevice) dump() {
expTab := table.NewWriter()
expTab.SetTitle("Exp:" + bDevices.FriendlyName)
expTab.SetStyle(table.StyleRounded)
expTab.AppendHeader(table.Row{"Name", "Type", "Unit"})
expTab.AppendHeader(table.Row{"Name", "Type", "Unit", "Values", "Features: Name[Type](Unit){Property}"})
for _, expose := range bDevices.Definition.Exposes {
expTab.AppendRow(table.Row{expose.Name, expose.Type, expose.Unit})
values := ""
if len(expose.Values) > 0 {
values = strings.Join(expose.Values, "\n")
}
features := ""
if len(expose.Features) > 0 {
for _, feature := range expose.Features {
features += fmt.Sprintf("- %s[%s](%s){%s}\n", feature.Name, feature.Type, feature.Unit, feature.Property)
}
features = strings.TrimSuffix(features, "\n")
}
expTab.AppendRow(table.Row{expose.Name, expose.Type, expose.Unit, values, features})
}
fmt.Println(expTab.Render())
}
......@@ -102,22 +114,7 @@ func parseDeviceJSON(jsonData []byte) {
if !newFlag {
continue
}
device.dump()
for _, expose := range device.Definition.Exposes {
fmt.Printf("- Expose: %s[%s](%s)\n", expose.Name, expose.Type, expose.Unit)
if len(expose.Features) > 0 {
for _, feature := range expose.Features {
fmt.Printf(" - Feature: %s[%s](%s){%s}\n", feature.Name, feature.Type, feature.Unit, feature.Property)
}
}
if len(expose.Values) > 0 {
fmt.Printf(" - Values: %v\n", expose.Values)
}
}
fmt.Printf("------------------\n\n")
// spew.Dump(device)
newDevices(gw, &device)
// TODO: filter if device already exists
gw.devices = append(gw.devices, &device)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment