Esempio n. 1
0
async def test_remove(node: Node):
    node._nodeId = 1  # Triggers Status.REMOVE_FAIL
    assert await node.remove() is False
    node._nodeId = 2  # Triggers Status.NOT_FOUND
    assert await node.remove() is False
    node._nodeId = 3  # Triggers Status.DONE
    assert await node.remove() is True
Esempio n. 2
0
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
Esempio n. 3
0
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)
Esempio n. 4
0
async def test_handleMessage(node: Node):
    # Skip handlers, when there is a session wating for the message
    node.addWaitingSession(Basic.Get)
    assert await node.handleMessage(Basic.Get(), 0) is True

    # Try again without any sessions
    assert await node.handleMessage(Basic.Get(), 0) is False

    # Send message with handler
    assert (await node.handleMessage(
        AssociationGrpInfo.GroupNameReport(groupingsIdentifier=1,
                                           name="Lifeline"),
        0,
    ) is True)
Esempio n. 5
0
async def test_interview(mocknode: Node):
    mocknode.queue(
        Version.VersionCommandClassReport(
            requestedCommandClass=Version.COMMAND_CLASS_VERSION,
            commandClassVersion=4,
        ))
    mocknode.queue(
        Version.VersionReport(
            zwaveLibraryType=6,
            zwaveProtocolVersion=1,
            zwaveProtocolSubVersion=2,
            applicationVersion=1,
            applicationSubVersion=0,
        ))
    await mocknode.interview()
    assert mocknode.supported[Version.COMMAND_CLASS_VERSION].version == 4
Esempio n. 6
0
async def test_sendAndReceive_no_wakeup(node: Node):
    async def noop(_):
        return False

    node.send = noop
    with pytest.raises(asyncio.TimeoutError):
        await node.sendAndReceive(Basic.Get(), Basic.Report)
Esempio n. 7
0
def app() -> Application:
    async def getFailedNodeList():
        return [2]

    async def getMultiChannelCapability(_, __):
        return NetworkManagementProxy.MultiChannelCapabilityReport(
            commandClass=b"")

    async def getMultiChannelEndPoints(_):
        return 1

    async def getNodeInfo(_):
        return NetworkManagementProxy.NodeInfoCachedReport(
            commandClass=bytes([COMMAND_CLASS_MULTI_CHANNEL_V2]))

    async def getNodeList():
        return [1, 2, 3]

    adapter = AdapterImpl()
    app = Application(adapter, None)
    app._nodes = {"3:0": Node(3, adapter, [Basic.COMMAND_CLASS_BASIC])}
    app.adapter.getFailedNodeList = getFailedNodeList
    app.adapter.getMultiChannelCapability = getMultiChannelCapability
    app.adapter.getMultiChannelEndPoints = getMultiChannelEndPoints
    app.adapter.getNodeInfo = getNodeInfo
    app.adapter.getNodeList = getNodeList
    return app
Esempio n. 8
0
async def test_supervision_handled(node: Node):
    supervision = Supervision.Get(statusUpdates=False,
                                  sessionID=42,
                                  command=Basic.Report(value=1))
    node.addWaitingSession(Basic.Report)
    assert await node.handleMessage(supervision, 0) is True
    node._adapter.sendToNode.assert_called_with(
        node.rootNodeId,
        Supervision.Report(
            moreStatusUpdates=False,
            wakeUpRequest=False,
            sessionID=supervision.sessionID,
            status=0xFF,
            duration=0,
        ),
        destEP=0,
        sourceEP=0,
        timeout=3,
    )
Esempio n. 9
0
def test_storageLock(node: Node):
    listener = MagicMock()
    node.addListener(listener)
    node.commandClassUpdated(None)
    listener.nodeUpdated.assert_called_once()

    listener.reset_mock()
    with node.storageLock():
        node.commandClassUpdated(None)
        node.commandClassUpdated(None)
        listener.nodeUpdated.assert_not_called()
    listener.nodeUpdated.assert_called_once()
Esempio n. 10
0
def node() -> Node:
    connection = ZIPConnection(None, None)
    future = asyncio.Future()
    future.set_result(True)
    connection.sendToNode = MagicMock()
    connection.sendToNode.return_value = future
    return Node(
        2,
        connection,
        [
            ZwavePlusInfo.COMMAND_CLASS_ZWAVEPLUS_INFO,
            AssociationGrpInfo.COMMAND_CLASS_ASSOCIATION_GRP_INFO,
        ],
    )
Esempio n. 11
0
    async def loadNode(self, nodeId: int) -> list:
        """Load a node"""
        if nodeId == self.adapter.nodeId:
            # Ignore ourself
            return []
        nodes = []
        nodeInfo = await self.adapter.getNodeInfo(nodeId)
        node = Node(nodeId, self.adapter, list(nodeInfo.commandClass))
        nodes.append(node)
        node.addListener(self._storage)
        node.basicDeviceClass = nodeInfo.basicDeviceClass
        # node.flirs = ?
        node.genericDeviceClass = nodeInfo.genericDeviceClass
        # node.isFailed = ?
        node.listening = nodeInfo.listening
        node.specificDeviceClass = nodeInfo.specificDeviceClass
        self._nodes[node.nodeId] = node

        if node.supports(COMMAND_CLASS_MULTI_CHANNEL_V2):
            endpoints = await self.adapter.getMultiChannelEndPoints(nodeId)
            for endpoint in range(1, endpoints + 1):
                nodes.append(await self.loadEndPointNode(node, endpoint))
        return nodes
Esempio n. 12
0
def test_flirs(node: Node):
    assert node.flirs is False
    node.flirs = True
    assert node.flirs is True
Esempio n. 13
0
def test_endpoint(node: Node):
    assert node.endpoint == 0
    node.endpoint = 2
    assert node.endpoint == 2
Esempio n. 14
0
def test_basicdeviceclass(node: Node):
    assert node.basicDeviceClass == 0
    node.basicDeviceClass = 2
    assert node.basicDeviceClass == 2
Esempio n. 15
0
def nodeendpoint() -> Node:
    connection = ZIPConnection(None, None)
    node = Node(2, connection, [ZwavePlusInfo.COMMAND_CLASS_ZWAVEPLUS_INFO])
    return NodeEndPoint(node, 1, connection, [])
Esempio n. 16
0
def test_specificdeviceclass(node: Node):
    assert node.specificDeviceClass == 0
    node.specificDeviceClass = 2
    assert node.specificDeviceClass == 2
Esempio n. 17
0
def commandclass() -> CommandClass:
    node = Node(1, Adapter(), [])
    return CommandClass.load(0, False, node)
Esempio n. 18
0
def test_genericdeviceclass(node: Node):
    assert node.genericDeviceClass == 0
    node.genericDeviceClass = 2
    assert node.genericDeviceClass == 2
Esempio n. 19
0
def test_isFailed(node: Node):
    assert node.isFailed is False
    node.isFailed = True
    assert node.isFailed is True
Esempio n. 20
0
def test_listening(node: Node):
    assert node.listening is False
    node.listening = True
    assert node.listening is True