Gracefully handle udev not available via OSError when setting up usb (#54967)

This commit is contained in:
J. Nick Koston 2021-08-21 07:24:45 -05:00 committed by GitHub
parent c609236a63
commit 51434c5faa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View File

@ -113,7 +113,7 @@ class USBDiscovery:
try:
context = Context()
except ImportError:
except (ImportError, OSError):
return False
monitor = Monitor.from_netlink(context)

View File

@ -243,7 +243,8 @@ async def test_discovered_by_scanner_after_started_no_vid_pid(hass):
assert len(mock_config_flow.mock_calls) == 0
async def test_non_matching_discovered_by_scanner_after_started(hass):
@pytest.mark.parametrize("exception_type", [ImportError, OSError])
async def test_non_matching_discovered_by_scanner_after_started(hass, exception_type):
"""Test a device is discovered by the scanner after the started event that does not match."""
new_usb = [{"domain": "test1", "vid": "4444", "pid": "4444"}]
@ -258,7 +259,7 @@ async def test_non_matching_discovered_by_scanner_after_started(hass):
)
]
with patch("pyudev.Context", side_effect=ImportError), patch(
with patch("pyudev.Context", side_effect=exception_type), patch(
"homeassistant.components.usb.async_get_usb", return_value=new_usb
), patch(
"homeassistant.components.usb.comports", return_value=mock_comports