Bump pydaikin to 2.0.1, catch HTTPForbidden exception (#35466)
This commit is contained in:
1 parent
3de4bc56b5
commit
93f8d21bc0
6 files changed
+60
-35
No files matched your search
@@ -2,12 +2,18 @@
|
||||
"""Tests for the Daikin config flow."""
|
||||
import asyncio
|
||||
|
||||
from aiohttp import ClientError
|
||||
from aiohttp.web_exceptions import HTTPForbidden
|
||||
import pytest
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components.daikin import config_flow
|
||||
from homeassistant.components.daikin.const import KEY_IP, KEY_MAC
|
||||
from homeassistant.const import CONF_HOST
|
||||
from homeassistant.data_entry_flow import (
|
||||
RESULT_TYPE_ABORT,
|
||||
RESULT_TYPE_CREATE_ENTRY,
|
||||
RESULT_TYPE_FORM,
|
||||
)
|
||||
|
||||
from tests.async_mock import PropertyMock, patch
|
||||
from tests.common import MockConfigEntry
|
||||
@@ -42,11 +48,11 @@ async def test_user(hass, mock_daikin):
|
||||
flow = init_config_flow(hass)
|
||||
|
||||
result = await flow.async_step_user()
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result = await flow.async_step_user({CONF_HOST: HOST})
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == HOST
|
||||
assert result["data"][CONF_HOST] == HOST
|
||||
assert result["data"][KEY_MAC] == MAC
|
||||
@@ -58,7 +64,7 @@ async def test_abort_if_already_setup(hass, mock_daikin):
|
||||
MockConfigEntry(domain="daikin", data={KEY_MAC: MAC}).add_to_hass(hass)
|
||||
|
||||
result = await flow.async_step_user({CONF_HOST: HOST})
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["type"] == RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
@@ -67,11 +73,11 @@ async def test_import(hass, mock_daikin):
|
||||
flow = init_config_flow(hass)
|
||||
|
||||
result = await flow.async_step_import({})
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
result = await flow.async_step_import({CONF_HOST: HOST})
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == HOST
|
||||
assert result["data"][CONF_HOST] == HOST
|
||||
assert result["data"][KEY_MAC] == MAC
|
||||
@@ -82,7 +88,7 @@ async def test_discovery(hass, mock_daikin):
|
||||
flow = init_config_flow(hass)
|
||||
|
||||
result = await flow.async_step_discovery({KEY_IP: HOST, KEY_MAC: MAC})
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == HOST
|
||||
assert result["data"][CONF_HOST] == HOST
|
||||
assert result["data"][KEY_MAC] == MAC
|
||||
@@ -90,7 +96,12 @@ async def test_discovery(hass, mock_daikin):
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"s_effect,reason",
|
||||
[(asyncio.TimeoutError, "device_timeout"), (Exception, "device_fail")],
|
||||
[
|
||||
(asyncio.TimeoutError, "device_timeout"),
|
||||
(HTTPForbidden, "forbidden"),
|
||||
(ClientError, "device_fail"),
|
||||
(Exception, "device_fail"),
|
||||
],
|
||||
)
|
||||
async def test_device_abort(hass, mock_daikin, s_effect, reason):
|
||||
"""Test device abort."""
|
||||
@@ -98,5 +109,6 @@ async def test_device_abort(hass, mock_daikin, s_effect, reason):
|
||||
mock_daikin.factory.side_effect = s_effect
|
||||
|
||||
result = await flow.async_step_user({CONF_HOST: HOST})
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == reason
|
||||
assert result["type"] == RESULT_TYPE_FORM
|
||||
assert result["errors"] == {"base": reason}
|
||||
assert result["step_id"] == "user"
|
||||
Reference in new issue
Block a user