Validate matcher field case in usb.async_is_plugged_in (#81514)

* Support case-insensitive matching

* Revert "Support case-insensitive matching"

This reverts commit 0fdb2aa6bc.

* Explicitly check the case of matcher fields in `async_is_plugged_in`
This commit is contained in:
puddly
2022-11-07 17:14:57 +01:00
committed by GitHub
parent 43745dbc6c
commit 3788a950e6
2 changed files with 47 additions and 0 deletions
+29
View File
@@ -877,6 +877,35 @@ async def test_async_is_plugged_in(hass, hass_ws_client):
assert usb.async_is_plugged_in(hass, matcher)
@pytest.mark.parametrize(
"matcher",
[
{"vid": "abcd"},
{"pid": "123a"},
{"serial_number": "1234ABCD"},
{"manufacturer": "Some Manufacturer"},
{"description": "A description"},
],
)
async def test_async_is_plugged_in_case_enforcement(hass, matcher):
"""Test `async_is_plugged_in` throws an error when incorrect cases are used."""
new_usb = [{"domain": "test1", "vid": "ABCD"}]
with patch("pyudev.Context", side_effect=ImportError), patch(
"homeassistant.components.usb.async_get_usb", return_value=new_usb
), patch("homeassistant.components.usb.comports", return_value=[]), patch.object(
hass.config_entries.flow, "async_init"
):
assert await async_setup_component(hass, "usb", {"usb": {}})
await hass.async_block_till_done()
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
await hass.async_block_till_done()
with pytest.raises(ValueError):
usb.async_is_plugged_in(hass, matcher)
async def test_web_socket_triggers_discovery_request_callbacks(hass, hass_ws_client):
"""Test the websocket call triggers a discovery request callback."""
mock_callback = Mock()