forked from home-assistant/core
Add reauth step to Hyperion config flow (#43797)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
@@ -50,6 +50,20 @@ TEST_INSTANCE_3: Dict[str, Any] = {
|
||||
"running": True,
|
||||
}
|
||||
|
||||
TEST_AUTH_REQUIRED_RESP: Dict[str, Any] = {
|
||||
"command": "authorize-tokenRequired",
|
||||
"info": {
|
||||
"required": True,
|
||||
},
|
||||
"success": True,
|
||||
"tan": 1,
|
||||
}
|
||||
|
||||
TEST_AUTH_NOT_REQUIRED_RESP = {
|
||||
**TEST_AUTH_REQUIRED_RESP,
|
||||
"info": {"required": False},
|
||||
}
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -78,12 +92,7 @@ def create_mock_client() -> Mock:
|
||||
mock_client.async_client_connect = AsyncMock(return_value=True)
|
||||
mock_client.async_client_disconnect = AsyncMock(return_value=True)
|
||||
mock_client.async_is_auth_required = AsyncMock(
|
||||
return_value={
|
||||
"command": "authorize-tokenRequired",
|
||||
"info": {"required": False},
|
||||
"success": True,
|
||||
"tan": 1,
|
||||
}
|
||||
return_value=TEST_AUTH_NOT_REQUIRED_RESP
|
||||
)
|
||||
mock_client.async_login = AsyncMock(
|
||||
return_value={"command": "authorize-login", "success": True, "tan": 0}
|
||||
@@ -91,6 +100,17 @@ def create_mock_client() -> Mock:
|
||||
|
||||
mock_client.async_sysinfo_id = AsyncMock(return_value=TEST_SYSINFO_ID)
|
||||
mock_client.async_sysinfo_version = AsyncMock(return_value=TEST_SYSINFO_ID)
|
||||
mock_client.async_client_switch_instance = AsyncMock(return_value=True)
|
||||
mock_client.async_client_login = AsyncMock(return_value=True)
|
||||
mock_client.async_get_serverinfo = AsyncMock(
|
||||
return_value={
|
||||
"command": "serverinfo",
|
||||
"success": True,
|
||||
"tan": 0,
|
||||
"info": {"fake": "data"},
|
||||
}
|
||||
)
|
||||
|
||||
mock_client.adjustment = None
|
||||
mock_client.effects = None
|
||||
mock_client.instances = [
|
||||
@@ -100,12 +120,15 @@ def create_mock_client() -> Mock:
|
||||
return mock_client
|
||||
|
||||
|
||||
def add_test_config_entry(hass: HomeAssistantType) -> ConfigEntry:
|
||||
def add_test_config_entry(
|
||||
hass: HomeAssistantType, data: Optional[Dict[str, Any]] = None
|
||||
) -> ConfigEntry:
|
||||
"""Add a test config entry."""
|
||||
config_entry: MockConfigEntry = MockConfigEntry( # type: ignore[no-untyped-call]
|
||||
entry_id=TEST_CONFIG_ENTRY_ID,
|
||||
domain=DOMAIN,
|
||||
data={
|
||||
data=data
|
||||
or {
|
||||
CONF_HOST: TEST_HOST,
|
||||
CONF_PORT: TEST_PORT,
|
||||
},
|
||||
@@ -118,10 +141,12 @@ def add_test_config_entry(hass: HomeAssistantType) -> ConfigEntry:
|
||||
|
||||
|
||||
async def setup_test_config_entry(
|
||||
hass: HomeAssistantType, hyperion_client: Optional[Mock] = None
|
||||
hass: HomeAssistantType,
|
||||
config_entry: Optional[ConfigEntry] = None,
|
||||
hyperion_client: Optional[Mock] = None,
|
||||
) -> ConfigEntry:
|
||||
"""Add a test Hyperion entity to hass."""
|
||||
config_entry = add_test_config_entry(hass)
|
||||
config_entry = config_entry or add_test_config_entry(hass)
|
||||
|
||||
hyperion_client = hyperion_client or create_mock_client()
|
||||
# pylint: disable=attribute-defined-outside-init
|
||||
|
||||
Reference in New Issue
Block a user