mirror of
https://github.com/nikdoof/hapz2m.git
synced 2026-01-30 06:58:14 +00:00
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:
@@ -393,7 +393,7 @@ func (br *Bridge) AddDevicesFromJSON(devJson []byte) error {
|
|||||||
|
|
||||||
acc, exp, err := createAccessory(&dev)
|
acc, exp, err := createAccessory(&dev)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == ErrDeviceSkipped {
|
if err == ErrDeviceSkipped || err == ErrUnknownDeviceType {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
|||||||
11
z2m.go
11
z2m.go
@@ -23,8 +23,9 @@ var IgnoreProperties = map[string]bool{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrDeviceSkipped = fmt.Errorf("device is skipped")
|
ErrDeviceSkipped = fmt.Errorf("device is skipped")
|
||||||
ErrMalfomedDevice = fmt.Errorf("device is malformed")
|
ErrMalfomedDevice = fmt.Errorf("device is malformed")
|
||||||
|
ErrUnknownDeviceType = fmt.Errorf("device type is unknown")
|
||||||
|
|
||||||
ErrNotNumericCharacteristic = fmt.Errorf("characteristic is non-numeric")
|
ErrNotNumericCharacteristic = fmt.Errorf("characteristic is non-numeric")
|
||||||
)
|
)
|
||||||
@@ -119,6 +120,11 @@ func createAccessory(dev *Device) (*accessory.A, []*ExposeMapping, error) {
|
|||||||
allExposes = append(allExposes, exposes...)
|
allExposes = append(allExposes, exposes...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if no Exposes entry was processed, return error
|
||||||
|
if len(allExposes) == 0 {
|
||||||
|
return nil, nil, ErrUnknownDeviceType
|
||||||
|
}
|
||||||
|
|
||||||
// copy value ranges
|
// copy value ranges
|
||||||
for _, e := range allExposes {
|
for _, e := range allExposes {
|
||||||
if e.ExposesEntry.Type != "numeric" {
|
if e.ExposesEntry.Type != "numeric" {
|
||||||
@@ -316,6 +322,7 @@ func (m *ExposeMapping) ToExposedValue(v any) (any, error) {
|
|||||||
expVal = m.ExposesEntry.ValueOn
|
expVal = m.ExposesEntry.ValueOn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return expVal, err
|
return expVal, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user