-
Notifications
You must be signed in to change notification settings - Fork 2
/
device_test.go
80 lines (63 loc) · 2.02 KB
/
device_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package zda
import (
"github.com/shimmeringbee/da"
"github.com/shimmeringbee/da/capabilities"
"github.com/shimmeringbee/da/mocks"
"github.com/shimmeringbee/zda/implcaps"
"github.com/shimmeringbee/zda/implcaps/generic/product_information"
"github.com/shimmeringbee/zigbee"
"github.com/stretchr/testify/assert"
"sync"
"testing"
)
func Test_device(t *testing.T) {
t.Run("returns the gateway and address the device was configured with", func(t *testing.T) {
gw := &mocks.Gateway{}
expectedAddr := IEEEAddressWithSubIdentifier{
IEEEAddress: zigbee.GenerateLocalAdministeredIEEEAddress(),
SubIdentifier: 1,
}
d := device{
address: expectedAddr,
gw: gw,
}
assert.Equal(t, gw, d.gw)
assert.Equal(t, expectedAddr, d.Identifier())
})
t.Run("verifies that the devices capability functions behave as expected", func(t *testing.T) {
c := da.Capability(0x01)
d := device{
capabilities: map[da.Capability]implcaps.ZDACapability{c: nil},
m: &sync.RWMutex{},
}
assert.Contains(t, d.Capabilities(), c)
})
t.Run("Device returns the stored capability", func(t *testing.T) {
c := &product_information.Implementation{}
d := device{
capabilities: map[da.Capability]implcaps.ZDACapability{capabilities.ProductInformationFlag: c},
m: &sync.RWMutex{},
}
assert.Equal(t, c, d.Capability(capabilities.ProductInformationFlag))
})
}
func Test_gateway_transmissionLookup(t *testing.T) {
t.Run("returns details required to transmit to zigbee", func(t *testing.T) {
expectedAddress := zigbee.GenerateLocalAdministeredIEEEAddress()
ch := make(chan uint8, 1)
ch <- 1
d := &device{
address: IEEEAddressWithSubIdentifier{IEEEAddress: expectedAddress, SubIdentifier: 1},
n: &node{
sequence: ch,
useAPSAck: true,
},
}
g := &ZDA{}
ieee, endpoint, aps, seq := g.transmissionLookup(d, zigbee.ProfileHomeAutomation)
assert.Equal(t, expectedAddress, ieee)
assert.Equal(t, zigbee.Endpoint(1), endpoint)
assert.True(t, aps)
assert.Equal(t, uint8(1), seq)
})
}