mirror of
https://github.com/nikdoof/hapz2m.git
synced 2026-01-31 00:28:26 +00:00
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:
11
bridge.go
11
bridge.go
@@ -442,6 +442,12 @@ func (br *Bridge) accessories() []*accessory.A {
|
||||
return acc
|
||||
}
|
||||
|
||||
func deviceJsonDescriptor(d Device) []byte {
|
||||
d.Definition = nil
|
||||
j, _ := json.Marshal(d)
|
||||
return j
|
||||
}
|
||||
|
||||
// Creates and calls AddDevice() based on the JSON definitions from zigbee2mqtt/bridge/devices.
|
||||
func (br *Bridge) AddDevicesFromJSON(devJson []byte) error {
|
||||
var devices []Device
|
||||
@@ -458,12 +464,13 @@ func (br *Bridge) AddDevicesFromJSON(devJson []byte) error {
|
||||
if err == ErrDeviceSkipped || err == ErrUnknownDeviceType {
|
||||
continue
|
||||
}
|
||||
return err
|
||||
return fmt.Errorf("createAccessory failed: %+v %s", err, deviceJsonDescriptor(dev))
|
||||
|
||||
}
|
||||
|
||||
err = br.AddDevice(&dev, acc, exp)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("AddDevice failed: %+v %s", err, deviceJsonDescriptor(dev))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user