mirror of
https://github.com/home-assistant/core.git
synced 2026-04-25 20:48:26 +00:00
Remove old migration from Tuya (#157237)
This commit is contained in:
@@ -19,7 +19,6 @@ from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.dispatcher import dispatcher_send
|
||||
|
||||
from .const import (
|
||||
CONF_APP_TYPE,
|
||||
CONF_ENDPOINT,
|
||||
CONF_TERMINAL_ID,
|
||||
CONF_TOKEN_INFO,
|
||||
@@ -47,9 +46,6 @@ class HomeAssistantTuyaData(NamedTuple):
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: TuyaConfigEntry) -> bool:
|
||||
"""Async setup hass config entry."""
|
||||
if CONF_APP_TYPE in entry.data:
|
||||
raise ConfigEntryAuthFailed("Authentication failed. Please re-authenticate.")
|
||||
|
||||
token_listener = TokenListener(hass, entry)
|
||||
manager = Manager(
|
||||
TUYA_CLIENT_ID,
|
||||
|
||||
@@ -30,7 +30,6 @@ from homeassistant.const import (
|
||||
DOMAIN = "tuya"
|
||||
LOGGER = logging.getLogger(__package__)
|
||||
|
||||
CONF_APP_TYPE = "tuya_app_type"
|
||||
CONF_ENDPOINT = "endpoint"
|
||||
CONF_TERMINAL_ID = "terminal_id"
|
||||
CONF_TOKEN_INFO = "token_info"
|
||||
|
||||
@@ -15,7 +15,6 @@ from tuya_sharing import (
|
||||
)
|
||||
|
||||
from homeassistant.components.tuya.const import (
|
||||
CONF_APP_TYPE,
|
||||
CONF_ENDPOINT,
|
||||
CONF_TERMINAL_ID,
|
||||
CONF_TOKEN_INFO,
|
||||
@@ -31,17 +30,6 @@ from . import DEVICE_MOCKS, MockDeviceListener
|
||||
from tests.common import MockConfigEntry, async_load_json_object_fixture
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_old_config_entry() -> MockConfigEntry:
|
||||
"""Mock an old config entry that can be migrated."""
|
||||
return MockConfigEntry(
|
||||
title="Old Tuya configuration entry",
|
||||
domain=DOMAIN,
|
||||
data={CONF_APP_TYPE: "tuyaSmart"},
|
||||
unique_id="12345",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_config_entry() -> MockConfigEntry:
|
||||
"""Mock a config entry."""
|
||||
|
||||
@@ -31,38 +31,6 @@
|
||||
'version': 1,
|
||||
})
|
||||
# ---
|
||||
# name: test_reauth_flow_migration
|
||||
ConfigEntrySnapshot({
|
||||
'data': dict({
|
||||
'endpoint': 'mocked_endpoint',
|
||||
'terminal_id': 'mocked_terminal_id',
|
||||
'token_info': dict({
|
||||
'access_token': 'mocked_access_token',
|
||||
'expire_time': 'mocked_expire_time',
|
||||
'refresh_token': 'mocked_refresh_token',
|
||||
't': 'mocked_t',
|
||||
'uid': 'mocked_uid',
|
||||
}),
|
||||
'user_code': '12345',
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'discovery_keys': dict({
|
||||
}),
|
||||
'domain': 'tuya',
|
||||
'entry_id': <ANY>,
|
||||
'minor_version': 1,
|
||||
'options': dict({
|
||||
}),
|
||||
'pref_disable_new_entities': False,
|
||||
'pref_disable_polling': False,
|
||||
'source': 'user',
|
||||
'subentries': list([
|
||||
]),
|
||||
'title': 'Old Tuya configuration entry',
|
||||
'unique_id': '12345',
|
||||
'version': 1,
|
||||
})
|
||||
# ---
|
||||
# name: test_user_flow
|
||||
FlowResultSnapshot({
|
||||
'context': dict({
|
||||
|
||||
@@ -7,7 +7,7 @@ from unittest.mock import MagicMock
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.tuya.const import CONF_APP_TYPE, CONF_USER_CODE, DOMAIN
|
||||
from homeassistant.components.tuya.const import CONF_USER_CODE, DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_USER
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
@@ -161,63 +161,22 @@ async def test_reauth_flow(
|
||||
assert mock_config_entry == snapshot
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_tuya_login_control")
|
||||
async def test_reauth_flow_migration(
|
||||
hass: HomeAssistant,
|
||||
mock_old_config_entry: MockConfigEntry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test the reauthentication configuration flow.
|
||||
|
||||
This flow tests the migration from an old config entry.
|
||||
"""
|
||||
mock_old_config_entry.add_to_hass(hass)
|
||||
|
||||
# Ensure old data is there, new data is missing
|
||||
assert CONF_APP_TYPE in mock_old_config_entry.data
|
||||
assert CONF_USER_CODE not in mock_old_config_entry.data
|
||||
|
||||
result = await mock_old_config_entry.start_reauth_flow(hass)
|
||||
|
||||
assert result.get("type") is FlowResultType.FORM
|
||||
assert result.get("step_id") == "reauth_user_code"
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={CONF_USER_CODE: "12345"},
|
||||
)
|
||||
|
||||
assert result2.get("type") is FlowResultType.FORM
|
||||
assert result2.get("step_id") == "scan"
|
||||
|
||||
result3 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={},
|
||||
)
|
||||
|
||||
assert result3.get("type") is FlowResultType.ABORT
|
||||
assert result3.get("reason") == "reauth_successful"
|
||||
|
||||
# Ensure the old data is gone, new data is present
|
||||
assert CONF_APP_TYPE not in mock_old_config_entry.data
|
||||
assert CONF_USER_CODE in mock_old_config_entry.data
|
||||
|
||||
assert mock_old_config_entry == snapshot
|
||||
|
||||
|
||||
async def test_reauth_flow_failed_qr_code(
|
||||
hass: HomeAssistant,
|
||||
mock_tuya_login_control: MagicMock,
|
||||
mock_old_config_entry: MockConfigEntry,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test an error occurring while retrieving the QR code."""
|
||||
mock_old_config_entry.add_to_hass(hass)
|
||||
|
||||
result = await mock_old_config_entry.start_reauth_flow(hass)
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
||||
# Something went wrong getting the QR code (like an invalid user code)
|
||||
mock_tuya_login_control.qr_code.return_value["success"] = False
|
||||
|
||||
result = await mock_config_entry.start_reauth_flow(hass)
|
||||
|
||||
assert result.get("type") is FlowResultType.FORM
|
||||
assert result.get("step_id") == "reauth_user_code"
|
||||
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={CONF_USER_CODE: "12345"},
|
||||
|
||||
Reference in New Issue
Block a user