Only process EndDevices during add and more verbose errors

If a Coordinator is present in the device list, AddDevicesFromJSON will
fail catastrophically, which shouldn't happen. Therefore, make sure only
EndDevices are considered during add. Also updated the tests to check
for this.

Added a device descriptor for failed adds. This will help with
identifying which device failed (and perhaps, why).
This commit is contained in:
Darell Tan
2024-11-22 03:40:27 +08:00
parent 5e24287d8c
commit e678f2a31d
3 changed files with 48 additions and 21 deletions

15
z2m.go
View File

@@ -76,7 +76,8 @@ func initExposeMappings(exposes ...*ExposeMapping) error {
func createAccessory(dev *Device) (*accessory.A, []*ExposeMapping, error) {
if dev.Disabled ||
!dev.Supported ||
!dev.InterviewCompleted {
!dev.InterviewCompleted ||
dev.Type != "EndDevice" {
return nil, nil, ErrDeviceSkipped
}
@@ -278,14 +279,14 @@ type Device struct {
IEEEAddress string `json:"ieee_address"`
InterviewCompleted bool `json:"interview_completed"`
Interviewing bool `json:"interviewing"`
Manufacturer string `json:"manufacturer"`
ModelId string `json:"model_id"`
Manufacturer string `json:"manufacturer,omitempty"`
ModelId string `json:"model_id,omitempty"`
NetworkAddress int `json:"network_address"`
PowerSource string `json:"power_source"`
SoftwareBuildId string `json:"software_build_id"`
DateCode string `json:"date_code"`
PowerSource string `json:"power_source,omitempty"`
SoftwareBuildId string `json:"software_build_id,omitempty"`
DateCode string `json:"date_code,omitempty"`
Definition *DevDefinition `json:"definition"`
Definition *DevDefinition `json:"definition,omitempty"`
Disabled bool `json:"disabled"`
Supported bool `json:"supported"`