Handle unknown device types

For devices that we have no idea how to handle, i.e. no services or
expose entries were processed, we return ErrUnknownDeviceType and skip
it during AddDevicesFromJSON(). This prevents a device from showing up
where HomeKit says it's not supported.
This commit is contained in:
Darell Tan
2023-08-04 23:49:51 +08:00
parent 24e3f92a59
commit b1949c73fd
2 changed files with 10 additions and 3 deletions

View File

@@ -393,7 +393,7 @@ func (br *Bridge) AddDevicesFromJSON(devJson []byte) error {
acc, exp, err := createAccessory(&dev)
if err != nil {
if err == ErrDeviceSkipped {
if err == ErrDeviceSkipped || err == ErrUnknownDeviceType {
continue
}
return err

11
z2m.go
View File

@@ -23,8 +23,9 @@ var IgnoreProperties = map[string]bool{
}
var (
ErrDeviceSkipped = fmt.Errorf("device is skipped")
ErrMalfomedDevice = fmt.Errorf("device is malformed")
ErrDeviceSkipped = fmt.Errorf("device is skipped")
ErrMalfomedDevice = fmt.Errorf("device is malformed")
ErrUnknownDeviceType = fmt.Errorf("device type is unknown")
ErrNotNumericCharacteristic = fmt.Errorf("characteristic is non-numeric")
)
@@ -119,6 +120,11 @@ func createAccessory(dev *Device) (*accessory.A, []*ExposeMapping, error) {
allExposes = append(allExposes, exposes...)
}
// if no Exposes entry was processed, return error
if len(allExposes) == 0 {
return nil, nil, ErrUnknownDeviceType
}
// copy value ranges
for _, e := range allExposes {
if e.ExposesEntry.Type != "numeric" {
@@ -316,6 +322,7 @@ func (m *ExposeMapping) ToExposedValue(v any) (any, error) {
expVal = m.ExposesEntry.ValueOn
}
}
return expVal, err
}