mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Fix Tado config flow (#135353)
This commit is contained in:
parent
907f1e062a
commit
74c3e9629f
@ -49,7 +49,7 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str,
|
|||||||
tado = await hass.async_add_executor_job(
|
tado = await hass.async_add_executor_job(
|
||||||
Tado, data[CONF_USERNAME], data[CONF_PASSWORD]
|
Tado, data[CONF_USERNAME], data[CONF_PASSWORD]
|
||||||
)
|
)
|
||||||
tado_me = await hass.async_add_executor_job(tado.getMe)
|
tado_me = await hass.async_add_executor_job(tado.get_me)
|
||||||
except KeyError as ex:
|
except KeyError as ex:
|
||||||
raise InvalidAuth from ex
|
raise InvalidAuth from ex
|
||||||
except RuntimeError as ex:
|
except RuntimeError as ex:
|
||||||
|
@ -23,12 +23,12 @@ from homeassistant.data_entry_flow import FlowResultType
|
|||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
def _get_mock_tado_api(getMe=None) -> MagicMock:
|
def _get_mock_tado_api(get_me=None) -> MagicMock:
|
||||||
mock_tado = MagicMock()
|
mock_tado = MagicMock()
|
||||||
if isinstance(getMe, Exception):
|
if isinstance(get_me, Exception):
|
||||||
type(mock_tado).getMe = MagicMock(side_effect=getMe)
|
type(mock_tado).get_me = MagicMock(side_effect=get_me)
|
||||||
else:
|
else:
|
||||||
type(mock_tado).getMe = MagicMock(return_value=getMe)
|
type(mock_tado).get_me = MagicMock(return_value=get_me)
|
||||||
return mock_tado
|
return mock_tado
|
||||||
|
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ async def test_form_exceptions(
|
|||||||
assert result["errors"] == {"base": error}
|
assert result["errors"] == {"base": error}
|
||||||
|
|
||||||
# Test a retry to recover, upon failure
|
# Test a retry to recover, upon failure
|
||||||
mock_tado_api = _get_mock_tado_api(getMe={"homes": [{"id": 1, "name": "myhome"}]})
|
mock_tado_api = _get_mock_tado_api(get_me={"homes": [{"id": 1, "name": "myhome"}]})
|
||||||
|
|
||||||
with (
|
with (
|
||||||
patch(
|
patch(
|
||||||
@ -131,7 +131,7 @@ async def test_create_entry(hass: HomeAssistant) -> None:
|
|||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["errors"] == {}
|
assert result["errors"] == {}
|
||||||
|
|
||||||
mock_tado_api = _get_mock_tado_api(getMe={"homes": [{"id": 1, "name": "myhome"}]})
|
mock_tado_api = _get_mock_tado_api(get_me={"homes": [{"id": 1, "name": "myhome"}]})
|
||||||
|
|
||||||
with (
|
with (
|
||||||
patch(
|
patch(
|
||||||
@ -166,7 +166,9 @@ async def test_form_invalid_auth(hass: HomeAssistant) -> None:
|
|||||||
|
|
||||||
response_mock = MagicMock()
|
response_mock = MagicMock()
|
||||||
type(response_mock).status_code = HTTPStatus.UNAUTHORIZED
|
type(response_mock).status_code = HTTPStatus.UNAUTHORIZED
|
||||||
mock_tado_api = _get_mock_tado_api(getMe=requests.HTTPError(response=response_mock))
|
mock_tado_api = _get_mock_tado_api(
|
||||||
|
get_me=requests.HTTPError(response=response_mock)
|
||||||
|
)
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.tado.config_flow.Tado",
|
"homeassistant.components.tado.config_flow.Tado",
|
||||||
@ -189,7 +191,9 @@ async def test_form_cannot_connect(hass: HomeAssistant) -> None:
|
|||||||
|
|
||||||
response_mock = MagicMock()
|
response_mock = MagicMock()
|
||||||
type(response_mock).status_code = HTTPStatus.INTERNAL_SERVER_ERROR
|
type(response_mock).status_code = HTTPStatus.INTERNAL_SERVER_ERROR
|
||||||
mock_tado_api = _get_mock_tado_api(getMe=requests.HTTPError(response=response_mock))
|
mock_tado_api = _get_mock_tado_api(
|
||||||
|
get_me=requests.HTTPError(response=response_mock)
|
||||||
|
)
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.tado.config_flow.Tado",
|
"homeassistant.components.tado.config_flow.Tado",
|
||||||
@ -210,7 +214,7 @@ async def test_no_homes(hass: HomeAssistant) -> None:
|
|||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
)
|
)
|
||||||
|
|
||||||
mock_tado_api = _get_mock_tado_api(getMe={"homes": []})
|
mock_tado_api = _get_mock_tado_api(get_me={"homes": []})
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.tado.config_flow.Tado",
|
"homeassistant.components.tado.config_flow.Tado",
|
||||||
@ -314,7 +318,7 @@ async def test_reconfigure_flow(
|
|||||||
assert result["type"] is FlowResultType.FORM
|
assert result["type"] is FlowResultType.FORM
|
||||||
assert result["errors"] == {"base": error}
|
assert result["errors"] == {"base": error}
|
||||||
|
|
||||||
mock_tado_api = _get_mock_tado_api(getMe={"homes": [{"id": 1, "name": "myhome"}]})
|
mock_tado_api = _get_mock_tado_api(get_me={"homes": [{"id": 1, "name": "myhome"}]})
|
||||||
with (
|
with (
|
||||||
patch(
|
patch(
|
||||||
"homeassistant.components.tado.config_flow.Tado",
|
"homeassistant.components.tado.config_flow.Tado",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user