Ejemplo n.º 1
0
def test_lock_clear_usercode_service(hass, mock_openzwave):
    """Test the zwave lock clear_usercode service."""
    mock_network = hass.data[zwave.zwave.DATA_NETWORK] = MagicMock()
    node = MockNode(node_id=12)
    value0 = MockValue(data=None, node=node, index=0)
    value1 = MockValue(data='123', node=node, index=1)
    yield from zwave.async_setup_platform(
        hass, {}, MagicMock())

    node.get_values.return_value = {
        value0.value_id: value0,
        value1.value_id: value1,
    }

    mock_network.nodes = {
        node.node_id: node
    }
    yield from hass.services.async_call(
        zwave.DOMAIN, zwave.SERVICE_CLEAR_USERCODE, {
            const.ATTR_NODE_ID: node.node_id,
            zwave.ATTR_CODE_SLOT: 1
        })
    yield from hass.async_block_till_done()

    assert value1.data == '\0\0\0'
Ejemplo n.º 2
0
def test_lock_get_usercode_service(hass, mock_openzwave):
    """Test the zwave lock get_usercode service."""
    mock_network = hass.data[zwave.zwave.DATA_NETWORK] = MagicMock()
    node = MockNode(node_id=12)
    value0 = MockValue(data=None, node=node, index=0)
    value1 = MockValue(data='1234', node=node, index=1)
    yield from zwave.async_setup_platform(
        hass, {}, MagicMock())

    node.get_values.return_value = {
        value0.value_id: value0,
        value1.value_id: value1,
    }

    with patch.object(zwave, '_LOGGER') as mock_logger:
        mock_network.nodes = {node.node_id: node}
        yield from hass.services.async_call(
            zwave.DOMAIN, zwave.SERVICE_GET_USERCODE, {
                const.ATTR_NODE_ID: node.node_id,
                zwave.ATTR_CODE_SLOT: 1,
                })
        yield from hass.async_block_till_done()
        # This service only seems to write to the log
        assert mock_logger.info.called
        assert len(mock_logger.info.mock_calls) == 1
        assert mock_logger.info.mock_calls[0][1][2] == '1234'
Ejemplo n.º 3
0
def test_lock_get_usercode_service(hass, mock_openzwave):
    """Test the zwave lock get_usercode service."""
    node = MockNode(node_id=12)
    value0 = MockValue(data=None, node=node, index=0)
    value1 = MockValue(data='1234', node=node, index=1)
    yield from zwave.async_setup_platform(hass, {}, MagicMock())

    node.get_values.return_value = {
        value0.value_id: value0,
        value1.value_id: value1,
    }

    with patch.object(zwave.zwave, 'NETWORK') as mock_network:
        with patch.object(zwave, '_LOGGER') as mock_logger:
            mock_network.nodes = {node.node_id: node}
            yield from hass.services.async_call(
                zwave.DOMAIN, zwave.SERVICE_GET_USERCODE, {
                    const.ATTR_NODE_ID: node.node_id,
                    zwave.ATTR_CODE_SLOT: 1,
                })
            yield from hass.async_block_till_done()

            # This service only seems to write to the log
            assert mock_logger.info.called
            assert len(mock_logger.info.mock_calls) == 1
            assert mock_logger.info.mock_calls[0][1][2] == '1234'
Ejemplo n.º 4
0
def test_lock_set_usercode_service(hass, mock_openzwave):
    """Test the zwave lock set_usercode service."""
    node = MockNode(node_id=12)
    value0 = MockValue(data=None, node=node, index=0)
    value1 = MockValue(data=None, node=node, index=1)
    yield from zwave.async_setup_platform(hass, {}, MagicMock())

    node.get_values.return_value = {
        value0.value_id: value0,
        value1.value_id: value1,
    }

    with patch.object(zwave.zwave, 'NETWORK') as mock_network:
        mock_network.nodes = {node.node_id: node}
        yield from hass.services.async_call(
            zwave.DOMAIN, zwave.SERVICE_SET_USERCODE, {
                const.ATTR_NODE_ID: node.node_id,
                zwave.ATTR_USERCODE: '1234',
                zwave.ATTR_CODE_SLOT: 1,
            })
        yield from hass.async_block_till_done()

    assert value1.data == '1234'

    with patch.object(zwave.zwave, 'NETWORK') as mock_network:
        mock_network.nodes = {node.node_id: node}
        yield from hass.services.async_call(
            zwave.DOMAIN, zwave.SERVICE_SET_USERCODE, {
                const.ATTR_NODE_ID: node.node_id,
                zwave.ATTR_USERCODE: '12345',
                zwave.ATTR_CODE_SLOT: 1,
            })
        yield from hass.async_block_till_done()

    assert value1.data == '1234'
Ejemplo n.º 5
0
def test_lock_clear_usercode_service(hass, mock_openzwave):
    """Test the zwave lock clear_usercode service."""
    mock_network = hass.data[zwave.zwave.ZWAVE_NETWORK] = MagicMock()
    node = MockNode(node_id=12)
    value0 = MockValue(data=None, node=node, index=0)
    value1 = MockValue(data='123', node=node, index=1)
    yield from zwave.async_setup_platform(
        hass, {}, MagicMock())

    node.get_values.return_value = {
        value0.value_id: value0,
        value1.value_id: value1,
    }

    mock_network.nodes = {
        node.node_id: node
    }
    yield from hass.services.async_call(
        zwave.DOMAIN, zwave.SERVICE_CLEAR_USERCODE, {
            const.ATTR_NODE_ID: node.node_id,
            zwave.ATTR_CODE_SLOT: 1
        })
    yield from hass.async_block_till_done()

    assert value1.data == '\0\0\0'
Ejemplo n.º 6
0
def test_lock_set_usercode_service(hass, mock_openzwave):
    """Test the zwave lock set_usercode service."""
    node = MockNode(node_id=12)
    value0 = MockValue(data=None, node=node, index=0)
    value1 = MockValue(data=None, node=node, index=1)
    yield from zwave.async_setup_platform(
        hass, {}, MagicMock())

    node.get_values.return_value = {
        value0.value_id: value0,
        value1.value_id: value1,
    }

    with patch.object(zwave.zwave, 'NETWORK') as mock_network:
        mock_network.nodes = {
            node.node_id: node
        }
        yield from hass.services.async_call(
            zwave.DOMAIN, zwave.SERVICE_SET_USERCODE, {
                const.ATTR_NODE_ID: node.node_id,
                zwave.ATTR_USERCODE: '1234',
                zwave.ATTR_CODE_SLOT: 1,
                })
        yield from hass.async_block_till_done()

    assert value1.data == '1234'

    with patch.object(zwave.zwave, 'NETWORK') as mock_network:
        mock_network.nodes = {
            node.node_id: node
        }
        yield from hass.services.async_call(
            zwave.DOMAIN, zwave.SERVICE_SET_USERCODE, {
                const.ATTR_NODE_ID: node.node_id,
                zwave.ATTR_USERCODE: '12345',
                zwave.ATTR_CODE_SLOT: 1,
                })
        yield from hass.async_block_till_done()

    assert value1.data == '1234'