mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-06-21 01:16:29 +00:00

* Next generation hardware handling * need daemon for some details * fix tests * fix wrong coresys lookup * test initial import * test device lookup * validate if device exists * Add cgroups rules manager * mapping udev from host * Modify validation/options handling * lookup devices * add support for host udev mapping * next * Add policy support to add-ons * Depricate hardware trigger call * next cleanup round * detect USB linking * optimize * readd udev utils for backwards compatibility * fix tests * Add more tests * fix tests * Make device explicit * Add filter * work on tests * Add migration step * clean out auto_uart * Fix all tests * Expose all device information * small improvment * Fix loop over right devices * Use migration for new device format * Update rootfs/etc/cont-init.d/udev.sh Co-authored-by: Franck Nijhof <git@frenck.dev> * Fix old helper * Fix API * add helper for by-id * fix tests * Fix serial helper * Fix hardware API schema * Hide some virtual devices from tracking * Apply suggestions from code review Co-authored-by: Stefan Agner <stefan@agner.ch> * Update supervisor/addons/validate.py Co-authored-by: Stefan Agner <stefan@agner.ch> * Update supervisor/addons/validate.py Co-authored-by: Stefan Agner <stefan@agner.ch> * fix lint * Apply suggestions from code review Co-authored-by: Joakim Sørensen <joasoe@gmail.com> * Apply suggestions from code review Co-authored-by: Joakim Sørensen <joasoe@gmail.com> * fix black * fix lint Co-authored-by: Franck Nijhof <git@frenck.dev> Co-authored-by: Stefan Agner <stefan@agner.ch> Co-authored-by: Joakim Sørensen <joasoe@gmail.com>
109 lines
3.0 KiB
Python
109 lines
3.0 KiB
Python
"""Test HardwareManager Module."""
|
|
from pathlib import Path
|
|
|
|
from supervisor.hardware.const import UdevSubsystem
|
|
from supervisor.hardware.data import Device
|
|
|
|
# pylint: disable=protected-access
|
|
|
|
|
|
def test_initial_device_initialize(coresys):
|
|
"""Initialize the local hardware."""
|
|
|
|
assert not coresys.hardware.devices
|
|
|
|
coresys.hardware._import_devices()
|
|
|
|
assert coresys.hardware.devices
|
|
|
|
|
|
def test_device_path_lookup(coresys):
|
|
"""Test device lookup."""
|
|
for device in (
|
|
Device(
|
|
"ttyACM0",
|
|
Path("/dev/ttyACM0"),
|
|
Path("/sys/bus/usb/001"),
|
|
"tty",
|
|
[],
|
|
{"ID_VENDOR": "xy"},
|
|
),
|
|
Device(
|
|
"ttyUSB0",
|
|
Path("/dev/ttyUSB0"),
|
|
Path("/sys/bus/usb/000"),
|
|
"tty",
|
|
[Path("/dev/ttyS1"), Path("/dev/serial/by-id/xyx")],
|
|
{"ID_VENDOR": "xy"},
|
|
),
|
|
Device("ttyS0", Path("/dev/ttyS0"), Path("/sys/bus/usb/002"), "tty", [], {}),
|
|
Device(
|
|
"video1",
|
|
Path("/dev/video1"),
|
|
Path("/sys/bus/usb/003"),
|
|
"misc",
|
|
[],
|
|
{"ID_VENDOR": "xy"},
|
|
),
|
|
):
|
|
coresys.hardware.update_device(device)
|
|
|
|
assert coresys.hardware.exists_device_node(Path("/dev/ttyACM0"))
|
|
assert coresys.hardware.exists_device_node(Path("/dev/ttyS1"))
|
|
assert coresys.hardware.exists_device_node(Path("/dev/ttyS0"))
|
|
assert coresys.hardware.exists_device_node(Path("/dev/serial/by-id/xyx"))
|
|
assert coresys.hardware.exists_device_node(Path("/sys/bus/usb/001"))
|
|
|
|
assert not coresys.hardware.exists_device_node(Path("/dev/ttyS2"))
|
|
assert not coresys.hardware.exists_device_node(Path("/dev/ttyUSB1"))
|
|
|
|
|
|
def test_device_filter(coresys):
|
|
"""Test device filter."""
|
|
for device in (
|
|
Device(
|
|
"ttyACM0",
|
|
Path("/dev/ttyACM0"),
|
|
Path("/sys/bus/usb/000"),
|
|
"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/002"), "tty", [], {}),
|
|
Device(
|
|
"video1",
|
|
Path("/dev/video1"),
|
|
Path("/sys/bus/usb/003"),
|
|
"misc",
|
|
[],
|
|
{"ID_VENDOR": "xy"},
|
|
),
|
|
):
|
|
coresys.hardware.update_device(device)
|
|
|
|
assert sorted(
|
|
[device.path for device in coresys.hardware.filter_devices()]
|
|
) == sorted([device.path for device in coresys.hardware.devices])
|
|
assert sorted(
|
|
[
|
|
device.path
|
|
for device in coresys.hardware.filter_devices(
|
|
subsystem=UdevSubsystem.SERIAL
|
|
)
|
|
]
|
|
) == sorted(
|
|
[
|
|
device.path
|
|
for device in coresys.hardware.devices
|
|
if device.subsystem == UdevSubsystem.SERIAL
|
|
]
|
|
)
|