From 388df40f2291685e0fb56b769b203ce5786a48cd Mon Sep 17 00:00:00 2001 From: Peter Wood Date: Sat, 15 Jun 2024 18:37:32 +0100 Subject: [PATCH] Capitalise ZDA persistence section names. --- enumerate_device.go | 4 ++-- persistence.go | 12 ++++++------ provider_load.go | 16 ++++++++-------- provider_load_test.go | 6 +++--- table.go | 4 ++-- table_test.go | 6 +++--- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/enumerate_device.go b/enumerate_device.go index 336110e..d81b1f0 100644 --- a/enumerate_device.go +++ b/enumerate_device.go @@ -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.") diff --git a/persistence.go b/persistence.go index 68ba50a..311a461 100644 --- a/persistence.go +++ b/persistence.go @@ -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)) } @@ -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)}) } diff --git a/provider_load.go b/provider_load.go index 958526f..5eda27e 100644 --- a/provider_load.go +++ b/provider_load.go @@ -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)) } } } diff --git a/provider_load_test.go b/provider_load_test.go index 346f052..6c5dac1 100644 --- a/provider_load_test.go +++ b/provider_load_test.go @@ -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") diff --git a/table.go b/table.go index 9b7e637..0976d97 100644 --- a/table.go +++ b/table.go @@ -178,7 +178,7 @@ 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}) } @@ -186,7 +186,7 @@ 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) } } diff --git a/table_test.go b/table_test.go index 628338d..96c4fd6 100644 --- a/table_test.go +++ b/table_test.go @@ -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])) }) } @@ -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) @@ -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) {