Add support for general API exception in Sense integration (#68517)

This commit is contained in:
Keilin Bickar
2022-03-23 15:45:20 -07:00
committed by Paulus Schoutsen
parent f85781dc51
commit 9636435ff2
7 changed files with 38 additions and 10 deletions
+21 -1
View File
@@ -3,6 +3,7 @@ from unittest.mock import AsyncMock, patch
import pytest
from sense_energy import (
SenseAPIException,
SenseAPITimeoutException,
SenseAuthenticationException,
SenseMFARequiredException,
@@ -189,7 +190,7 @@ async def test_form_mfa_required_exception(hass, mock_sense):
assert result3["errors"] == {"base": "unknown"}
async def test_form_cannot_connect(hass):
async def test_form_timeout(hass):
"""Test we handle cannot connect error."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
@@ -208,6 +209,25 @@ async def test_form_cannot_connect(hass):
assert result2["errors"] == {"base": "cannot_connect"}
async def test_form_cannot_connect(hass):
"""Test we handle cannot connect error."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
with patch(
"sense_energy.ASyncSenseable.authenticate",
side_effect=SenseAPIException,
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{"timeout": "6", "email": "test-email", "password": "test-password"},
)
assert result2["type"] == "form"
assert result2["errors"] == {"base": "cannot_connect"}
async def test_form_unknown_exception(hass):
"""Test we handle unknown error."""
result = await hass.config_entries.flow.async_init(