diff --git a/supervisor/addons/options.py b/supervisor/addons/options.py index ca73120f8..ab5299c9e 100644 --- a/supervisor/addons/options.py +++ b/supervisor/addons/options.py @@ -311,12 +311,13 @@ class UiOptions(CoreSysAttributes): if match.group("filter"): device_filter = _create_device_filter(match.group("filter")) ui_node["options"] = [ - device.path.as_posix() + (device.by_id or device.path).as_posix() for device in self.sys_hardware.filter_devices(**device_filter) ] else: ui_node["options"] = [ - device.path.as_posix() for device in self.sys_hardware.devices() + (device.by_id or device.path).as_posix() + for device in self.sys_hardware.devices() ] ui_schema.append(ui_node) diff --git a/tests/addons/test_options.py b/tests/addons/test_options.py index ef9f0a5ea..165dc2cf2 100644 --- a/tests/addons/test_options.py +++ b/tests/addons/test_options.py @@ -174,7 +174,7 @@ def test_ui_group_schema(coresys): ] -def test_ui_group_list(coresys): +def test_ui_group_list_schema(coresys): """Test with group schema.""" assert UiOptions(coresys)( { @@ -201,3 +201,54 @@ def test_ui_group_list(coresys): "type": "schema", }, ] + + +def test_ui_simple_device_schema(coresys): + """Test with simple schema.""" + for device in ( + Device( + "ttyACM0", + Path("/dev/ttyACM0"), + Path("/sys/bus/usb/002"), + "tty", + [], + {"ID_VENDOR": "xy"}, + ), + Device( + "ttyUSB0", + Path("/dev/ttyUSB0"), + Path("/sys/bus/usb/001"), + "tty", + [Path("/dev/ttyS1"), Path("/dev/serial/by-id/xyx")], + {"ID_VENDOR": "xy"}, + ), + Device("ttyS0", Path("/dev/ttyS0"), Path("/sys/bus/usb/003"), "tty", [], {}), + Device( + "video1", + Path("/dev/video1"), + Path("/sys/bus/usb/004"), + "misc", + [], + {"ID_VENDOR": "xy"}, + ), + ): + coresys.hardware.update_device(device) + + data = UiOptions(coresys)( + { + "name": "str", + "password": "password", + "fires": "bool", + "alias": "str?", + "input": "device(subsystem=tty)", + }, + ) + + assert sorted(data[-1]["options"]) == sorted( + [ + "/dev/serial/by-id/xyx", + "/dev/ttyACM0", + "/dev/ttyS0", + ] + ) + assert data[-1]["type"] == "select"