From 2fe0382841b9e6009cadd7e140f9352ce051ed07 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 1 Dec 2021 16:43:31 +0100 Subject: [PATCH] Add compatibility tests for UsbServiceInfo (#60753) Co-authored-by: epenet --- tests/components/usb/test_init.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/components/usb/test_init.py b/tests/components/usb/test_init.py index 7d620b45984..cc34add6726 100644 --- a/tests/components/usb/test_init.py +++ b/tests/components/usb/test_init.py @@ -777,3 +777,27 @@ def test_human_readable_device_name(): assert "Silicon Labs" in name assert "10C4" in name assert "8A2A" in name + + +async def test_service_info_compatibility(hass, caplog): + """Test compatibility with old-style dict. + + To be removed in 2022.6 + """ + discovery_info = usb.UsbServiceInfo( + 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, + ) + + # Ensure first call get logged + assert discovery_info["vid"] == 12345 + assert "Detected code that accessed discovery_info['vid']" in caplog.text + + # Ensure second call doesn't get logged + caplog.clear() + assert discovery_info["vid"] == 12345 + assert "Detected code that accessed discovery_info['vid']" not in caplog.text