Ejemplo n.º 1
0
def test_ctor_mapping():
    """Make sure the constructor accepts the mapping parameter."""
    dev = MiotDevice("127.0.0.1", "68ffffffffffffffffffffffffffffff")
    assert dev.mapping is None

    test_mapping = {}
    dev2 = MiotDevice("127.0.0.1",
                      "68ffffffffffffffffffffffffffffff",
                      mapping=test_mapping)
    assert dev2.mapping == test_mapping
Ejemplo n.º 2
0
def dev(module_mocker):
    DUMMY_MAPPING = {}
    device = MiotDevice("127.0.0.1",
                        "68ffffffffffffffffffffffffffffff",
                        mapping=DUMMY_MAPPING)
    module_mocker.patch.object(device, "send")
    return device
Ejemplo n.º 3
0
def connect_miot_device(ip, force=False):
    if ip in miot_devs and not force:
        return miot_devs[ip]
    d = dev_model[ip]
    try:
        miot_devs[ip] = MiotDevice(ip, d['token'], lazy_discover=False)
        d['error'] = None
    except DeviceException as e:
        error(f'{format(e)} {d["name"]}')
        d['error'] = f'cannot connect this device'
        return None
    return miot_devs[ip]
Ejemplo n.º 4
0
import math

import pytest

from miio import Device, MiotDevice, RoborockVacuum
from miio.exceptions import DeviceInfoUnavailableException, PayloadDecodeException

DEVICE_CLASSES = Device.__subclasses__() + MiotDevice.__subclasses__(
)  # type: ignore
DEVICE_CLASSES.remove(MiotDevice)


@pytest.mark.parametrize("max_properties", [None, 1, 15])
def test_get_properties_splitting(mocker, max_properties):
    properties = [i for i in range(20)]

    send = mocker.patch("miio.Device.send")
    d = Device("127.0.0.1", "68ffffffffffffffffffffffffffffff")
    d.get_properties(properties, max_properties=max_properties)

    if max_properties is None:
        max_properties = len(properties)
    assert send.call_count == math.ceil(len(properties) / max_properties)


def test_default_timeout_and_retry(mocker):
    send = mocker.patch("miio.miioprotocol.MiIOProtocol.send")
    d = Device("127.0.0.1", "68ffffffffffffffffffffffffffffff")
    assert d._protocol._timeout == 5
    d.send(command="fake_command", parameters=[])
    send.assert_called_with("fake_command", [], 3, extra_parameters=None)
Ejemplo n.º 5
0
def dev(module_mocker):
    device = MiotDevice("127.0.0.1", "68ffffffffffffffffffffffffffffff")
    module_mocker.patch.object(device, "send")
    return device
Ejemplo n.º 6
0
def test_missing_mapping():
    """Make sure ctor raises exception if neither class nor parameter defines the
    mapping."""
    with pytest.raises(DeviceException):
        _ = MiotDevice("127.0.0.1", "68ffffffffffffffffffffffffffffff")
Ejemplo n.º 7
0
def test_missing_mapping(caplog):
    """Make sure ctor raises exception if neither class nor parameter defines the
    mapping."""
    _ = MiotDevice("127.0.0.1", "68ffffffffffffffffffffffffffffff")
    assert "Neither the class nor the parameter defines the mapping" in caplog.text
Ejemplo n.º 8
0
import pytest

from miio import Huizuo, MiotDevice
from miio.miot_device import MiotValueType

MIOT_DEVICES = MiotDevice.__subclasses__()
# TODO: huizuo needs to be refactored to use _mappings,
# until then, just disable the tests on it.
MIOT_DEVICES.remove(Huizuo)  # type: ignore


@pytest.fixture(scope="module")
def dev(module_mocker):
    DUMMY_MAPPING = {}
    device = MiotDevice("127.0.0.1",
                        "68ffffffffffffffffffffffffffffff",
                        mapping=DUMMY_MAPPING)
    module_mocker.patch.object(device, "send")
    return device


def test_missing_mapping(caplog):
    """Make sure ctor raises exception if neither class nor parameter defines the
    mapping."""
    _ = MiotDevice("127.0.0.1", "68ffffffffffffffffffffffffffffff")
    assert "Neither the class nor the parameter defines the mapping" in caplog.text


def test_ctor_mapping():
    """Make sure the constructor accepts the mapping parameter."""
    test_mapping = {}