11"""Test the Plugwise config flow."""
22
3- from unittest .mock import AsyncMock , MagicMock , patch
3+ from unittest .mock import MagicMock , patch
44
55from custom_components .plugwise_usb .config_flow import CONF_MANUAL_PATH
66from custom_components .plugwise_usb .const import CONF_USB_PATH , DOMAIN
1111from homeassistant .config_entries import SOURCE_USER
1212from homeassistant .const import CONF_SOURCE
1313from homeassistant .data_entry_flow import FlowResultType , InvalidData
14- from plugwise_usb .exceptions import StickError
1514
1615TEST_USBPORT = "/dev/ttyUSB1"
1716TEST_USBPORT2 = "/dev/ttyUSB2"
@@ -29,7 +28,7 @@ def com_port():
2928
3029
3130@patch ("serial.tools.list_ports.comports" , MagicMock (return_value = [com_port ()]))
32- async def test_user_flow_select (hass , mock_usb : MagicMock ):
31+ async def test_user_flow_select (hass , mock_usb_stick : MagicMock ):
3332 """Test user flow when USB-stick is selected from list."""
3433 port = com_port ()
3534 port_select = f"{ port } , s/n: { port .serial_number } - { port .manufacturer } "
@@ -78,7 +77,7 @@ async def test_user_flow_manual_selected_show_form(hass):
7877
7978
8079async def test_user_flow_manual (
81- hass , mock_usb : MagicMock , init_integration : MockConfigEntry
80+ hass , mock_usb_stick : MagicMock , init_integration : MockConfigEntry
8281):
8382 """Test user flow when USB-stick is manually entered."""
8483
@@ -146,9 +145,7 @@ async def test_empty_connection(hass):
146145 assert result .get ("errors" ) == {}
147146
148147
149- @patch ("plugwise_usb.Stick.connect" , AsyncMock (side_effect = (StickError )))
150- @patch ("plugwise_usb.Stick.initialize" , AsyncMock (return_value = None ))
151- async def test_failed_connect (hass ):
148+ async def test_failed_connect (hass , mock_usb_stick_error : MagicMock ):
152149 """Test we handle failed connection."""
153150 result = await hass .config_entries .flow .async_init (
154151 DOMAIN ,
@@ -168,9 +165,7 @@ async def test_failed_connect(hass):
168165 assert result .get ("errors" ) == {"base" : "cannot_connect" }
169166
170167
171- @patch ("plugwise_usb.Stick.connect" , AsyncMock (return_value = None ))
172- @patch ("plugwise_usb.Stick.initialize" , AsyncMock (side_effect = (StickError )))
173- async def test_failed_initialization (hass ):
168+ async def test_failed_initialization (hass , mock_usb_stick_init_error : MagicMock ):
174169 """Test we handle failed initialization of Plugwise USB-stick."""
175170 result = await hass .config_entries .flow .async_init (
176171 DOMAIN ,
0 commit comments