Deprecate YAML config for SimpliSafe (0.119 removal) (#41896)

* Deprecate YAML config for SimpliSafe (0.119 removal)

* Remove import step from config flow
This commit is contained in:
Aaron Bach 2020-10-15 14:28:09 -06:00 committed by GitHub
parent 32675e0e38
commit 6114006b8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 78 deletions

View File

@ -16,11 +16,10 @@ from simplipy.websocket import (
) )
import voluptuous as vol import voluptuous as vol
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_REAUTH from homeassistant.config_entries import SOURCE_REAUTH
from homeassistant.const import ( from homeassistant.const import (
ATTR_CODE, ATTR_CODE,
CONF_CODE, CONF_CODE,
CONF_PASSWORD,
CONF_TOKEN, CONF_TOKEN,
CONF_USERNAME, CONF_USERNAME,
EVENT_HOMEASSISTANT_STOP, EVENT_HOMEASSISTANT_STOP,
@ -60,8 +59,6 @@ from .const import (
VOLUMES, VOLUMES,
) )
CONF_ACCOUNTS = "accounts"
DATA_LISTENER = "listener" DATA_LISTENER = "listener"
TOPIC_UPDATE_REST_API = "simplisafe_update_rest_api_{0}" TOPIC_UPDATE_REST_API = "simplisafe_update_rest_api_{0}"
TOPIC_UPDATE_WEBSOCKET = "simplisafe_update_websocket_{0}" TOPIC_UPDATE_WEBSOCKET = "simplisafe_update_websocket_{0}"
@ -138,26 +135,7 @@ SERVICE_SET_SYSTEM_PROPERTIES_SCHEMA = SERVICE_BASE_SCHEMA.extend(
} }
) )
ACCOUNT_CONFIG_SCHEMA = vol.Schema( CONFIG_SCHEMA = cv.deprecated(DOMAIN, invalidation_version="0.119")
{
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Optional(CONF_CODE): cv.string,
}
)
CONFIG_SCHEMA = vol.Schema(
{
DOMAIN: vol.Schema(
{
vol.Optional(CONF_ACCOUNTS): vol.All(
cv.ensure_list, [ACCOUNT_CONFIG_SCHEMA]
)
}
)
},
extra=vol.ALLOW_EXTRA,
)
@callback @callback
@ -189,28 +167,7 @@ async def async_register_base_station(hass, system, config_entry_id):
async def async_setup(hass, config): async def async_setup(hass, config):
"""Set up the SimpliSafe component.""" """Set up the SimpliSafe component."""
hass.data[DOMAIN] = {} hass.data[DOMAIN] = {DATA_CLIENT: {}, DATA_LISTENER: {}}
hass.data[DOMAIN][DATA_CLIENT] = {}
hass.data[DOMAIN][DATA_LISTENER] = {}
if DOMAIN not in config:
return True
conf = config[DOMAIN]
for account in conf[CONF_ACCOUNTS]:
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data={
CONF_USERNAME: account[CONF_USERNAME],
CONF_PASSWORD: account[CONF_PASSWORD],
CONF_CODE: account.get(CONF_CODE),
},
)
)
return True return True

View File

@ -93,10 +93,6 @@ class SimpliSafeFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
return self.async_abort(reason="reauth_successful") return self.async_abort(reason="reauth_successful")
return self.async_create_entry(title=self._username, data=user_input) return self.async_create_entry(title=self._username, data=user_input)
async def async_step_import(self, import_config):
"""Import a config entry from configuration.yaml."""
return await self.async_step_user(import_config)
async def async_step_mfa(self, user_input=None): async def async_step_mfa(self, user_input=None):
"""Handle multi-factor auth confirmation.""" """Handle multi-factor auth confirmation."""
if user_input is None: if user_input is None:

View File

@ -7,7 +7,7 @@ from simplipy.errors import (
from homeassistant import data_entry_flow from homeassistant import data_entry_flow
from homeassistant.components.simplisafe import DOMAIN from homeassistant.components.simplisafe import DOMAIN
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_CODE, CONF_PASSWORD, CONF_TOKEN, CONF_USERNAME from homeassistant.const import CONF_CODE, CONF_PASSWORD, CONF_TOKEN, CONF_USERNAME
from tests.async_mock import AsyncMock, MagicMock, PropertyMock, patch from tests.async_mock import AsyncMock, MagicMock, PropertyMock, patch
@ -88,39 +88,13 @@ async def test_options_flow(hass):
async def test_show_form(hass): async def test_show_form(hass):
"""Test that the form is served with no input.""" """Test that the form is served with no input."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_IMPORT} DOMAIN, context={"source": SOURCE_USER}
) )
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "user" assert result["step_id"] == "user"
async def test_step_import(hass):
"""Test that the import step works."""
conf = {
CONF_USERNAME: "user@email.com",
CONF_PASSWORD: "password",
CONF_CODE: "1234",
}
with patch(
"homeassistant.components.simplisafe.async_setup_entry", return_value=True
), patch(
"simplipy.API.login_via_credentials", new=AsyncMock(return_value=mock_api())
):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}, data=conf
)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["title"] == "user@email.com"
assert result["data"] == {
CONF_USERNAME: "user@email.com",
CONF_TOKEN: "12345abc",
CONF_CODE: "1234",
}
async def test_step_reauth(hass): async def test_step_reauth(hass):
"""Test that the reauth step works.""" """Test that the reauth step works."""
MockConfigEntry( MockConfigEntry(