|
39 | 39 | DOMAIN,
|
40 | 40 | UPDATER,
|
41 | 41 | )
|
42 |
| -from custom_components.miwifi.exceptions import LuciRequestError |
| 42 | +from custom_components.miwifi.exceptions import LuciConnectionError, LuciRequestError |
43 | 43 | from custom_components.miwifi.helper import generate_entity_id
|
44 | 44 | from custom_components.miwifi.updater import LuciUpdater
|
45 | 45 | from tests.setup import MultipleSideEffect, async_mock_luci_client, async_setup
|
@@ -218,6 +218,56 @@ async def test_init_without_guest(hass: HomeAssistant) -> None:
|
218 | 218 | assert registry.async_get(unique_id) is None
|
219 | 219 |
|
220 | 220 |
|
| 221 | +async def test_init_with_error(hass: HomeAssistant) -> None: |
| 222 | + """Test init. |
| 223 | +
|
| 224 | + :param hass: HomeAssistant |
| 225 | + """ |
| 226 | + |
| 227 | + with patch( |
| 228 | + "custom_components.miwifi.updater.LuciClient" |
| 229 | + ) as mock_luci_client, patch( |
| 230 | + "custom_components.miwifi.updater.async_dispatcher_send" |
| 231 | + ), patch( |
| 232 | + "custom_components.miwifi.async_start_discovery", return_value=None |
| 233 | + ), patch( |
| 234 | + "custom_components.miwifi.device_tracker.socket.socket" |
| 235 | + ) as mock_socket, patch( |
| 236 | + "custom_components.miwifi.updater.asyncio.sleep", return_value=None |
| 237 | + ): |
| 238 | + mock_socket.return_value.recv.return_value = AsyncMock(return_value=None) |
| 239 | + |
| 240 | + await async_mock_luci_client(mock_luci_client) |
| 241 | + |
| 242 | + mock_luci_client.return_value.wifi_detail_all = AsyncMock( |
| 243 | + side_effect=LuciConnectionError |
| 244 | + ) |
| 245 | + |
| 246 | + setup_data: list = await async_setup(hass) |
| 247 | + |
| 248 | + config_entry: MockConfigEntry = setup_data[1] |
| 249 | + |
| 250 | + assert await hass.config_entries.async_setup(config_entry.entry_id) |
| 251 | + await hass.async_block_till_done() |
| 252 | + |
| 253 | + updater: LuciUpdater = hass.data[DOMAIN][config_entry.entry_id][UPDATER] |
| 254 | + registry = er.async_get(hass) |
| 255 | + |
| 256 | + assert updater.last_update_success |
| 257 | + |
| 258 | + unique_id: str = _generate_id(ATTR_SWITCH_WIFI_2_4_NAME, updater) |
| 259 | + states: State | None = hass.states.get(unique_id) |
| 260 | + assert states is not None |
| 261 | + assert states.state == STATE_UNAVAILABLE |
| 262 | + assert registry.async_get(unique_id) is not None |
| 263 | + |
| 264 | + unique_id = _generate_id(ATTR_SWITCH_WIFI_5_0_NAME, updater) |
| 265 | + states = hass.states.get(unique_id) |
| 266 | + assert states is not None |
| 267 | + assert states.state == STATE_UNAVAILABLE |
| 268 | + assert registry.async_get(unique_id) is not None |
| 269 | + |
| 270 | + |
221 | 271 | async def test_init_bsd(
|
222 | 272 | hass: HomeAssistant,
|
223 | 273 | ) -> None:
|
|
0 commit comments