Skip to content

Commit

Permalink
Change Self() device to match others.
Browse files Browse the repository at this point in the history
  • Loading branch information
pwood committed Jun 18, 2024
1 parent 054421a commit 9e2582f
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
8 changes: 4 additions & 4 deletions enumerate_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand All @@ -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))
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
2 changes: 1 addition & 1 deletion provider_load.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion provider_load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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("Device", 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("Device").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("Device").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("Device").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("Device").SectionExists(capabilities.StandardNames[capabilities.ProductInformationFlag]))
})

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

0 comments on commit 9e2582f

Please sign in to comment.