mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 01:37:08 +00:00
Add Neato application credentials platform and deprecate configuration.yaml (#72175)
This commit is contained in:
parent
36e9088e6b
commit
c028db00de
@ -2,10 +2,14 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
from pybotvac import Account, Neato
|
from pybotvac import Account
|
||||||
from pybotvac.exceptions import NeatoException
|
from pybotvac.exceptions import NeatoException
|
||||||
import voluptuous as vol
|
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_CLIENT_ID, CONF_CLIENT_SECRET, CONF_TOKEN, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -13,7 +17,7 @@ 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, config_validation as cv
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
from . import api, config_flow
|
from . import api
|
||||||
from .const import NEATO_CONFIG, NEATO_DOMAIN, NEATO_LOGIN
|
from .const import NEATO_CONFIG, NEATO_DOMAIN, NEATO_LOGIN
|
||||||
from .hub import NeatoHub
|
from .hub import NeatoHub
|
||||||
|
|
||||||
@ -21,6 +25,8 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema(
|
CONFIG_SCHEMA = vol.Schema(
|
||||||
|
vol.All(
|
||||||
|
cv.deprecated(NEATO_DOMAIN),
|
||||||
{
|
{
|
||||||
NEATO_DOMAIN: vol.Schema(
|
NEATO_DOMAIN: vol.Schema(
|
||||||
{
|
{
|
||||||
@ -29,6 +35,7 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
),
|
||||||
extra=vol.ALLOW_EXTRA,
|
extra=vol.ALLOW_EXTRA,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -43,18 +50,21 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
hass.data[NEATO_CONFIG] = config[NEATO_DOMAIN]
|
hass.data[NEATO_CONFIG] = config[NEATO_DOMAIN]
|
||||||
vendor = Neato()
|
await async_import_client_credential(
|
||||||
config_flow.OAuth2FlowHandler.async_register_implementation(
|
|
||||||
hass,
|
|
||||||
api.NeatoImplementation(
|
|
||||||
hass,
|
hass,
|
||||||
NEATO_DOMAIN,
|
NEATO_DOMAIN,
|
||||||
|
ClientCredential(
|
||||||
config[NEATO_DOMAIN][CONF_CLIENT_ID],
|
config[NEATO_DOMAIN][CONF_CLIENT_ID],
|
||||||
config[NEATO_DOMAIN][CONF_CLIENT_SECRET],
|
config[NEATO_DOMAIN][CONF_CLIENT_SECRET],
|
||||||
vendor.auth_endpoint,
|
|
||||||
vendor.token_endpoint,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
_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"
|
||||||
|
)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ from typing import Any
|
|||||||
import pybotvac
|
import pybotvac
|
||||||
|
|
||||||
from homeassistant import config_entries, core
|
from homeassistant import config_entries, core
|
||||||
|
from homeassistant.components.application_credentials import AuthImplementation
|
||||||
from homeassistant.helpers import config_entry_oauth2_flow
|
from homeassistant.helpers import config_entry_oauth2_flow
|
||||||
|
|
||||||
|
|
||||||
@ -35,7 +36,7 @@ class ConfigEntryAuth(pybotvac.OAuthSession): # type: ignore[misc]
|
|||||||
return self.session.token["access_token"] # type: ignore[no-any-return]
|
return self.session.token["access_token"] # type: ignore[no-any-return]
|
||||||
|
|
||||||
|
|
||||||
class NeatoImplementation(config_entry_oauth2_flow.LocalOAuth2Implementation):
|
class NeatoImplementation(AuthImplementation):
|
||||||
"""Neato implementation of LocalOAuth2Implementation.
|
"""Neato implementation of LocalOAuth2Implementation.
|
||||||
|
|
||||||
We need this class because we have to add client_secret and scope to the authorization request.
|
We need this class because we have to add client_secret and scope to the authorization request.
|
||||||
|
28
homeassistant/components/neato/application_credentials.py
Normal file
28
homeassistant/components/neato/application_credentials.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
"""Application credentials platform for neato."""
|
||||||
|
|
||||||
|
from pybotvac import Neato
|
||||||
|
|
||||||
|
from homeassistant.components.application_credentials import (
|
||||||
|
AuthorizationServer,
|
||||||
|
ClientCredential,
|
||||||
|
)
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers import config_entry_oauth2_flow
|
||||||
|
|
||||||
|
from . import api
|
||||||
|
|
||||||
|
|
||||||
|
async def async_get_auth_implementation(
|
||||||
|
hass: HomeAssistant, auth_domain: str, credential: ClientCredential
|
||||||
|
) -> config_entry_oauth2_flow.AbstractOAuth2Implementation:
|
||||||
|
"""Return auth implementation for a custom auth implementation."""
|
||||||
|
vendor = Neato()
|
||||||
|
return api.NeatoImplementation(
|
||||||
|
hass,
|
||||||
|
auth_domain,
|
||||||
|
credential,
|
||||||
|
AuthorizationServer(
|
||||||
|
authorize_url=vendor.auth_endpoint,
|
||||||
|
token_url=vendor.token_endpoint,
|
||||||
|
),
|
||||||
|
)
|
@ -5,7 +5,7 @@
|
|||||||
"documentation": "https://www.home-assistant.io/integrations/neato",
|
"documentation": "https://www.home-assistant.io/integrations/neato",
|
||||||
"requirements": ["pybotvac==0.0.23"],
|
"requirements": ["pybotvac==0.0.23"],
|
||||||
"codeowners": ["@dshokouhi", "@Santobert"],
|
"codeowners": ["@dshokouhi", "@Santobert"],
|
||||||
"dependencies": ["auth"],
|
"dependencies": ["application_credentials"],
|
||||||
"iot_class": "cloud_polling",
|
"iot_class": "cloud_polling",
|
||||||
"loggers": ["pybotvac"]
|
"loggers": ["pybotvac"]
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ APPLICATION_CREDENTIALS = [
|
|||||||
"geocaching",
|
"geocaching",
|
||||||
"google",
|
"google",
|
||||||
"home_connect",
|
"home_connect",
|
||||||
|
"neato",
|
||||||
"netatmo",
|
"netatmo",
|
||||||
"spotify",
|
"spotify",
|
||||||
"xbox",
|
"xbox",
|
||||||
|
@ -27,7 +27,6 @@ async def test_full_flow(
|
|||||||
"neato",
|
"neato",
|
||||||
{
|
{
|
||||||
"neato": {"client_id": CLIENT_ID, "client_secret": CLIENT_SECRET},
|
"neato": {"client_id": CLIENT_ID, "client_secret": CLIENT_SECRET},
|
||||||
"http": {"base_url": "https://example.com"},
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -99,7 +98,6 @@ async def test_reauth(
|
|||||||
"neato",
|
"neato",
|
||||||
{
|
{
|
||||||
"neato": {"client_id": CLIENT_ID, "client_secret": CLIENT_SECRET},
|
"neato": {"client_id": CLIENT_ID, "client_secret": CLIENT_SECRET},
|
||||||
"http": {"base_url": "https://example.com"},
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user