async def test_handleMessage_onMessage(node: Node): # Test catch all message handler listener = MagicMock() node.addListener(listener) listener.onMessage.return_value = True assert await node.handleMessage(Basic.Report(value=0), 0) is True listener.onMessage.return_value = False assert await node.handleMessage(Basic.Report(value=0), 0) is False
async def test_messageReceived(app: Application): handler = MagicMock() handler.onSet.return_value = False # Do not handle these messages cmdClass = app.nodes["3:0"].supported[Basic.COMMAND_CLASS_BASIC] cmdClass.addListener(handler) assert await app.messageReceived(None, 4, 0, Basic.Report(value=42), 0) is False assert await app.messageReceived(None, 3, 0, Basic.Report(value=42), 0) is True assert await app.messageReceived(None, 3, 0, Basic.Set(value=0), 0) is False handler.onReport.assert_called_once_with(cmdClass, Basic.Report(value=42), 0) assert (await app.messageReceived(None, app.adapter.nodeId, 0, Basic.Report(value=42), 0) is True)
async def test_sendAndReceive(node: Node): async def noop(_): return True node.send = noop values = await asyncio.gather( node.sendAndReceive(Basic.Get(), Basic.Report), runDelayed(node.messageReceived, Basic.Report()), ) assert isinstance(values[0], Basic.Report)
async def test_sendAndReceive(adapter: Adapter): async def noop(_): pass adapter.send = noop # Throws not implemented as default values = await asyncio.gather( adapter.sendAndReceive(Basic.Get(), Basic.Report), runDelayed(adapter.commandReceived, Basic.Report()), ) assert isinstance(values[0], Basic.Report)
async def test_supervision_not_handled(node: Node): supervision = Supervision.Get(statusUpdates=False, sessionID=42, command=Basic.Report(value=1)) assert await node.handleMessage(supervision, 0) is False node._adapter.sendToNode.assert_called_with( node.rootNodeId, Supervision.Report( moreStatusUpdates=False, wakeUpRequest=False, sessionID=supervision.sessionID, status=0x0, duration=0, ), destEP=0, sourceEP=0, timeout=3, )
def test_commandReceived(adapter: Adapter): adapter.messageReceived = MagicMock() adapter.commandReceived(Zip.ZipPacket(command=Basic.Report(value=0))) adapter.messageReceived.assert_called_once_with(Basic.Report(value=0))