Remove config import in Neato (#107967)
Co-authored-by: jbouwh <jan@jbsoft.nl>
This commit is contained in:
parent
bc9a85405e
commit
ad35113e86
3 changed files with 15 additions and 81 deletions
|
@ -4,42 +4,19 @@ import logging
|
||||||
import aiohttp
|
import aiohttp
|
||||||
from pybotvac import Account
|
from pybotvac import Account
|
||||||
from pybotvac.exceptions import NeatoException
|
from pybotvac.exceptions import NeatoException
|
||||||
import voluptuous as vol
|
|
||||||
|
|
||||||
from homeassistant.components.application_credentials import (
|
|
||||||
ClientCredential,
|
|
||||||
async_import_client_credential,
|
|
||||||
)
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET, CONF_TOKEN, Platform
|
from homeassistant.const import CONF_TOKEN, Platform
|
||||||
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||||
from homeassistant.helpers import config_entry_oauth2_flow, config_validation as cv
|
from homeassistant.helpers import config_entry_oauth2_flow
|
||||||
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
|
||||||
from homeassistant.helpers.typing import ConfigType
|
|
||||||
|
|
||||||
from . import api
|
from . import api
|
||||||
from .const import NEATO_CONFIG, NEATO_DOMAIN, NEATO_LOGIN
|
from .const import NEATO_DOMAIN, NEATO_LOGIN
|
||||||
from .hub import NeatoHub
|
from .hub import NeatoHub
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema(
|
|
||||||
vol.All(
|
|
||||||
cv.deprecated(NEATO_DOMAIN),
|
|
||||||
{
|
|
||||||
NEATO_DOMAIN: vol.Schema(
|
|
||||||
{
|
|
||||||
vol.Required(CONF_CLIENT_ID): cv.string,
|
|
||||||
vol.Required(CONF_CLIENT_SECRET): cv.string,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
},
|
|
||||||
),
|
|
||||||
extra=vol.ALLOW_EXTRA,
|
|
||||||
)
|
|
||||||
|
|
||||||
PLATFORMS = [
|
PLATFORMS = [
|
||||||
Platform.BUTTON,
|
Platform.BUTTON,
|
||||||
Platform.CAMERA,
|
Platform.CAMERA,
|
||||||
|
@ -49,49 +26,9 @@ PLATFORMS = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|
||||||
"""Set up the Neato component."""
|
|
||||||
hass.data[NEATO_DOMAIN] = {}
|
|
||||||
|
|
||||||
if NEATO_DOMAIN not in config:
|
|
||||||
return True
|
|
||||||
|
|
||||||
hass.data[NEATO_CONFIG] = config[NEATO_DOMAIN]
|
|
||||||
await async_import_client_credential(
|
|
||||||
hass,
|
|
||||||
NEATO_DOMAIN,
|
|
||||||
ClientCredential(
|
|
||||||
config[NEATO_DOMAIN][CONF_CLIENT_ID],
|
|
||||||
config[NEATO_DOMAIN][CONF_CLIENT_SECRET],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
_LOGGER.warning(
|
|
||||||
"Configuration of Neato integration in YAML is deprecated and "
|
|
||||||
"will be removed in a future release; Your existing OAuth "
|
|
||||||
"Application Credentials have been imported into the UI "
|
|
||||||
"automatically and can be safely removed from your "
|
|
||||||
"configuration.yaml file"
|
|
||||||
)
|
|
||||||
async_create_issue(
|
|
||||||
hass,
|
|
||||||
HOMEASSISTANT_DOMAIN,
|
|
||||||
f"deprecated_yaml_{NEATO_DOMAIN}",
|
|
||||||
breaks_in_ha_version="2024.2.0",
|
|
||||||
is_fixable=False,
|
|
||||||
issue_domain=NEATO_DOMAIN,
|
|
||||||
severity=IssueSeverity.WARNING,
|
|
||||||
translation_key="deprecated_yaml",
|
|
||||||
translation_placeholders={
|
|
||||||
"domain": NEATO_DOMAIN,
|
|
||||||
"integration_title": "Neato Botvac",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up config entry."""
|
"""Set up config entry."""
|
||||||
|
hass.data.setdefault(NEATO_DOMAIN, {})
|
||||||
if CONF_TOKEN not in entry.data:
|
if CONF_TOKEN not in entry.data:
|
||||||
raise ConfigEntryAuthFailed
|
raise ConfigEntryAuthFailed
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
NEATO_DOMAIN = "neato"
|
NEATO_DOMAIN = "neato"
|
||||||
|
|
||||||
CONF_VENDOR = "vendor"
|
CONF_VENDOR = "vendor"
|
||||||
NEATO_CONFIG = "neato_config"
|
|
||||||
NEATO_LOGIN = "neato_login"
|
NEATO_LOGIN = "neato_login"
|
||||||
NEATO_MAP_DATA = "neato_map_data"
|
NEATO_MAP_DATA = "neato_map_data"
|
||||||
NEATO_PERSISTENT_MAPS = "neato_persistent_maps"
|
NEATO_PERSISTENT_MAPS = "neato_persistent_maps"
|
||||||
|
|
|
@ -4,6 +4,10 @@ from unittest.mock import patch
|
||||||
from pybotvac.neato import Neato
|
from pybotvac.neato import Neato
|
||||||
|
|
||||||
from homeassistant import config_entries, data_entry_flow, setup
|
from homeassistant import config_entries, data_entry_flow, setup
|
||||||
|
from homeassistant.components.application_credentials import (
|
||||||
|
ClientCredential,
|
||||||
|
async_import_client_credential,
|
||||||
|
)
|
||||||
from homeassistant.components.neato.const import NEATO_DOMAIN
|
from homeassistant.components.neato.const import NEATO_DOMAIN
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import config_entry_oauth2_flow
|
from homeassistant.helpers import config_entry_oauth2_flow
|
||||||
|
@ -27,12 +31,9 @@ async def test_full_flow(
|
||||||
current_request_with_host: None,
|
current_request_with_host: None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Check full flow."""
|
"""Check full flow."""
|
||||||
assert await setup.async_setup_component(
|
assert await setup.async_setup_component(hass, "neato", {})
|
||||||
hass,
|
await async_import_client_credential(
|
||||||
"neato",
|
hass, NEATO_DOMAIN, ClientCredential(CLIENT_ID, CLIENT_SECRET)
|
||||||
{
|
|
||||||
"neato": {"client_id": CLIENT_ID, "client_secret": CLIENT_SECRET},
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -101,12 +102,9 @@ async def test_reauth(
|
||||||
current_request_with_host: None,
|
current_request_with_host: None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test initialization of the reauth flow."""
|
"""Test initialization of the reauth flow."""
|
||||||
assert await setup.async_setup_component(
|
assert await setup.async_setup_component(hass, "neato", {})
|
||||||
hass,
|
await async_import_client_credential(
|
||||||
"neato",
|
hass, NEATO_DOMAIN, ClientCredential(CLIENT_ID, CLIENT_SECRET)
|
||||||
{
|
|
||||||
"neato": {"client_id": CLIENT_ID, "client_secret": CLIENT_SECRET},
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
MockConfigEntry(
|
MockConfigEntry(
|
||||||
|
|
Loading…
Add table
Reference in a new issue