@@ -11,7 +11,9 @@ const mqtt = {
11
11
12
12
const zigbee = {
13
13
getDevice : null ,
14
- publish : sinon . spy ( ) ,
14
+ publish : sandbox . stub ( ) . callsFake ( ( ieeAddr , cid , cmd , cmdType , zclData , cfg , ep , callback ) => {
15
+ callback ( false , null ) ;
16
+ } ) ,
15
17
} ;
16
18
17
19
const cfg = {
@@ -26,7 +28,7 @@ describe('DevicePublish', () => {
26
28
27
29
beforeEach ( ( ) => {
28
30
utils . stubLogger ( sandbox ) ;
29
- devicePublish = new DevicePublish ( zigbee , mqtt , null , null ) ;
31
+ devicePublish = new DevicePublish ( zigbee , mqtt , null , ( ) => { } ) ;
30
32
} ) ;
31
33
32
34
afterEach ( ( ) => {
@@ -37,7 +39,6 @@ describe('DevicePublish', () => {
37
39
it ( 'Should publish messages to zigbee devices' , ( ) => {
38
40
zigbee . publish . resetHistory ( ) ;
39
41
zigbee . getDevice = sinon . fake . returns ( { modelId : 'TRADFRI bulb E27 CWS opal 600lm' } ) ;
40
- devicePublish = new DevicePublish ( zigbee , mqtt , null , null ) ;
41
42
devicePublish . onMQTTMessage ( 'zigbee2mqtt/0x12345678/set' , JSON . stringify ( { brightness : '200' } ) ) ;
42
43
chai . assert . isTrue ( zigbee . publish . calledOnce ) ;
43
44
chai . assert . strictEqual ( zigbee . publish . getCall ( 0 ) . args [ 0 ] , '0x12345678' ) ;
@@ -52,7 +53,6 @@ describe('DevicePublish', () => {
52
53
it ( 'Should publish messages to zigbee devices when brightness is in %' , ( ) => {
53
54
zigbee . publish . resetHistory ( ) ;
54
55
zigbee . getDevice = sinon . fake . returns ( { modelId : 'TRADFRI bulb E27 CWS opal 600lm' } ) ;
55
- devicePublish = new DevicePublish ( zigbee , mqtt , null , null ) ;
56
56
devicePublish . onMQTTMessage ( 'zigbee2mqtt/0x12345678/set' , JSON . stringify ( { brightness : '92%' } ) ) ;
57
57
chai . assert . isTrue ( zigbee . publish . calledOnce ) ;
58
58
chai . assert . strictEqual ( zigbee . publish . getCall ( 0 ) . args [ 0 ] , '0x12345678' ) ;
@@ -67,7 +67,6 @@ describe('DevicePublish', () => {
67
67
it ( 'Should publish messages to zigbee devices when brightness is in number' , ( ) => {
68
68
zigbee . publish . resetHistory ( ) ;
69
69
zigbee . getDevice = sinon . fake . returns ( { modelId : 'TRADFRI bulb E27 CWS opal 600lm' } ) ;
70
- devicePublish = new DevicePublish ( zigbee , mqtt , null , null ) ;
71
70
devicePublish . onMQTTMessage ( 'zigbee2mqtt/0x12345678/set' , JSON . stringify ( { brightness : 230 } ) ) ;
72
71
chai . assert . isTrue ( zigbee . publish . calledOnce ) ;
73
72
chai . assert . strictEqual ( zigbee . publish . getCall ( 0 ) . args [ 0 ] , '0x12345678' ) ;
@@ -82,7 +81,6 @@ describe('DevicePublish', () => {
82
81
it ( 'Should publish messages to zigbee devices with color_temp' , ( ) => {
83
82
zigbee . publish . resetHistory ( ) ;
84
83
zigbee . getDevice = sinon . fake . returns ( { modelId : 'TRADFRI bulb E27 CWS opal 600lm' } ) ;
85
- devicePublish = new DevicePublish ( zigbee , mqtt , null , null ) ;
86
84
devicePublish . onMQTTMessage ( 'zigbee2mqtt/0x12345678/set' , JSON . stringify ( { color_temp : '222' } ) ) ;
87
85
chai . assert . isTrue ( zigbee . publish . calledOnce ) ;
88
86
chai . assert . strictEqual ( zigbee . publish . getCall ( 0 ) . args [ 0 ] , '0x12345678' ) ;
@@ -97,7 +95,6 @@ describe('DevicePublish', () => {
97
95
it ( 'Should publish messages to zigbee devices with color_temp in %' , ( ) => {
98
96
zigbee . publish . resetHistory ( ) ;
99
97
zigbee . getDevice = sinon . fake . returns ( { modelId : 'TRADFRI bulb E27 CWS opal 600lm' } ) ;
100
- devicePublish = new DevicePublish ( zigbee , mqtt , null , null ) ;
101
98
devicePublish . onMQTTMessage ( 'zigbee2mqtt/0x12345678/set' , JSON . stringify ( { color_temp : '100%' } ) ) ;
102
99
chai . assert . isTrue ( zigbee . publish . calledOnce ) ;
103
100
chai . assert . strictEqual ( zigbee . publish . getCall ( 0 ) . args [ 0 ] , '0x12345678' ) ;
@@ -112,7 +109,6 @@ describe('DevicePublish', () => {
112
109
it ( 'Should publish messages to zigbee devices with non-default ep' , ( ) => {
113
110
zigbee . publish . resetHistory ( ) ;
114
111
zigbee . getDevice = sinon . fake . returns ( { modelId : 'lumi.ctrl_neutral1' } ) ;
115
- devicePublish = new DevicePublish ( zigbee , mqtt , null , null ) ;
116
112
devicePublish . onMQTTMessage ( 'zigbee2mqtt/0x12345678/set' , JSON . stringify ( { state : 'OFF' } ) ) ;
117
113
chai . assert . isTrue ( zigbee . publish . calledOnce ) ;
118
114
chai . assert . strictEqual ( zigbee . publish . getCall ( 0 ) . args [ 0 ] , '0x12345678' ) ;
@@ -127,7 +123,6 @@ describe('DevicePublish', () => {
127
123
it ( 'Should publish messages to zigbee devices with non-default ep and postfix' , ( ) => {
128
124
zigbee . publish . resetHistory ( ) ;
129
125
zigbee . getDevice = sinon . fake . returns ( { modelId : 'lumi.ctrl_neutral2' } ) ;
130
- devicePublish = new DevicePublish ( zigbee , mqtt , null , null ) ;
131
126
devicePublish . onMQTTMessage ( 'zigbee2mqtt/0x12345678/right/set' , JSON . stringify ( { state : 'OFF' } ) ) ;
132
127
chai . assert . isTrue ( zigbee . publish . calledOnce ) ;
133
128
chai . assert . strictEqual ( zigbee . publish . getCall ( 0 ) . args [ 0 ] , '0x12345678' ) ;
@@ -142,7 +137,6 @@ describe('DevicePublish', () => {
142
137
it ( 'Should publish messages to zigbee gledopto with [11,13]' , ( ) => {
143
138
zigbee . publish . resetHistory ( ) ;
144
139
zigbee . getDevice = sinon . fake . returns ( { modelId : 'GLEDOPTO' , epList : [ 11 , 13 ] } ) ;
145
- devicePublish = new DevicePublish ( zigbee , mqtt , null , null ) ;
146
140
devicePublish . onMQTTMessage ( 'zigbee2mqtt/0x12345678/set' , JSON . stringify ( { state : 'OFF' } ) ) ;
147
141
chai . assert . isTrue ( zigbee . publish . calledOnce ) ;
148
142
chai . assert . strictEqual ( zigbee . publish . getCall ( 0 ) . args [ 0 ] , '0x12345678' ) ;
@@ -157,7 +151,6 @@ describe('DevicePublish', () => {
157
151
it ( 'Should publish messages to zigbee gledopto with [11,12,13]' , ( ) => {
158
152
zigbee . publish . resetHistory ( ) ;
159
153
zigbee . getDevice = sinon . fake . returns ( { modelId : 'GLEDOPTO' , epList : [ 11 , 12 , 13 ] } ) ;
160
- devicePublish = new DevicePublish ( zigbee , mqtt , null , null ) ;
161
154
devicePublish . onMQTTMessage ( 'zigbee2mqtt/0x12345678/set' , JSON . stringify ( { state : 'OFF' } ) ) ;
162
155
chai . assert . isTrue ( zigbee . publish . calledOnce ) ;
163
156
chai . assert . strictEqual ( zigbee . publish . getCall ( 0 ) . args [ 0 ] , '0x12345678' ) ;
@@ -210,6 +203,20 @@ describe('DevicePublish', () => {
210
203
chai . assert . deepEqual ( zigbee . publish . getCall ( 0 ) . args [ 5 ] , cfg . default ) ;
211
204
chai . assert . deepEqual ( zigbee . publish . getCall ( 0 ) . args [ 6 ] , null ) ;
212
205
} ) ;
206
+
207
+ it ( 'Should publish 1 message when brightness with state is send' , ( ) => {
208
+ zigbee . publish . resetHistory ( ) ;
209
+ zigbee . getDevice = sinon . fake . returns ( { modelId : 'TRADFRI bulb E27 CWS opal 600lm' } ) ;
210
+ devicePublish . onMQTTMessage ( 'zigbee2mqtt/0x12345678/set' , JSON . stringify ( { state : 'ON' , brightness : '50' } ) ) ;
211
+ chai . assert . isTrue ( zigbee . publish . calledOnce ) ;
212
+ chai . assert . strictEqual ( zigbee . publish . getCall ( 0 ) . args [ 0 ] , '0x12345678' ) ;
213
+ chai . assert . strictEqual ( zigbee . publish . getCall ( 0 ) . args [ 1 ] , 'genLevelCtrl' ) ;
214
+ chai . assert . strictEqual ( zigbee . publish . getCall ( 0 ) . args [ 2 ] , 'moveToLevelWithOnOff' ) ;
215
+ chai . assert . strictEqual ( zigbee . publish . getCall ( 0 ) . args [ 3 ] , 'functional' ) ;
216
+ chai . assert . deepEqual ( zigbee . publish . getCall ( 0 ) . args [ 4 ] , { level : '50' , transtime : 0 } ) ;
217
+ chai . assert . deepEqual ( zigbee . publish . getCall ( 0 ) . args [ 5 ] , cfg . default ) ;
218
+ chai . assert . deepEqual ( zigbee . publish . getCall ( 0 ) . args [ 6 ] , null ) ;
219
+ } ) ;
213
220
} ) ;
214
221
215
222
describe ( 'Parse topic' , ( ) => {
0 commit comments