1515
1616from freezegun .api import FrozenDateTimeFactory
1717from homeassistant .components .plugwise .const import DOMAIN
18- from homeassistant .components .plugwise .coordinator import PlugwiseDataUpdateCoordinator
1918from homeassistant .config_entries import ConfigEntryState
2019from homeassistant .const import (
2120 CONF_HOST ,
2726 Platform ,
2827)
2928from homeassistant .core import HomeAssistant
30- from homeassistant .exceptions import ConfigEntryError
3129from homeassistant .helpers import device_registry as dr , entity_registry as er
32- from homeassistant .helpers .update_coordinator import UpdateFailed
3330from homeassistant .setup import async_setup_component
3431
3532from tests .common import MockConfigEntry , async_fire_time_changed
@@ -104,7 +101,7 @@ async def test_gateway_config_entry_not_ready(
104101 mock_smile_anna : MagicMock ,
105102 side_effect : Exception ,
106103) -> None :
107- """Test the Plugwise configuration entry not ready."""
104+ """Test the Plugwise config- entry not being ready."""
108105 mock_smile_anna .async_update .side_effect = side_effect
109106
110107 mock_config_entry .add_to_hass (hass )
@@ -118,32 +115,33 @@ async def test_gateway_config_entry_not_ready(
118115@pytest .mark .parametrize ("chosen_env" , ["anna_heatpump_heating" ], indirect = True )
119116@pytest .mark .parametrize ("cooling_present" , [True ], indirect = True )
120117@pytest .mark .parametrize (
121- ("side_effect" , "expected_raise " ),
118+ ("side_effect" , "entry_state " ),
122119 [
123- (ConnectionFailedError , UpdateFailed ),
124- (InvalidAuthentication , ConfigEntryError ),
125- (InvalidSetupError , ConfigEntryError ),
126- (InvalidXMLError , UpdateFailed ),
127- (ResponseError , UpdateFailed ),
128- (UnsupportedDeviceError , ConfigEntryError ),
120+ (ConnectionFailedError , ConfigEntryState .SETUP_RETRY ),
121+ (InvalidAuthentication , ConfigEntryState .SETUP_ERROR ),
122+ (InvalidSetupError , ConfigEntryState .SETUP_ERROR ),
123+ (InvalidXMLError , ConfigEntryState .SETUP_RETRY ),
124+ (ResponseError , ConfigEntryState .SETUP_RETRY ),
125+ (PlugwiseError , ConfigEntryState .SETUP_RETRY ),
126+ (UnsupportedDeviceError , ConfigEntryState .SETUP_ERROR ),
129127 ],
130128)
131129async def test_coordinator_connect_exceptions (
132130 hass : HomeAssistant ,
133131 mock_config_entry : MockConfigEntry ,
134132 mock_smile_anna : MagicMock ,
135133 side_effect : Exception ,
136- expected_raise : Exception ,
134+ entry_state : ConfigEntryState ,
137135) -> None :
138136 """Ensure _connect raises translated errors."""
139137 mock_smile_anna .connect .side_effect = side_effect
140- coordinator = PlugwiseDataUpdateCoordinator (
141- hass ,
142- cooldown = 0 ,
143- config_entry = mock_config_entry ,
144- )
145- with pytest . raises ( expected_raise ):
146- await coordinator . _connect ()
138+
139+ mock_config_entry . add_to_hass ( hass )
140+ await hass . config_entries . async_setup ( mock_config_entry . entry_id )
141+ await hass . async_block_till_done ()
142+
143+ assert len ( mock_smile_anna . connect . mock_calls ) == 1
144+ assert mock_config_entry . state is entry_state
147145
148146
149147@pytest .mark .parametrize ("chosen_env" , ["p1v4_442_single" ], indirect = True )
@@ -360,9 +358,6 @@ async def test_delete_removed_device(
360358) -> None :
361359 """Test device removal at integration init."""
362360 data = mock_smile_adam_heat_cool .async_update .return_value
363- mock_config_entry .add_to_hass (hass )
364- assert await async_setup_component (hass , DOMAIN , {})
365- await hass .async_block_till_done ()
366361
367362 item_list : list [str ] = []
368363 for device_entry in device_registry .devices .values ():
0 commit comments