Skip to content

Commit

Permalink
Capitalise ZDA persistence section names.
Browse files Browse the repository at this point in the history
  • Loading branch information
pwood committed Jun 15, 2024
1 parent f367036 commit 388df40
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions enumerate_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,9 @@ func (e enumerateDevice) enumerateCapabilityOnDevice(ctx context.Context, d *dev
}

section := e.gw.sectionForDevice(d.address).Section("capability", capabilities.StandardNames[cF])
section.Set("implementation", capImplName)
section.Set("Implementation", capImplName)

c.Init(d, section.Section("data"))
c.Init(d, section.Section("Data"))
}

e.logger.LogInfo(ctx, "Attaching capability implementation.")
Expand Down
12 changes: 6 additions & 6 deletions persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import (
)

func (z *ZDA) sectionRemoveNode(i zigbee.IEEEAddress) bool {
return z.section.Section("node").SectionDelete(i.String())
return z.section.Section("Node").SectionDelete(i.String())
}

func (z *ZDA) sectionForNode(i zigbee.IEEEAddress) persistence.Section {
return z.section.Section("node", i.String())
return z.section.Section("Node", i.String())
}

func (z *ZDA) nodeListFromPersistence() []zigbee.IEEEAddress {
var nodeList []zigbee.IEEEAddress

for _, k := range z.section.Section("node").SectionKeys() {
for _, k := range z.section.Section("Node").SectionKeys() {
if addr, err := strconv.ParseUint(k, 16, 64); err == nil {
nodeList = append(nodeList, zigbee.IEEEAddress(addr))
}
Expand All @@ -27,17 +27,17 @@ func (z *ZDA) nodeListFromPersistence() []zigbee.IEEEAddress {
}

func (z *ZDA) sectionRemoveDevice(i IEEEAddressWithSubIdentifier) bool {
return z.sectionForNode(i.IEEEAddress).Section("device").SectionDelete(strconv.Itoa(int(i.SubIdentifier)))
return z.sectionForNode(i.IEEEAddress).Section("Device").SectionDelete(strconv.Itoa(int(i.SubIdentifier)))
}

func (z *ZDA) sectionForDevice(i IEEEAddressWithSubIdentifier) persistence.Section {
return z.sectionForNode(i.IEEEAddress).Section("device", strconv.Itoa(int(i.SubIdentifier)))
return z.sectionForNode(i.IEEEAddress).Section("Device", strconv.Itoa(int(i.SubIdentifier)))
}

func (z *ZDA) deviceListFromPersistence(id zigbee.IEEEAddress) []IEEEAddressWithSubIdentifier {
var deviceList []IEEEAddressWithSubIdentifier

for _, k := range z.sectionForNode(id).Section("device").SectionKeys() {
for _, k := range z.sectionForNode(id).Section("Device").SectionKeys() {
if i, err := strconv.Atoi(k); err == nil {
deviceList = append(deviceList, IEEEAddressWithSubIdentifier{IEEEAddress: id, SubIdentifier: uint8(i)})
}
Expand Down
16 changes: 8 additions & 8 deletions provider_load.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,31 @@ func (z *ZDA) providerLoadDevice(pctx context.Context, n *node, i IEEEAddressWit

d := z.createSpecificDevice(n, i.SubIdentifier)

capSection := z.sectionForDevice(i).Section("capability")
capSection := z.sectionForDevice(i).Section("Capability")

for _, cName := range capSection.SectionKeys() {
cctx, cend := z.logger.Segment(ctx, "Loading capability data.", logwrap.Datum("capability", cName))

cSection := capSection.Section(cName)

if capImpl, ok := cSection.String("implementation"); ok {
if capImpl, ok := cSection.String("Implementation"); ok {
if capI := factory.Create(capImpl, z.zdaInterface); capI == nil {
z.logger.LogError(cctx, "Could not find capability implementation.", logwrap.Datum("implementation", capImpl))
z.logger.LogError(cctx, "Could not find capability implementation.", logwrap.Datum("Implementation", capImpl))
continue
} else {
z.logger.LogInfo(cctx, "Constructed capability implementation.", logwrap.Datum("implementation", capImpl))
capI.Init(d, cSection.Section("data"))
z.logger.LogInfo(cctx, "Constructed capability implementation.", logwrap.Datum("Implementation", capImpl))
capI.Init(d, cSection.Section("Data"))
attached, err := capI.Load(cctx)

if err != nil {
z.logger.LogError(cctx, "Error while loading from persistence.", logwrap.Err(err), logwrap.Datum("implementation", capImpl))
z.logger.LogError(cctx, "Error while loading from persistence.", logwrap.Err(err), logwrap.Datum("Implementation", capImpl))
}

if attached {
z.attachCapabilityToDevice(d, capI)
z.logger.LogInfo(cctx, "Attached capability from persistence.", logwrap.Datum("implementation", capImpl))
z.logger.LogInfo(cctx, "Attached capability from persistence.", logwrap.Datum("Implementation", capImpl))
} else {
z.logger.LogWarn(cctx, "Rejected capability attach from persistence.", logwrap.Datum("implementation", capImpl))
z.logger.LogWarn(cctx, "Rejected capability attach from persistence.", logwrap.Datum("Implementation", capImpl))
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions provider_load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ func Test_gateway_providerLoad(t *testing.T) {
id := IEEEAddressWithSubIdentifier{IEEEAddress: zigbee.GenerateLocalAdministeredIEEEAddress(), SubIdentifier: 1}
dS := g.sectionForDevice(id)

cS := dS.Section("capability", "ProductInformation")
cS.Set("implementation", "GenericProductInformation")
cS := dS.Section("Capability", "ProductInformation")
cS.Set("Implementation", "GenericProductInformation")

daS := cS.Section("data")
daS := cS.Section("Data")
daS.Set("Name", "NEXUS-7")
daS.Set("Manufacturer", "Tyrell Corporation")
daS.Set("Serial", "N7FAA52318")
Expand Down
4 changes: 2 additions & 2 deletions table.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,15 @@ func (z *ZDA) attachCapabilityToDevice(d *device, c implcaps.ZDACapability) {
cF := c.Capability()

d.capabilities[cF] = c
z.sectionForDevice(d.address).Section("capability", capabilities.StandardNames[cF])
z.sectionForDevice(d.address).Section("Capability", capabilities.StandardNames[cF])
z.sendEvent(da.CapabilityAdded{Device: d, Capability: cF})
}

func (z *ZDA) detachCapabilityFromDevice(d *device, c implcaps.ZDACapability) {
cF := c.Capability()
if _, found := d.capabilities[cF]; found {
z.sendEvent(da.CapabilityRemoved{Device: d, Capability: cF})
z.sectionForDevice(d.address).Section("capability").SectionDelete(capabilities.StandardNames[cF])
z.sectionForDevice(d.address).Section("Capability").SectionDelete(capabilities.StandardNames[cF])
delete(d.capabilities, cF)
}
}
6 changes: 3 additions & 3 deletions table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func Test_gateway_attachCapabilityToDevice(t *testing.T) {
assert.Len(t, events, 1)
assert.IsType(t, da.CapabilityAdded{}, events[0])

assert.True(t, g.sectionForDevice(d.address).Section("capability").SectionExists(capabilities.StandardNames[capabilities.ProductInformationFlag]))
assert.True(t, g.sectionForDevice(d.address).Section("Capability").SectionExists(capabilities.StandardNames[capabilities.ProductInformationFlag]))
})
}

Expand All @@ -272,7 +272,7 @@ func Test_gateway_detachCapabilityFromDevice(t *testing.T) {
c := generic.NewProductInformation()
g.attachCapabilityToDevice(d, c)

assert.True(t, g.sectionForDevice(d.address).Section("capability").SectionExists(capabilities.StandardNames[capabilities.ProductInformationFlag]))
assert.True(t, g.sectionForDevice(d.address).Section("Capability").SectionExists(capabilities.StandardNames[capabilities.ProductInformationFlag]))

_ = drainEvents(g)

Expand All @@ -284,7 +284,7 @@ func Test_gateway_detachCapabilityFromDevice(t *testing.T) {
assert.Len(t, events, 1)
assert.IsType(t, da.CapabilityRemoved{}, events[0])

assert.False(t, g.sectionForDevice(d.address).Section("capability").SectionExists(capabilities.StandardNames[capabilities.ProductInformationFlag]))
assert.False(t, g.sectionForDevice(d.address).Section("Capability").SectionExists(capabilities.StandardNames[capabilities.ProductInformationFlag]))
})

t.Run("does nothing if called for unattached capability", func(t *testing.T) {
Expand Down

0 comments on commit 388df40

Please sign in to comment.