async def _test_startup(app, nwk_type, ieee, auto_form=False, init=0, ezsp_version=4): nwk_params = bellows.types.struct.EmberNetworkParameters( extendedPanId=t.ExtendedPanId.convert("aa:bb:cc:dd:ee:ff:aa:bb"), panId=t.EmberPanId(0x55AA), radioTxPower=0, radioChannel=25, joinMethod=t.EmberJoinMethod.USE_MAC_ASSOCIATION, nwkManagerId=t.EmberNodeId(0x0000), nwkUpdateId=1, channels=t.Channels.ALL_CHANNELS, ) async def mock_leave(*args, **kwargs): app._ezsp.handle_callback("stackStatusHandler", [t.EmberStatus.NETWORK_DOWN]) return [t.EmberStatus.NETWORK_DOWN] app._in_flight_msg = None ezsp_mock = MagicMock() type(ezsp_mock).ezsp_version = PropertyMock(return_value=ezsp_version) ezsp_mock.initialize = AsyncMock(return_value=ezsp_mock) ezsp_mock.connect = AsyncMock() ezsp_mock.setConcentrator = AsyncMock() ezsp_mock._command = AsyncMock(return_value=t.EmberStatus.SUCCESS) ezsp_mock.addEndpoint = AsyncMock(return_value=t.EmberStatus.SUCCESS) ezsp_mock.setConfigurationValue = AsyncMock( return_value=t.EmberStatus.SUCCESS) ezsp_mock.networkInit = AsyncMock(return_value=[init]) ezsp_mock.getNetworkParameters = AsyncMock( return_value=[0, nwk_type, nwk_params]) ezsp_mock.get_board_info = AsyncMock(return_value=("Mock Manufacturer", "Mock board", "Mock version")) ezsp_mock.setPolicy = AsyncMock(return_value=[t.EmberStatus.SUCCESS]) ezsp_mock.getMfgToken = AsyncMock(return_value=(b"Some token\xff", )) ezsp_mock.getNodeId = AsyncMock(return_value=[t.EmberNodeId(0x0000)]) ezsp_mock.getEui64 = AsyncMock(return_value=[ieee]) ezsp_mock.getValue = AsyncMock(return_value=(0, b"\x01" * 6)) ezsp_mock.leaveNetwork = AsyncMock(side_effect=mock_leave) app.form_network = AsyncMock() ezsp_mock.reset = AsyncMock() ezsp_mock.version = AsyncMock() ezsp_mock.getConfigurationValue = AsyncMock(return_value=(0, 1)) ezsp_mock.update_policies = AsyncMock() p1 = patch.object(bellows.ezsp, "EZSP", new=ezsp_mock) p2 = patch.object(bellows.multicast.Multicast, "startup") with p1, p2 as multicast_mock: await app.startup(auto_form=auto_form) assert multicast_mock.await_count == 1
async def test_startup_ezsp_ver8(app, ieee): app.state.counters["ezsp_counters"] = MagicMock() ieee_1 = t.EmberEUI64.convert("11:22:33:44:55:66:77:88") dev_1 = app.add_device(ieee_1, 0x1234) dev_1.relays = [ t.EmberNodeId(0x2222), ] await _test_startup(app, t.EmberNodeType.COORDINATOR, ieee, ezsp_version=8) assert app.state.counters["ezsp_counters"].reset.call_count == 1
def test_handle_id_conflict(app, ieee): """Test handling of an ID conflict report.""" nwk = t.EmberNodeId(0x1234) app.add_device(ieee, nwk) app.handle_leave = MagicMock() app.ezsp_callback_handler("idConflictHandler", [nwk + 1]) assert app.handle_leave.call_count == 0 app.ezsp_callback_handler("idConflictHandler", [nwk]) assert app.handle_leave.call_count == 1 assert app.handle_leave.call_args[0][0] == nwk