|
| 1 | +"""Test the config manager.""" |
| 2 | + |
| 3 | +from zwave_js_server.client import Client |
| 4 | +from zwave_js_server.model.config_manager import ConfigManager |
| 5 | +from zwave_js_server.model.device_config import DeviceConfigDataType |
| 6 | + |
| 7 | +from ..common import MockCommandProtocol |
| 8 | + |
| 9 | + |
| 10 | +async def test_lookup_device( |
| 11 | + client: Client, |
| 12 | + mock_command: MockCommandProtocol, |
| 13 | + device_config: DeviceConfigDataType, |
| 14 | +) -> None: |
| 15 | + """Test the lookup_device command.""" |
| 16 | + # Test successful lookup |
| 17 | + mock_command( |
| 18 | + { |
| 19 | + "command": "config_manager.lookup_device", |
| 20 | + "manufacturerId": 0x1234, |
| 21 | + "productType": 0x5678, |
| 22 | + "productId": 0x9ABC, |
| 23 | + }, |
| 24 | + {"config": device_config}, |
| 25 | + ) |
| 26 | + |
| 27 | + config_manager = ConfigManager(client) |
| 28 | + result = await config_manager.lookup_device(0x1234, 0x5678, 0x9ABC) |
| 29 | + |
| 30 | + assert result is not None |
| 31 | + assert result.manufacturer == "Test Manufacturer" |
| 32 | + assert result.manufacturer_id == "0x1234" |
| 33 | + assert result.label == "Test Device" |
| 34 | + assert result.description == "Test Device Description" |
| 35 | + assert len(result.devices) == 1 |
| 36 | + assert result.devices[0].product_type == "0x5678" |
| 37 | + assert result.devices[0].product_id == "0x9ABC" |
| 38 | + assert result.firmware_version.min == "1.0" |
| 39 | + assert result.firmware_version.max == "2.0" |
| 40 | + |
| 41 | + # Test lookup with firmware version |
| 42 | + mock_command( |
| 43 | + { |
| 44 | + "command": "config_manager.lookup_device", |
| 45 | + "manufacturerId": 0x1234, |
| 46 | + "productType": 0x5678, |
| 47 | + "productId": 0x9ABC, |
| 48 | + "firmwareVersion": "1.5", |
| 49 | + }, |
| 50 | + {"config": device_config}, |
| 51 | + ) |
| 52 | + |
| 53 | + result = await config_manager.lookup_device(0x1234, 0x5678, 0x9ABC, "1.5") |
| 54 | + |
| 55 | + assert result is not None |
| 56 | + assert result.manufacturer == "Test Manufacturer" |
| 57 | + |
| 58 | + assert result.to_dict() == device_config |
| 59 | + |
| 60 | + # Test device not found |
| 61 | + mock_command( |
| 62 | + { |
| 63 | + "command": "config_manager.lookup_device", |
| 64 | + "manufacturerId": 0x4321, |
| 65 | + "productType": 0x8765, |
| 66 | + "productId": 0xCBA9, |
| 67 | + }, |
| 68 | + {"config": None}, |
| 69 | + ) |
| 70 | + |
| 71 | + result = await config_manager.lookup_device(0x4321, 0x8765, 0xCBA9) |
| 72 | + |
| 73 | + assert result is None |
0 commit comments