File: test_config_manager.py

package info (click to toggle)
zwave-js-server-python 0.67.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,820 kB
  • sloc: python: 15,886; sh: 21; javascript: 16; makefile: 2
file content (73 lines) | stat: -rw-r--r-- 2,180 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""Test the config manager."""

from zwave_js_server.client import Client
from zwave_js_server.model.config_manager import ConfigManager
from zwave_js_server.model.device_config import DeviceConfigDataType

from ..common import MockCommandProtocol


async def test_lookup_device(
    client: Client,
    mock_command: MockCommandProtocol,
    device_config: DeviceConfigDataType,
) -> None:
    """Test the lookup_device command."""
    # Test successful lookup
    mock_command(
        {
            "command": "config_manager.lookup_device",
            "manufacturerId": 0x1234,
            "productType": 0x5678,
            "productId": 0x9ABC,
        },
        {"config": device_config},
    )

    config_manager = ConfigManager(client)
    result = await config_manager.lookup_device(0x1234, 0x5678, 0x9ABC)

    assert result is not None
    assert result.manufacturer == "Test Manufacturer"
    assert result.manufacturer_id == "0x1234"
    assert result.label == "Test Device"
    assert result.description == "Test Device Description"
    assert len(result.devices) == 1
    assert result.devices[0].product_type == "0x5678"
    assert result.devices[0].product_id == "0x9ABC"
    assert result.firmware_version.min == "1.0"
    assert result.firmware_version.max == "2.0"

    # Test lookup with firmware version
    mock_command(
        {
            "command": "config_manager.lookup_device",
            "manufacturerId": 0x1234,
            "productType": 0x5678,
            "productId": 0x9ABC,
            "firmwareVersion": "1.5",
        },
        {"config": device_config},
    )

    result = await config_manager.lookup_device(0x1234, 0x5678, 0x9ABC, "1.5")

    assert result is not None
    assert result.manufacturer == "Test Manufacturer"

    assert result.to_dict() == device_config

    # Test device not found
    mock_command(
        {
            "command": "config_manager.lookup_device",
            "manufacturerId": 0x4321,
            "productType": 0x8765,
            "productId": 0xCBA9,
        },
        {"config": None},
    )

    result = await config_manager.lookup_device(0x4321, 0x8765, 0xCBA9)

    assert result is None