Remove YAML configuration from Tuya (#50360)
* Remove YAML configuration from Tuya * Keep deprecation warning
This commit is contained in:
parent
ec08256ff0
commit
b2cee2e602
3 changed files with 3 additions and 84 deletions
|
@ -10,9 +10,8 @@ from tuyaha.tuyaapi import (
|
||||||
TuyaNetException,
|
TuyaNetException,
|
||||||
TuyaServerException,
|
TuyaServerException,
|
||||||
)
|
)
|
||||||
import voluptuous as vol
|
|
||||||
|
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_PASSWORD,
|
CONF_PASSWORD,
|
||||||
CONF_PLATFORM,
|
CONF_PLATFORM,
|
||||||
|
@ -67,22 +66,7 @@ TUYA_TYPE_TO_HA = {
|
||||||
TUYA_TRACKER = "tuya_tracker"
|
TUYA_TRACKER = "tuya_tracker"
|
||||||
STOP_CANCEL = "stop_event_cancel"
|
STOP_CANCEL = "stop_event_cancel"
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema(
|
CONFIG_SCHEMA = cv.deprecated(DOMAIN)
|
||||||
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,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def _update_discovery_interval(hass, interval):
|
def _update_discovery_interval(hass, interval):
|
||||||
|
@ -109,20 +93,6 @@ def _update_query_interval(hass, interval):
|
||||||
_LOGGER.warning(ex)
|
_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):
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||||
"""Set up Tuya platform."""
|
"""Set up Tuya platform."""
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,6 @@ class TuyaConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
self._password = None
|
self._password = None
|
||||||
self._platform = None
|
self._platform = None
|
||||||
self._username = None
|
self._username = None
|
||||||
self._is_import = False
|
|
||||||
|
|
||||||
def _save_entry(self):
|
def _save_entry(self):
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
|
@ -116,11 +115,6 @@ class TuyaConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
|
|
||||||
return RESULT_SUCCESS
|
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):
|
async def async_step_user(self, user_input=None):
|
||||||
"""Handle a flow initialized by the user."""
|
"""Handle a flow initialized by the user."""
|
||||||
if self._async_current_entries():
|
if self._async_current_entries():
|
||||||
|
@ -139,12 +133,7 @@ class TuyaConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
|
|
||||||
if result == RESULT_SUCCESS:
|
if result == RESULT_SUCCESS:
|
||||||
return self._save_entry()
|
return self._save_entry()
|
||||||
if result != RESULT_AUTH_FAILED or self._is_import:
|
if result != RESULT_AUTH_FAILED:
|
||||||
if self._is_import:
|
|
||||||
_LOGGER.error(
|
|
||||||
"Error importing from configuration.yaml: %s",
|
|
||||||
RESULT_LOG_MESSAGE.get(result, "Generic Error"),
|
|
||||||
)
|
|
||||||
return self.async_abort(reason=result)
|
return self.async_abort(reason=result)
|
||||||
errors["base"] = result
|
errors["base"] = result
|
||||||
|
|
||||||
|
|
|
@ -96,24 +96,6 @@ async def test_user(hass, tuya):
|
||||||
assert not result["result"].unique_id
|
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):
|
async def test_abort_if_already_setup(hass, tuya):
|
||||||
"""Test we abort if Tuya is already setup."""
|
"""Test we abort if Tuya is already setup."""
|
||||||
MockConfigEntry(domain=DOMAIN, data=TUYA_USER_DATA).add_to_hass(hass)
|
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["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||||
assert result["reason"] == RESULT_SINGLE_INSTANCE
|
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):
|
async def test_abort_on_invalid_credentials(hass, tuya):
|
||||||
"""Test when we have invalid credentials."""
|
"""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["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
assert result["errors"] == {"base": RESULT_AUTH_FAILED}
|
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):
|
async def test_abort_on_connection_error(hass, tuya):
|
||||||
"""Test when we have a network error."""
|
"""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["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||||
assert result["reason"] == RESULT_CONN_ERROR
|
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):
|
async def test_options_flow(hass):
|
||||||
"""Test config flow options."""
|
"""Test config flow options."""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue