Skip to content

Commit 817a66d

Browse files
committed
Add identify ZCL cluster.
1 parent 8400e0c commit 817a66d

File tree

3 files changed

+160
-0
lines changed

3 files changed

+160
-0
lines changed

commands/local/identify/identify.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package identify
2+
3+
import "github.com/shimmeringbee/zcl"
4+
5+
const (
6+
IdentifyTime = zcl.AttributeID(0x0000)
7+
)
8+
9+
const (
10+
IdentifyId = zcl.CommandIdentifier(0x00)
11+
IdentifyQueryId = zcl.CommandIdentifier(0x01)
12+
TriggerEffectId = zcl.CommandIdentifier(0x02)
13+
14+
IdentifyQueryResponseId = zcl.CommandIdentifier(0x00)
15+
)
16+
17+
type Identify struct {
18+
IdentifyTime uint16
19+
}
20+
21+
type IdentifyQuery struct{}
22+
23+
type TriggerEffect struct {
24+
EffectIdentifier uint8
25+
EffectVariant uint8
26+
}
27+
28+
type IdentifyQueryResponse struct {
29+
Timeout uint16
30+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package identify
2+
3+
import (
4+
"github.com/shimmeringbee/bytecodec"
5+
"github.com/shimmeringbee/zcl"
6+
"github.com/shimmeringbee/zigbee"
7+
"github.com/stretchr/testify/assert"
8+
"testing"
9+
)
10+
11+
func Test_Identify(t *testing.T) {
12+
t.Run("marshals and unmarshalls correctly", func(t *testing.T) {
13+
expectedCommand := Identify{
14+
IdentifyTime: 0x1122,
15+
}
16+
actualCommand := Identify{}
17+
expectedBytes := []byte{0x22, 0x11}
18+
19+
actualBytes, err := bytecodec.Marshal(&expectedCommand)
20+
assert.NoError(t, err)
21+
assert.Equal(t, expectedBytes, actualBytes)
22+
23+
err = bytecodec.Unmarshal(expectedBytes, &actualCommand)
24+
assert.NoError(t, err)
25+
assert.Equal(t, expectedCommand, actualCommand)
26+
})
27+
28+
t.Run("the message is registered in the command registry", func(t *testing.T) {
29+
cr := zcl.NewCommandRegistry()
30+
Register(cr)
31+
32+
id, err := cr.GetLocalCommandIdentifier(zcl.IdentifyId, zigbee.NoManufacturer, zcl.ClientToServer, &Identify{})
33+
assert.NoError(t, err)
34+
assert.Equal(t, IdentifyId, id)
35+
})
36+
}
37+
38+
func Test_IdentifyQuery(t *testing.T) {
39+
t.Run("marshals and unmarshalls correctly", func(t *testing.T) {
40+
expectedCommand := IdentifyQuery{}
41+
actualCommand := IdentifyQuery{}
42+
expectedBytes := []byte(nil)
43+
44+
actualBytes, err := bytecodec.Marshal(&expectedCommand)
45+
assert.NoError(t, err)
46+
assert.Equal(t, expectedBytes, actualBytes)
47+
48+
err = bytecodec.Unmarshal(expectedBytes, &actualCommand)
49+
assert.NoError(t, err)
50+
assert.Equal(t, expectedCommand, actualCommand)
51+
})
52+
53+
t.Run("the message is registered in the command registry", func(t *testing.T) {
54+
cr := zcl.NewCommandRegistry()
55+
Register(cr)
56+
57+
id, err := cr.GetLocalCommandIdentifier(zcl.IdentifyId, zigbee.NoManufacturer, zcl.ClientToServer, &IdentifyQuery{})
58+
assert.NoError(t, err)
59+
assert.Equal(t, IdentifyQueryId, id)
60+
})
61+
}
62+
63+
func Test_TriggerEffect(t *testing.T) {
64+
t.Run("marshals and unmarshalls correctly", func(t *testing.T) {
65+
expectedCommand := TriggerEffect{
66+
EffectIdentifier: 0x11,
67+
EffectVariant: 0x22,
68+
}
69+
actualCommand := TriggerEffect{}
70+
expectedBytes := []byte{0x11, 0x22}
71+
72+
actualBytes, err := bytecodec.Marshal(&expectedCommand)
73+
assert.NoError(t, err)
74+
assert.Equal(t, expectedBytes, actualBytes)
75+
76+
err = bytecodec.Unmarshal(expectedBytes, &actualCommand)
77+
assert.NoError(t, err)
78+
assert.Equal(t, expectedCommand, actualCommand)
79+
})
80+
81+
t.Run("the message is registered in the command registry", func(t *testing.T) {
82+
cr := zcl.NewCommandRegistry()
83+
Register(cr)
84+
85+
id, err := cr.GetLocalCommandIdentifier(zcl.IdentifyId, zigbee.NoManufacturer, zcl.ClientToServer, &TriggerEffect{})
86+
assert.NoError(t, err)
87+
assert.Equal(t, TriggerEffectId, id)
88+
})
89+
}
90+
91+
func Test_IdentifyQueryResponse(t *testing.T) {
92+
t.Run("marshals and unmarshalls correctly", func(t *testing.T) {
93+
expectedCommand := IdentifyQueryResponse{
94+
Timeout: 0x1122,
95+
}
96+
actualCommand := IdentifyQueryResponse{}
97+
expectedBytes := []byte{0x22, 0x11}
98+
99+
actualBytes, err := bytecodec.Marshal(&expectedCommand)
100+
assert.NoError(t, err)
101+
assert.Equal(t, expectedBytes, actualBytes)
102+
103+
err = bytecodec.Unmarshal(expectedBytes, &actualCommand)
104+
assert.NoError(t, err)
105+
assert.Equal(t, expectedCommand, actualCommand)
106+
})
107+
108+
t.Run("the message is registered in the command registry", func(t *testing.T) {
109+
cr := zcl.NewCommandRegistry()
110+
Register(cr)
111+
112+
id, err := cr.GetLocalCommandIdentifier(zcl.IdentifyId, zigbee.NoManufacturer, zcl.ServerToClient, &IdentifyQueryResponse{})
113+
assert.NoError(t, err)
114+
assert.Equal(t, IdentifyQueryResponseId, id)
115+
})
116+
}

commands/local/identify/register.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package identify
2+
3+
import (
4+
"github.com/shimmeringbee/zcl"
5+
"github.com/shimmeringbee/zigbee"
6+
)
7+
8+
func Register(cr *zcl.CommandRegistry) {
9+
cr.RegisterLocal(zcl.IdentifyId, zigbee.NoManufacturer, zcl.ClientToServer, IdentifyId, &Identify{})
10+
cr.RegisterLocal(zcl.IdentifyId, zigbee.NoManufacturer, zcl.ClientToServer, IdentifyQueryId, &IdentifyQuery{})
11+
cr.RegisterLocal(zcl.IdentifyId, zigbee.NoManufacturer, zcl.ClientToServer, TriggerEffectId, &TriggerEffect{})
12+
13+
cr.RegisterLocal(zcl.IdentifyId, zigbee.NoManufacturer, zcl.ServerToClient, IdentifyQueryResponseId, &IdentifyQueryResponse{})
14+
}

0 commit comments

Comments
 (0)