Skip to content

Commit

Permalink
Fix workaround reporting bug, fix product information attaching with …
Browse files Browse the repository at this point in the history
…no data.
  • Loading branch information
pwood committed Jun 24, 2024
1 parent 82e410e commit dc513d4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 33 deletions.
22 changes: 6 additions & 16 deletions implcaps/generic/device_workarounds/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,19 @@ func (i *Implementation) Load(ctx context.Context) (bool, error) {
if err := i.loadWorkaround(ctx, workaround); err != nil {
return false, err
} else {
i.workaroundsEnabled = append(i.workaroundsEnabled, "ZCLReportingKeepAlive")
i.workaroundsEnabled = append(i.workaroundsEnabled, workaround)
}
}

return true, nil
}

func (i *Implementation) Enumerate(ctx context.Context, m map[string]any) (bool, error) {
var workarounds []string

for k, _ := range m {
if strings.HasPrefix(k, "Enable") {
workarounds = append(workarounds, k)
}
}

i.m.Lock()
i.workaroundsEnabled = workarounds
i.m.Unlock()

for _, workaround := range workarounds {
if err := i.enumerateWorkaround(ctx, m, workaround); err != nil {
return false, err
for workaround, _ := range m {
if strings.HasPrefix(workaround, "Enable") {
if err := i.enumerateWorkaround(ctx, m, workaround); err != nil {
return false, err
}
}
}

Expand Down
36 changes: 19 additions & 17 deletions implcaps/generic/product_information/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,25 @@ func (g *Implementation) Enumerate(_ context.Context, m map[string]any) (bool, e
return g.pi != nil, fmt.Errorf("failed to cast '%s' value to string", k)
}

switch k {
case "Name":
newPI.Name = stringV
g.s.Set("Name", stringV)
attach = true
case "Manufacturer":
newPI.Manufacturer = stringV
g.s.Set("Manufacturer", stringV)
attach = true
case "Version":
newPI.Version = stringV
g.s.Set("Version", stringV)
attach = true
case "Serial":
newPI.Serial = stringV
g.s.Set("Serial", stringV)
attach = true
if len(stringV) > 0 {
switch k {
case "Name":
newPI.Name = stringV
g.s.Set("Name", stringV)
attach = true
case "Manufacturer":
newPI.Manufacturer = stringV
g.s.Set("Manufacturer", stringV)
attach = true
case "Version":
newPI.Version = stringV
g.s.Set("Version", stringV)
attach = true
case "Serial":
newPI.Serial = stringV
g.s.Set("Serial", stringV)
attach = true
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions implcaps/generic/product_information/impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,17 @@ func TestProductInformation(t *testing.T) {
assert.NoError(t, err)
})

t.Run("fails to attach if there is empty data", func(t *testing.T) {
pi := NewProductInformation()
pi.Init(nil, memory.New())

attached, err := pi.Enumerate(nil, map[string]any{
"Name": "",
"Manufacturer": "",
"Serial": "",
"Version": "",
})
assert.False(t, attached)
assert.NoError(t, err)
})
}

0 comments on commit dc513d4

Please sign in to comment.