@@ -26,21 +26,21 @@ const mockBonjourResult = jest.fn().mockImplementation((type) => ({
26
26
name : 'Mock Adapter' ,
27
27
type : `${ type } _mdns` ,
28
28
port : '1122' ,
29
+ host : 'mock_adapter.local' ,
29
30
addresses : [ '192.168.1.123' ] ,
30
31
txt : {
31
32
radio_type : `${ type } ` ,
32
- baud_rate : 115200 ,
33
33
} ,
34
34
} ) ) ;
35
- const mockBonjourFindOne = jest . fn ( ) . mockImplementation ( ( opts : BrowserConfig | null , timeout : number , callback ?: CallableFunction ) => {
35
+ const mockBonjourFindOne = jest . fn ( ( opts : BrowserConfig | null , timeout : number , callback ?: CallableFunction ) => {
36
36
if ( callback ) {
37
37
callback ( mockBonjourResult ( opts ?. type ) ) ;
38
38
}
39
39
} ) ;
40
40
const mockBonjourDestroy = jest . fn ( ) ;
41
41
42
42
jest . mock ( 'bonjour-service' , ( ) => ( {
43
- Bonjour : jest . fn ( ) . mockImplementation ( ( ) => ( {
43
+ Bonjour : jest . fn ( ( ) => ( {
44
44
findOne : mockBonjourFindOne ,
45
45
destroy : mockBonjourDestroy ,
46
46
} ) ) ,
@@ -71,7 +71,6 @@ describe('Adapter', () => {
71
71
expect ( adapter ) . toBeInstanceOf ( adapterCls ) ;
72
72
// @ts -expect-error protected
73
73
expect ( adapter . serialPortOptions ) . toStrictEqual ( {
74
- baudRate : 115200 ,
75
74
path : 'tcp://192.168.1.123:1122' ,
76
75
adapter : name ,
77
76
} ) ;
@@ -83,12 +82,31 @@ describe('Adapter', () => {
83
82
expect ( adapter ) . toBeInstanceOf ( ZStackAdapter ) ;
84
83
// @ts -expect-error protected
85
84
expect ( adapter . serialPortOptions ) . toStrictEqual ( {
86
- baudRate : 115200 ,
87
85
path : 'tcp://192.168.1.123:1122' ,
88
86
adapter : 'zstack' ,
89
87
} ) ;
90
88
} ) ;
91
89
90
+ it ( 'falls back to host if no addresses' , async ( ) => {
91
+ mockBonjourResult . mockReturnValueOnce ( {
92
+ name : 'Mock Adapter' ,
93
+ type : `my_adapter_mdns` ,
94
+ port : '1122' ,
95
+ host : 'mock_adapter.local' ,
96
+ txt : {
97
+ radio_type : `zstack` ,
98
+ } ,
99
+ } ) ;
100
+ const adapter = await Adapter . create ( { panID : 0x1a62 , channelList : [ 11 ] } , { path : `mdns://zstack` } , 'test.db.backup' , { disableLED : false } ) ;
101
+
102
+ expect ( adapter ) . toBeInstanceOf ( ZStackAdapter ) ;
103
+ // @ts -expect-error protected
104
+ expect ( adapter . serialPortOptions ) . toStrictEqual ( {
105
+ path : 'tcp://mock_adapter.local:1122' ,
106
+ adapter : `zstack` ,
107
+ } ) ;
108
+ } ) ;
109
+
92
110
it ( 'times out' , async ( ) => {
93
111
mockBonjourResult . mockReturnValueOnce ( null ) ;
94
112
const fakeAdapterName = 'mdns_test_device' ;
@@ -109,10 +127,10 @@ describe('Adapter', () => {
109
127
name : 'Mock Adapter' ,
110
128
type : `my_adapter_mdns` ,
111
129
port : '1122' ,
130
+ host : 'my_adapter.local' ,
112
131
addresses : [ '192.168.1.123' ] ,
113
132
txt : {
114
133
radio_type : undefined ,
115
- baud_rate : 115200 ,
116
134
} ,
117
135
} ) ;
118
136
@@ -121,15 +139,13 @@ describe('Adapter', () => {
121
139
} ) . rejects . toThrow (
122
140
`Coordinator returned wrong Zeroconf format! The following values are expected:\n` +
123
141
`txt.radio_type, got: undefined\n` +
124
- `txt.baud_rate, got: 115200\n` +
125
- `address, got: 192.168.1.123\n` +
126
142
`port, got: 1122` ,
127
143
) ;
128
144
} ) ;
129
145
} ) ;
130
146
131
147
describe ( 'TCP discovery' , ( ) => {
132
- it ( 'returns config' , async ( ) => {
148
+ it ( 'returns config with tcp path ' , async ( ) => {
133
149
const adapter = await Adapter . create (
134
150
{ panID : 0x1a62 , channelList : [ 11 ] } ,
135
151
{ path : `tcp://192.168.1.321:3456` , adapter : `zstack` } ,
@@ -144,6 +160,21 @@ describe('Adapter', () => {
144
160
} ) ;
145
161
} ) ;
146
162
163
+ it ( 'returns config with socket path' , async ( ) => {
164
+ const adapter = await Adapter . create (
165
+ { panID : 0x1a62 , channelList : [ 11 ] } ,
166
+ { path : `socket://192.168.1.321:3456` , adapter : `zstack` } ,
167
+ 'test.db.backup' ,
168
+ { disableLED : false } ,
169
+ ) ;
170
+
171
+ // @ts -expect-error protected
172
+ expect ( adapter . serialPortOptions ) . toStrictEqual ( {
173
+ path : `tcp://192.168.1.321:3456` ,
174
+ adapter : `zstack` ,
175
+ } ) ;
176
+ } ) ;
177
+
147
178
it ( 'invalid path' , async ( ) => {
148
179
expect ( async ( ) => {
149
180
await Adapter . create ( { panID : 0x1a62 , channelList : [ 11 ] } , { path : `tcp://192168.1.321:3456` , adapter : `zstack` } , 'test.db.backup' , {
@@ -177,24 +208,26 @@ describe('Adapter', () => {
177
208
it ( 'detects each adapter' , async ( ) => {
178
209
listSpy . mockReturnValueOnce ( [ DECONZ_CONBEE_II ] ) ;
179
210
180
- let adapter = await Adapter . create ( { panID : 0x1a62 , channelList : [ 11 ] } , { } , 'test.db.backup' , { disableLED : false } ) ;
211
+ let adapter = await Adapter . create ( { panID : 0x1a62 , channelList : [ 11 ] } , { baudRate : 57600 } , 'test.db.backup' , { disableLED : false } ) ;
181
212
182
213
expect ( adapter ) . toBeInstanceOf ( DeconzAdapter ) ;
183
214
// @ts -expect-error protected
184
215
expect ( adapter . serialPortOptions ) . toStrictEqual ( {
185
216
path : DECONZ_CONBEE_II . path ,
186
217
adapter : 'deconz' ,
218
+ baudRate : 57600 ,
187
219
} ) ;
188
220
189
221
listSpy . mockReturnValueOnce ( [ EMBER_ZBDONGLE_E ] ) ;
190
222
191
- adapter = await Adapter . create ( { panID : 0x1a62 , channelList : [ 11 ] } , { } , 'test.db.backup' , { disableLED : false } ) ;
223
+ adapter = await Adapter . create ( { panID : 0x1a62 , channelList : [ 11 ] } , { baudRate : 115200 } , 'test.db.backup' , { disableLED : false } ) ;
192
224
193
225
expect ( adapter ) . toBeInstanceOf ( EmberAdapter ) ;
194
226
// @ts -expect-error protected
195
227
expect ( adapter . serialPortOptions ) . toStrictEqual ( {
196
228
path : EMBER_ZBDONGLE_E . path ,
197
229
adapter : 'ember' ,
230
+ baudRate : 115200 ,
198
231
} ) ;
199
232
200
233
listSpy . mockReturnValueOnce ( [ ZSTACK_CC2538 ] ) ;
0 commit comments