mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 00:37:53 +00:00
Remove YAML configuration from Tuya (#50360)
* Remove YAML configuration from Tuya * Keep deprecation warning
This commit is contained in:
parent
ec08256ff0
commit
b2cee2e602
@ -10,9 +10,8 @@ from tuyaha.tuyaapi import (
|
||||
TuyaNetException,
|
||||
TuyaServerException,
|
||||
)
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_PASSWORD,
|
||||
CONF_PLATFORM,
|
||||
@ -67,22 +66,7 @@ TUYA_TYPE_TO_HA = {
|
||||
TUYA_TRACKER = "tuya_tracker"
|
||||
STOP_CANCEL = "stop_event_cancel"
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
vol.All(
|
||||
cv.deprecated(DOMAIN),
|
||||
{
|
||||
DOMAIN: vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_USERNAME): cv.string,
|
||||
vol.Required(CONF_COUNTRYCODE): cv.string,
|
||||
vol.Required(CONF_PASSWORD): cv.string,
|
||||
vol.Optional(CONF_PLATFORM, default="tuya"): cv.string,
|
||||
}
|
||||
)
|
||||
},
|
||||
),
|
||||
extra=vol.ALLOW_EXTRA,
|
||||
)
|
||||
CONFIG_SCHEMA = cv.deprecated(DOMAIN)
|
||||
|
||||
|
||||
def _update_discovery_interval(hass, interval):
|
||||
@ -109,20 +93,6 @@ def _update_query_interval(hass, interval):
|
||||
_LOGGER.warning(ex)
|
||||
|
||||
|
||||
async def async_setup(hass, config):
|
||||
"""Set up the Tuya integration."""
|
||||
|
||||
conf = config.get(DOMAIN)
|
||||
if conf is not None:
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=conf
|
||||
)
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||
"""Set up Tuya platform."""
|
||||
|
||||
|
@ -89,7 +89,6 @@ class TuyaConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
self._password = None
|
||||
self._platform = None
|
||||
self._username = None
|
||||
self._is_import = False
|
||||
|
||||
def _save_entry(self):
|
||||
return self.async_create_entry(
|
||||
@ -116,11 +115,6 @@ class TuyaConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
|
||||
return RESULT_SUCCESS
|
||||
|
||||
async def async_step_import(self, user_input=None):
|
||||
"""Handle configuration by yaml file."""
|
||||
self._is_import = True
|
||||
return await self.async_step_user(user_input)
|
||||
|
||||
async def async_step_user(self, user_input=None):
|
||||
"""Handle a flow initialized by the user."""
|
||||
if self._async_current_entries():
|
||||
@ -139,12 +133,7 @@ class TuyaConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
|
||||
if result == RESULT_SUCCESS:
|
||||
return self._save_entry()
|
||||
if result != RESULT_AUTH_FAILED or self._is_import:
|
||||
if self._is_import:
|
||||
_LOGGER.error(
|
||||
"Error importing from configuration.yaml: %s",
|
||||
RESULT_LOG_MESSAGE.get(result, "Generic Error"),
|
||||
)
|
||||
if result != RESULT_AUTH_FAILED:
|
||||
return self.async_abort(reason=result)
|
||||
errors["base"] = result
|
||||
|
||||
|
@ -96,24 +96,6 @@ async def test_user(hass, tuya):
|
||||
assert not result["result"].unique_id
|
||||
|
||||
|
||||
async def test_import(hass, tuya):
|
||||
"""Test import step."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data=TUYA_USER_DATA,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == USERNAME
|
||||
assert result["data"][CONF_USERNAME] == USERNAME
|
||||
assert result["data"][CONF_PASSWORD] == PASSWORD
|
||||
assert result["data"][CONF_COUNTRYCODE] == COUNTRY_CODE
|
||||
assert result["data"][CONF_PLATFORM] == TUYA_PLATFORM
|
||||
assert not result["result"].unique_id
|
||||
|
||||
|
||||
async def test_abort_if_already_setup(hass, tuya):
|
||||
"""Test we abort if Tuya is already setup."""
|
||||
MockConfigEntry(domain=DOMAIN, data=TUYA_USER_DATA).add_to_hass(hass)
|
||||
@ -126,14 +108,6 @@ async def test_abort_if_already_setup(hass, tuya):
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == RESULT_SINGLE_INSTANCE
|
||||
|
||||
# Should fail, config exist (flow)
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=TUYA_USER_DATA
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == RESULT_SINGLE_INSTANCE
|
||||
|
||||
|
||||
async def test_abort_on_invalid_credentials(hass, tuya):
|
||||
"""Test when we have invalid credentials."""
|
||||
@ -146,13 +120,6 @@ async def test_abort_on_invalid_credentials(hass, tuya):
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["errors"] == {"base": RESULT_AUTH_FAILED}
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=TUYA_USER_DATA
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == RESULT_AUTH_FAILED
|
||||
|
||||
|
||||
async def test_abort_on_connection_error(hass, tuya):
|
||||
"""Test when we have a network error."""
|
||||
@ -165,13 +132,6 @@ async def test_abort_on_connection_error(hass, tuya):
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == RESULT_CONN_ERROR
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=TUYA_USER_DATA
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == RESULT_CONN_ERROR
|
||||
|
||||
|
||||
async def test_options_flow(hass):
|
||||
"""Test config flow options."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user