mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-12-12 05:07:36 -06:00
Improve device selection and show device by id if available (#2476)
This commit is contained in:
parent
6a0206c1e7
commit
e024c3e38d
@ -311,12 +311,13 @@ class UiOptions(CoreSysAttributes):
|
|||||||
if match.group("filter"):
|
if match.group("filter"):
|
||||||
device_filter = _create_device_filter(match.group("filter"))
|
device_filter = _create_device_filter(match.group("filter"))
|
||||||
ui_node["options"] = [
|
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)
|
for device in self.sys_hardware.filter_devices(**device_filter)
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
ui_node["options"] = [
|
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)
|
ui_schema.append(ui_node)
|
||||||
|
|||||||
@ -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."""
|
"""Test with group schema."""
|
||||||
assert UiOptions(coresys)(
|
assert UiOptions(coresys)(
|
||||||
{
|
{
|
||||||
@ -201,3 +201,54 @@ def test_ui_group_list(coresys):
|
|||||||
"type": "schema",
|
"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"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user