|
15 | 15 |
|
16 | 16 | from freezegun.api import FrozenDateTimeFactory |
17 | 17 | from homeassistant.components.plugwise.const import DOMAIN |
18 | | -from homeassistant.components.plugwise.coordinator import PlugwiseDataUpdateCoordinator |
19 | 18 | from homeassistant.config_entries import ConfigEntryState |
20 | 19 | from homeassistant.const import ( |
21 | 20 | CONF_HOST, |
|
27 | 26 | Platform, |
28 | 27 | ) |
29 | 28 | from homeassistant.core import HomeAssistant |
30 | | -from homeassistant.exceptions import ConfigEntryError |
| 29 | + |
| 30 | +# from homeassistant.exceptions import ConfigEntryError |
31 | 31 | from homeassistant.helpers import device_registry as dr, entity_registry as er |
32 | | -from homeassistant.helpers.update_coordinator import UpdateFailed |
| 32 | + |
| 33 | +# from homeassistant.helpers.update_coordinator import UpdateFailed |
33 | 34 | from homeassistant.setup import async_setup_component |
34 | 35 |
|
35 | 36 | from tests.common import MockConfigEntry, async_fire_time_changed |
@@ -118,32 +119,53 @@ async def test_gateway_config_entry_not_ready( |
118 | 119 | @pytest.mark.parametrize("chosen_env", ["anna_heatpump_heating"], indirect=True) |
119 | 120 | @pytest.mark.parametrize("cooling_present", [True], indirect=True) |
120 | 121 | @pytest.mark.parametrize( |
121 | | - ("side_effect", "expected_raise"), |
| 122 | + "side_effect", |
122 | 123 | [ |
123 | | - (ConnectionFailedError, UpdateFailed), |
124 | | - (InvalidAuthentication, ConfigEntryError), |
125 | | - (InvalidSetupError, ConfigEntryError), |
126 | | - (InvalidXMLError, UpdateFailed), |
127 | | - (ResponseError, UpdateFailed), |
128 | | - (UnsupportedDeviceError, ConfigEntryError), |
| 124 | + ConnectionFailedError, |
| 125 | + InvalidXMLError, |
| 126 | + ResponseError, |
129 | 127 | ], |
130 | 128 | ) |
131 | | -async def test_coordinator_connect_exceptions( |
| 129 | +async def test_coordinator_connect_exceptions_1( |
132 | 130 | hass: HomeAssistant, |
133 | 131 | mock_config_entry: MockConfigEntry, |
134 | 132 | mock_smile_anna: MagicMock, |
135 | 133 | side_effect: Exception, |
136 | | - expected_raise: Exception, |
137 | 134 | ) -> None: |
138 | 135 | """Ensure _connect raises translated errors.""" |
139 | 136 | 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() |
| 137 | + |
| 138 | + mock_config_entry.add_to_hass(hass) |
| 139 | + await hass.config_entries.async_setup(mock_config_entry.entry_id) |
| 140 | + await hass.async_block_till_done() |
| 141 | + |
| 142 | + assert len(mock_smile_anna.connect.mock_calls) == 1 |
| 143 | + assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY |
| 144 | + |
| 145 | + |
| 146 | +@pytest.mark.parametrize("chosen_env", ["anna_heatpump_heating"], indirect=True) |
| 147 | +@pytest.mark.parametrize("cooling_present", [True], indirect=True) |
| 148 | +@pytest.mark.parametrize( |
| 149 | + ("side_effect", "raise_match"), |
| 150 | + [ |
| 151 | + (InvalidAuthentication, "Invalid authentication"), |
| 152 | + (InvalidSetupError, "invalid_setup"), |
| 153 | + (UnsupportedDeviceError, "Device with unsupported firmware"), |
| 154 | + ], |
| 155 | +) |
| 156 | +async def test_coordinator_connect_exceptions_2( |
| 157 | + hass: HomeAssistant, |
| 158 | + mock_config_entry: MockConfigEntry, |
| 159 | + mock_smile_anna: MagicMock, |
| 160 | + side_effect: Exception, |
| 161 | + raise_match: str, |
| 162 | +) -> None: |
| 163 | + """Ensure _connect raises translated errors.""" |
| 164 | + mock_smile_anna.connect.side_effect = side_effect |
| 165 | + |
| 166 | + mock_config_entry.add_to_hass(hass) |
| 167 | + with pytest.raises(side_effect, match=raise_match): |
| 168 | + await hass.config_entries.async_setup(mock_config_entry.entry_id) |
147 | 169 |
|
148 | 170 |
|
149 | 171 | @pytest.mark.parametrize("chosen_env", ["p1v4_442_single"], indirect=True) |
|
0 commit comments