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