Add support for USB dongles to the hardware integration (#76795)

* Add support for USB dongles to the hardware integration

* Update hardware integrations

* Adjust tests

* Add USB discovery for SkyConnect 1.0

* Improve test coverage

* Apply suggestions from code review

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>

* Fix frozen dataclass shizzle

* Adjust test

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
Erik Montnemery 2022-08-18 21:52:12 +02:00 committed by GitHub
parent fb5a67fb1f
commit bb74730e96
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 581 additions and 28 deletions

View file

@ -833,3 +833,45 @@ def test_human_readable_device_name():
assert "Silicon Labs" in name
assert "10C4" in name
assert "8A2A" in name
async def test_async_is_plugged_in(hass, hass_ws_client):
"""Test async_is_plugged_in."""
new_usb = [{"domain": "test1", "vid": "3039", "pid": "3039"}]
mock_comports = [
MagicMock(
device=slae_sh_device.device,
vid=12345,
pid=12345,
serial_number=slae_sh_device.serial_number,
manufacturer=slae_sh_device.manufacturer,
description=slae_sh_device.description,
)
]
matcher = {
"vid": "3039",
"pid": "3039",
}
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()
assert not usb.async_is_plugged_in(hass, matcher)
with patch(
"homeassistant.components.usb.comports", return_value=mock_comports
), patch.object(hass.config_entries.flow, "async_init"):
ws_client = await hass_ws_client(hass)
await ws_client.send_json({"id": 1, "type": "usb/scan"})
response = await ws_client.receive_json()
assert response["success"]
await hass.async_block_till_done()
assert usb.async_is_plugged_in(hass, matcher)