|
11 | 11 | CONF_BLE_SCANNER_MODE, |
12 | 12 | DEPRECATED_FIRMWARE_ISSUE_ID, |
13 | 13 | DOMAIN, |
| 14 | + OPEN_WIFI_AP_ISSUE_ID, |
14 | 15 | OUTBOUND_WEBSOCKET_INCORRECTLY_ENABLED_ISSUE_ID, |
15 | 16 | BLEScannerMode, |
16 | 17 | DeprecatedFirmwareInfo, |
@@ -254,3 +255,207 @@ async def test_deprecated_firmware_issue( |
254 | 255 | # Assert the issue is no longer present |
255 | 256 | assert not issue_registry.async_get_issue(DOMAIN, issue_id) |
256 | 257 | assert len(issue_registry.issues) == 0 |
| 258 | + |
| 259 | + |
| 260 | +async def test_open_wifi_ap_issue( |
| 261 | + hass: HomeAssistant, |
| 262 | + hass_client: ClientSessionGenerator, |
| 263 | + mock_rpc_device: Mock, |
| 264 | + issue_registry: ir.IssueRegistry, |
| 265 | + monkeypatch: pytest.MonkeyPatch, |
| 266 | +) -> None: |
| 267 | + """Test repair issues handling for open WiFi AP.""" |
| 268 | + monkeypatch.setitem( |
| 269 | + mock_rpc_device.config, |
| 270 | + "wifi", |
| 271 | + {"ap": {"enable": True, "is_open": True}}, |
| 272 | + ) |
| 273 | + |
| 274 | + issue_id = OPEN_WIFI_AP_ISSUE_ID.format(unique=MOCK_MAC) |
| 275 | + assert await async_setup_component(hass, "repairs", {}) |
| 276 | + await hass.async_block_till_done() |
| 277 | + await init_integration(hass, 2) |
| 278 | + |
| 279 | + assert issue_registry.async_get_issue(DOMAIN, issue_id) |
| 280 | + assert len(issue_registry.issues) == 1 |
| 281 | + |
| 282 | + await async_process_repairs_platforms(hass) |
| 283 | + client = await hass_client() |
| 284 | + result = await start_repair_fix_flow(client, DOMAIN, issue_id) |
| 285 | + |
| 286 | + flow_id = result["flow_id"] |
| 287 | + assert result["step_id"] == "init" |
| 288 | + assert result["type"] == "menu" |
| 289 | + |
| 290 | + result = await process_repair_fix_flow(client, flow_id, {"next_step_id": "confirm"}) |
| 291 | + assert result["type"] == "create_entry" |
| 292 | + assert mock_rpc_device.wifi_setconfig.call_count == 1 |
| 293 | + assert mock_rpc_device.wifi_setconfig.call_args[1] == {"ap_enable": False} |
| 294 | + assert mock_rpc_device.trigger_reboot.call_count == 1 |
| 295 | + |
| 296 | + assert not issue_registry.async_get_issue(DOMAIN, issue_id) |
| 297 | + assert len(issue_registry.issues) == 0 |
| 298 | + |
| 299 | + |
| 300 | +async def test_open_wifi_ap_issue_no_restart( |
| 301 | + hass: HomeAssistant, |
| 302 | + hass_client: ClientSessionGenerator, |
| 303 | + mock_rpc_device: Mock, |
| 304 | + issue_registry: ir.IssueRegistry, |
| 305 | + monkeypatch: pytest.MonkeyPatch, |
| 306 | +) -> None: |
| 307 | + """Test repair issues handling for open WiFi AP when restart not required.""" |
| 308 | + monkeypatch.setitem( |
| 309 | + mock_rpc_device.config, |
| 310 | + "wifi", |
| 311 | + {"ap": {"enable": True, "is_open": True}}, |
| 312 | + ) |
| 313 | + |
| 314 | + issue_id = OPEN_WIFI_AP_ISSUE_ID.format(unique=MOCK_MAC) |
| 315 | + assert await async_setup_component(hass, "repairs", {}) |
| 316 | + await hass.async_block_till_done() |
| 317 | + await init_integration(hass, 2) |
| 318 | + |
| 319 | + assert issue_registry.async_get_issue(DOMAIN, issue_id) |
| 320 | + assert len(issue_registry.issues) == 1 |
| 321 | + |
| 322 | + await async_process_repairs_platforms(hass) |
| 323 | + client = await hass_client() |
| 324 | + result = await start_repair_fix_flow(client, DOMAIN, issue_id) |
| 325 | + |
| 326 | + flow_id = result["flow_id"] |
| 327 | + assert result["step_id"] == "init" |
| 328 | + assert result["type"] == "menu" |
| 329 | + |
| 330 | + mock_rpc_device.wifi_setconfig.return_value = {"restart_required": False} |
| 331 | + |
| 332 | + result = await process_repair_fix_flow(client, flow_id, {"next_step_id": "confirm"}) |
| 333 | + assert result["type"] == "create_entry" |
| 334 | + assert mock_rpc_device.wifi_setconfig.call_count == 1 |
| 335 | + assert mock_rpc_device.wifi_setconfig.call_args[1] == {"ap_enable": False} |
| 336 | + assert mock_rpc_device.trigger_reboot.call_count == 0 |
| 337 | + |
| 338 | + assert not issue_registry.async_get_issue(DOMAIN, issue_id) |
| 339 | + assert len(issue_registry.issues) == 0 |
| 340 | + |
| 341 | + |
| 342 | +@pytest.mark.parametrize( |
| 343 | + "exception", [DeviceConnectionError, RpcCallError(999, "Unknown error")] |
| 344 | +) |
| 345 | +async def test_open_wifi_ap_issue_exc( |
| 346 | + hass: HomeAssistant, |
| 347 | + hass_client: ClientSessionGenerator, |
| 348 | + mock_rpc_device: Mock, |
| 349 | + issue_registry: ir.IssueRegistry, |
| 350 | + monkeypatch: pytest.MonkeyPatch, |
| 351 | + exception: Exception, |
| 352 | +) -> None: |
| 353 | + """Test repair issues handling when wifi_setconfig ends with an exception.""" |
| 354 | + monkeypatch.setitem( |
| 355 | + mock_rpc_device.config, |
| 356 | + "wifi", |
| 357 | + {"ap": {"enable": True, "is_open": True}}, |
| 358 | + ) |
| 359 | + |
| 360 | + issue_id = OPEN_WIFI_AP_ISSUE_ID.format(unique=MOCK_MAC) |
| 361 | + assert await async_setup_component(hass, "repairs", {}) |
| 362 | + await hass.async_block_till_done() |
| 363 | + await init_integration(hass, 2) |
| 364 | + |
| 365 | + assert issue_registry.async_get_issue(DOMAIN, issue_id) |
| 366 | + assert len(issue_registry.issues) == 1 |
| 367 | + |
| 368 | + await async_process_repairs_platforms(hass) |
| 369 | + client = await hass_client() |
| 370 | + result = await start_repair_fix_flow(client, DOMAIN, issue_id) |
| 371 | + |
| 372 | + flow_id = result["flow_id"] |
| 373 | + assert result["step_id"] == "init" |
| 374 | + assert result["type"] == "menu" |
| 375 | + |
| 376 | + mock_rpc_device.wifi_setconfig.side_effect = exception |
| 377 | + result = await process_repair_fix_flow(client, flow_id, {"next_step_id": "confirm"}) |
| 378 | + assert result["type"] == "abort" |
| 379 | + assert result["reason"] == "cannot_connect" |
| 380 | + assert mock_rpc_device.wifi_setconfig.call_count == 1 |
| 381 | + |
| 382 | + assert issue_registry.async_get_issue(DOMAIN, issue_id) |
| 383 | + assert len(issue_registry.issues) == 1 |
| 384 | + |
| 385 | + |
| 386 | +async def test_no_open_wifi_ap_issue_with_password( |
| 387 | + hass: HomeAssistant, |
| 388 | + mock_rpc_device: Mock, |
| 389 | + issue_registry: ir.IssueRegistry, |
| 390 | + monkeypatch: pytest.MonkeyPatch, |
| 391 | +) -> None: |
| 392 | + """Test no repair issue is created when WiFi AP has a password.""" |
| 393 | + monkeypatch.setitem( |
| 394 | + mock_rpc_device.config, |
| 395 | + "wifi", |
| 396 | + {"ap": {"enable": True, "is_open": False}}, |
| 397 | + ) |
| 398 | + |
| 399 | + issue_id = OPEN_WIFI_AP_ISSUE_ID.format(unique=MOCK_MAC) |
| 400 | + await init_integration(hass, 2) |
| 401 | + |
| 402 | + assert not issue_registry.async_get_issue(DOMAIN, issue_id) |
| 403 | + assert len(issue_registry.issues) == 0 |
| 404 | + |
| 405 | + |
| 406 | +async def test_no_open_wifi_ap_issue_when_disabled( |
| 407 | + hass: HomeAssistant, |
| 408 | + mock_rpc_device: Mock, |
| 409 | + issue_registry: ir.IssueRegistry, |
| 410 | + monkeypatch: pytest.MonkeyPatch, |
| 411 | +) -> None: |
| 412 | + """Test no repair issue is created when WiFi AP is disabled.""" |
| 413 | + monkeypatch.setitem( |
| 414 | + mock_rpc_device.config, |
| 415 | + "wifi", |
| 416 | + {"ap": {"enable": False, "is_open": True}}, |
| 417 | + ) |
| 418 | + |
| 419 | + issue_id = OPEN_WIFI_AP_ISSUE_ID.format(unique=MOCK_MAC) |
| 420 | + await init_integration(hass, 2) |
| 421 | + |
| 422 | + assert not issue_registry.async_get_issue(DOMAIN, issue_id) |
| 423 | + assert len(issue_registry.issues) == 0 |
| 424 | + |
| 425 | + |
| 426 | +async def test_open_wifi_ap_issue_ignore( |
| 427 | + hass: HomeAssistant, |
| 428 | + hass_client: ClientSessionGenerator, |
| 429 | + mock_rpc_device: Mock, |
| 430 | + issue_registry: ir.IssueRegistry, |
| 431 | + monkeypatch: pytest.MonkeyPatch, |
| 432 | +) -> None: |
| 433 | + """Test ignoring the open WiFi AP issue.""" |
| 434 | + monkeypatch.setitem( |
| 435 | + mock_rpc_device.config, |
| 436 | + "wifi", |
| 437 | + {"ap": {"enable": True, "is_open": True}}, |
| 438 | + ) |
| 439 | + |
| 440 | + issue_id = OPEN_WIFI_AP_ISSUE_ID.format(unique=MOCK_MAC) |
| 441 | + assert await async_setup_component(hass, "repairs", {}) |
| 442 | + await hass.async_block_till_done() |
| 443 | + await init_integration(hass, 2) |
| 444 | + |
| 445 | + assert issue_registry.async_get_issue(DOMAIN, issue_id) |
| 446 | + assert len(issue_registry.issues) == 1 |
| 447 | + |
| 448 | + await async_process_repairs_platforms(hass) |
| 449 | + client = await hass_client() |
| 450 | + result = await start_repair_fix_flow(client, DOMAIN, issue_id) |
| 451 | + |
| 452 | + flow_id = result["flow_id"] |
| 453 | + assert result["step_id"] == "init" |
| 454 | + assert result["type"] == "menu" |
| 455 | + |
| 456 | + result = await process_repair_fix_flow(client, flow_id, {"next_step_id": "ignore"}) |
| 457 | + assert result["type"] == "abort" |
| 458 | + assert result["reason"] == "issue_ignored" |
| 459 | + assert mock_rpc_device.wifi_setconfig.call_count == 0 |
| 460 | + |
| 461 | + assert issue_registry.async_get_issue(DOMAIN, issue_id).dismissed_version |
0 commit comments