mirror of
https://github.com/nikdoof/hapz2m.git
synced 2026-01-30 11:38:22 +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)
|
||||
if err != nil {
|
||||
if err == ErrDeviceSkipped {
|
||||
if err == ErrDeviceSkipped || err == ErrUnknownDeviceType {
|
||||
continue
|
||||
}
|
||||
return err
|
||||
|
||||
7
z2m.go
7
z2m.go
@@ -25,6 +25,7 @@ var IgnoreProperties = map[string]bool{
|
||||
var (
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user