fix socket

This commit is contained in:
firestar5683
2026-07-24 01:02:05 -05:00
parent 779b42d8ea
commit 8640f06054
4 changed files with 39 additions and 34 deletions
+21
View File
@@ -0,0 +1,21 @@
from openpilot.system.hardware import usb
def test_chestnut_present(tmp_path, monkeypatch):
monkeypatch.setattr(usb, "USB_DEVICES_PATH", tmp_path)
device = tmp_path / "1-1"
device.mkdir()
(device / "idVendor").write_text("add1\n")
(device / "idProduct").write_text("0001\n")
assert usb.chestnut_present()
def test_chestnut_absent_for_other_usb_device(tmp_path, monkeypatch):
monkeypatch.setattr(usb, "USB_DEVICES_PATH", tmp_path)
device = tmp_path / "1-1"
device.mkdir()
(device / "idVendor").write_text("18d1\n")
(device / "idProduct").write_text("4ee7\n")
assert not usb.chestnut_present()
+8
View File
@@ -20,6 +20,14 @@ def usb_devices() -> list[Path]:
return []
def chestnut_present() -> bool:
return any(
read_int(device / "idVendor", 16) == CHESTNUT_VENDOR_ID and
read_int(device / "idProduct", 16) == CHESTNUT_PRODUCT_ID
for device in usb_devices()
)
def controller(device: Path) -> Path | None:
try:
return next((parent for parent in device.resolve().parents if parent.name.endswith(".ssusb")), None)