From 9e2582f9f071c3892a131ffed0127980623cf7cb Mon Sep 17 00:00:00 2001 From: Peter Wood Date: Tue, 18 Jun 2024 21:09:46 +0100 Subject: [PATCH] Change Self() device to match others. --- device_test.go | 2 +- enumerate_device.go | 8 ++++---- gateway.go | 2 +- gateway_test.go | 2 +- provider_load.go | 2 +- provider_load_test.go | 2 +- table.go | 8 ++++---- table_test.go | 6 +++--- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/device_test.go b/device_test.go index f385fa7..5223047 100644 --- a/device_test.go +++ b/device_test.go @@ -41,7 +41,7 @@ func Test_device(t *testing.T) { assert.Contains(t, d.Capabilities(), c) }) - t.Run("Capability returns the stored capability", func(t *testing.T) { + t.Run("Device returns the stored capability", func(t *testing.T) { c := &generic.ProductInformation{} d := device{ diff --git a/enumerate_device.go b/enumerate_device.go index d81b1f0..2b4fd71 100644 --- a/enumerate_device.go +++ b/enumerate_device.go @@ -349,7 +349,7 @@ func (e enumerateDevice) updateCapabilitiesOnDevice(ctx context.Context, d *devi errs[cF] = &capabilities.EnumerationCapability{Attached: false} } - ectx, end := e.logger.Segment(ctx, "Enumerating capability.", logwrap.Datum("Endpoint", ep.description.Endpoint), logwrap.Datum("DeviceId", ep.description.DeviceID), logwrap.Datum("CapabilityImplementation", capImplName), logwrap.Datum("Capability", capabilities.StandardNames[cF])) + ectx, end := e.logger.Segment(ctx, "Enumerating capability.", logwrap.Datum("Endpoint", ep.description.Endpoint), logwrap.Datum("DeviceId", ep.description.DeviceID), logwrap.Datum("CapabilityImplementation", capImplName), logwrap.Datum("Device", capabilities.StandardNames[cF])) attached, err := e.enumerateCapabilityOnDevice(ectx, d, capImplName, cF, activeCapabilities, settings) if err != nil { errs[cF].Errors = append(errs[cF].Errors, err...) @@ -368,7 +368,7 @@ func (e enumerateDevice) updateCapabilitiesOnDevice(ctx context.Context, d *devi if !slices.Contains(activeCapabilities, cf) { errs[cf] = &capabilities.EnumerationCapability{Attached: false} - e.logger.LogInfo(ctx, "Removing redundant capability implementation.", logwrap.Datum("Capability", capabilities.StandardNames[cf])) + e.logger.LogInfo(ctx, "Removing redundant capability implementation.", logwrap.Datum("Device", capabilities.StandardNames[cf])) if err := impl.Detach(ctx, implcaps.NoLongerEnumerated); err != nil { e.logger.LogWarn(ctx, "Failed to detach redundant capability.", logwrap.Datum("RedundantCapabilityImplementationName", impl.ImplName()), logwrap.Err(err)) errs[cf].Errors = append(errs[cf].Errors, fmt.Errorf("failed to detach redundant capabiltiy: %w", err)) @@ -420,7 +420,7 @@ func (e enumerateDevice) enumerateCapabilityOnDevice(ctx context.Context, d *dev e.logger.LogInfo(ctx, "Attaching capability implementation.") defer func() { if r := recover(); r != nil { - e.logger.LogPanic(ctx, "Capability paniced during enumeration!", logwrap.Datum("Panic", r), logwrap.Datum("Trace", string(debug.Stack()))) + e.logger.LogPanic(ctx, "Device paniced during enumeration!", logwrap.Datum("Panic", r), logwrap.Datum("Trace", string(debug.Stack()))) } }() attached, err := c.Enumerate(ctx, settings) @@ -439,7 +439,7 @@ func (e enumerateDevice) enumerateCapabilityOnDevice(ctx context.Context, d *dev e.dm.detachCapabilityFromDevice(d, c) } else { e.dm.attachCapabilityToDevice(d, c) - e.logger.LogInfo(ctx, "Capability attached successfully.") + e.logger.LogInfo(ctx, "Device attached successfully.") } return attached, errs diff --git a/gateway.go b/gateway.go index 38468d7..3f42e71 100644 --- a/gateway.go +++ b/gateway.go @@ -141,7 +141,7 @@ func (z *ZDA) Start(ctx context.Context) error { z.selfDevice = gatewayDevice{ gateway: z, - identifier: adapterNode.IEEEAddress, + identifier: IEEEAddressWithSubIdentifier{IEEEAddress: adapterNode.IEEEAddress, SubIdentifier: 0}, dd: &deviceDiscovery{ gateway: z, networkJoining: z.provider, diff --git a/gateway_test.go b/gateway_test.go index b3a5b9a..660af46 100644 --- a/gateway_test.go +++ b/gateway_test.go @@ -57,7 +57,7 @@ func Test_gateway_Start(t *testing.T) { assert.NoError(t, err) self := gw.Self() - assert.Equal(t, testGatewayIEEEAddress, self.Identifier()) + assert.Equal(t, IEEEAddressWithSubIdentifier{IEEEAddress: testGatewayIEEEAddress, SubIdentifier: 0}, self.Identifier()) assert.Equal(t, gw, self.Gateway()) assert.Contains(t, self.Capabilities(), capabilities.DeviceDiscoveryFlag) }) diff --git a/provider_load.go b/provider_load.go index 5eda27e..360d714 100644 --- a/provider_load.go +++ b/provider_load.go @@ -32,7 +32,7 @@ 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("Device") for _, cName := range capSection.SectionKeys() { cctx, cend := z.logger.Segment(ctx, "Loading capability data.", logwrap.Datum("capability", cName)) diff --git a/provider_load_test.go b/provider_load_test.go index 6c5dac1..4280b6f 100644 --- a/provider_load_test.go +++ b/provider_load_test.go @@ -19,7 +19,7 @@ func Test_gateway_providerLoad(t *testing.T) { id := IEEEAddressWithSubIdentifier{IEEEAddress: zigbee.GenerateLocalAdministeredIEEEAddress(), SubIdentifier: 1} dS := g.sectionForDevice(id) - cS := dS.Section("Capability", "ProductInformation") + cS := dS.Section("Device", "ProductInformation") cS.Set("Implementation", "GenericProductInformation") daS := cS.Section("Data") diff --git a/table.go b/table.go index 0976d97..1aa8ff1 100644 --- a/table.go +++ b/table.go @@ -153,9 +153,9 @@ func (z *ZDA) removeDevice(ctx context.Context, addr IEEEAddressWithSubIdentifie if d, found := n.device[addr.SubIdentifier]; found { d.m.RLock() for cf, impl := range d.capabilities { - z.logger.LogInfo(ctx, "Detaching capability from removed device.", logwrap.Datum("Capability", capabilities.StandardNames[cf]), logwrap.Datum("CapabilityImplementation", impl.ImplName())) + z.logger.LogInfo(ctx, "Detaching capability from removed device.", logwrap.Datum("Device", capabilities.StandardNames[cf]), logwrap.Datum("CapabilityImplementation", impl.ImplName())) if err := impl.Detach(ctx, implcaps.DeviceRemoved); err != nil { - z.logger.LogWarn(ctx, "Error thrown while detaching capability.", logwrap.Datum("Capability", capabilities.StandardNames[cf]), logwrap.Datum("CapabilityImplementation", impl.ImplName()), logwrap.Err(err)) + z.logger.LogWarn(ctx, "Error thrown while detaching capability.", logwrap.Datum("Device", capabilities.StandardNames[cf]), logwrap.Datum("CapabilityImplementation", impl.ImplName()), logwrap.Err(err)) } z.detachCapabilityFromDevice(d, impl) @@ -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("Device", 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("Device").SectionDelete(capabilities.StandardNames[cF]) delete(d.capabilities, cF) } } diff --git a/table_test.go b/table_test.go index 96c4fd6..b702696 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("Device").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("Device").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("Device").SectionExists(capabilities.StandardNames[capabilities.ProductInformationFlag])) }) t.Run("does nothing if called for unattached capability", func(t *testing.T) {