@@ -152,14 +152,16 @@ async def _version():
152152 app ._api .version = mock .MagicMock (
153153 side_effect = _version )
154154
155- await app .startup (auto_form = False )
156- assert app .form_network .call_count == 0
157- await app .startup (auto_form = True )
158- assert app .form_network .call_count == 1
155+ with mock .patch ('zigpy_deconz.zigbee.application.ConBeeDevice' ) as con :
156+ con .new .side_effect = asyncio .coroutine (mock .MagicMock ())
157+ await app .startup (auto_form = False )
158+ assert app .form_network .call_count == 0
159+ await app .startup (auto_form = True )
160+ assert app .form_network .call_count == 1
159161
160162
161163@pytest .mark .asyncio
162- async def test_permit (app ):
164+ async def test_permit (app , nwk ):
163165 app ._api .write_parameter = mock .MagicMock (
164166 side_effect = asyncio .coroutine (mock .MagicMock ()))
165167 time_s = 30
@@ -187,7 +189,7 @@ def aps_data_request(req_id, dst_addr_ep, profile, cluster, src_ep, data):
187189 app .get_device = mock .MagicMock (
188190 return_value = zigpy .device .Device (app ,
189191 mock .sentinel .ieee ,
190- mock . sentinel . nwk ))
192+ nwk ))
191193
192194 return await app .request (nwk , 0x0260 , 1 , 2 , 3 , seq , b'\x01 \x02 \x03 ' , expect_reply = expect_reply , ** kwargs )
193195
@@ -306,3 +308,54 @@ def test_rx_device_annce(app, addr_ieee, addr_nwk):
306308 assert app .handle_join .call_args [0 ][0 ] == addr_nwk .address
307309 assert app .handle_join .call_args [0 ][1 ] == addr_ieee .address
308310 assert app .handle_join .call_args [0 ][2 ] == 0
311+
312+
313+ @pytest .mark .asyncio
314+ async def test_conbee_dev_add_to_group (app , nwk ):
315+ group = mock .MagicMock ()
316+ app ._groups = mock .MagicMock ()
317+ app ._groups .add_group .return_value = group
318+
319+ conbee = application .ConBeeDevice (app , mock .sentinel .ieee , nwk )
320+
321+ await conbee .add_to_group (mock .sentinel .grp_id , mock .sentinel .grp_name )
322+ assert group .add_member .call_count == 1
323+
324+ assert app .groups .add_group .call_count == 1
325+ assert app .groups .add_group .call_args [0 ][0 ] is mock .sentinel .grp_id
326+ assert app .groups .add_group .call_args [0 ][1 ] is mock .sentinel .grp_name
327+
328+
329+ @pytest .mark .asyncio
330+ async def test_conbee_dev_remove_from_group (app , nwk ):
331+ group = mock .MagicMock ()
332+ app .groups [mock .sentinel .grp_id ] = group
333+ conbee = application .ConBeeDevice (app ,
334+ mock .sentinel .ieee , nwk )
335+
336+ await conbee .remove_from_group (mock .sentinel .grp_id )
337+ assert group .remove_member .call_count == 1
338+
339+
340+ def test_conbee_props (nwk ):
341+ conbee = application .ConBeeDevice (app , mock .sentinel .ieee , nwk )
342+ assert conbee .manufacturer is not None
343+ assert conbee .model is not None
344+
345+
346+ @pytest .mark .asyncio
347+ async def test_conbee_new (app , nwk , monkeypatch ):
348+ mock_init = mock .MagicMock (
349+ side_effect = asyncio .coroutine (mock .MagicMock ())
350+ )
351+ monkeypatch .setattr (zigpy .device .Device , '_initialize' , mock_init )
352+
353+ conbee = await application .ConBeeDevice .new (app , mock .sentinel .ieee , nwk )
354+ assert isinstance (conbee , zigpy_deconz .zigbee .application .ConBeeDevice )
355+ assert mock_init .call_count == 1
356+ mock_init .reset_mock ()
357+
358+ app .devices [mock .sentinel .ieee ] = mock .MagicMock ()
359+ conbee = await application .ConBeeDevice .new (app , mock .sentinel .ieee , nwk )
360+ assert isinstance (conbee , zigpy_deconz .zigbee .application .ConBeeDevice )
361+ assert mock_init .call_count == 0
0 commit comments