From 1922f57a6fa5d3a85895054654434a63ce2d07b9 Mon Sep 17 00:00:00 2001 From: Darell Tan Date: Fri, 22 Nov 2024 04:31:06 +0800 Subject: [PATCH] Added Z2M description to the Accessory name This should help you better identify devices if you have added some description in zigbee2mqtt. --- z2m.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/z2m.go b/z2m.go index a4b031d..45f6bfa 100644 --- a/z2m.go +++ b/z2m.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "regexp" + "strings" "reflect" "runtime" @@ -113,8 +114,13 @@ func createAccessory(dev *Device) (*accessory.A, []*ExposeMapping, error) { } // create accessory first, then see if any handler wants to modify it + accName := dev.Definition.Description + devDesc := strings.TrimSpace(dev.Description) + if len(devDesc) > 0 { + accName = devDesc + " " + accName + } acc := accessory.New(accessory.Info{ - Name: dev.Definition.Description, + Name: accName, SerialNumber: serialNum, Manufacturer: dev.Manufacturer, Model: dev.Definition.Model, @@ -285,6 +291,7 @@ type Device struct { PowerSource string `json:"power_source,omitempty"` SoftwareBuildId string `json:"software_build_id,omitempty"` DateCode string `json:"date_code,omitempty"` + Description string `json:"description,omitempty"` Definition *DevDefinition `json:"definition,omitempty"`