mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Add SENZ application credentials platform (#72338)
This commit is contained in:
parent
9763b44357
commit
dc76cce96b
@ -4,10 +4,14 @@ from __future__ import annotations
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from aiosenz import AUTHORIZATION_ENDPOINT, SENZAPI, TOKEN_ENDPOINT, Thermostat
|
from aiosenz import SENZAPI, Thermostat
|
||||||
from httpx import RequestError
|
from httpx import RequestError
|
||||||
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, Platform
|
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -20,7 +24,6 @@ from homeassistant.helpers import (
|
|||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
|
||||||
from . import config_flow
|
|
||||||
from .api import SENZConfigEntryAuth
|
from .api import SENZConfigEntryAuth
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
@ -29,14 +32,17 @@ UPDATE_INTERVAL = timedelta(seconds=30)
|
|||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema(
|
CONFIG_SCHEMA = vol.Schema(
|
||||||
{
|
vol.All(
|
||||||
DOMAIN: vol.Schema(
|
cv.deprecated(DOMAIN),
|
||||||
{
|
{
|
||||||
vol.Required(CONF_CLIENT_ID): cv.string,
|
DOMAIN: vol.Schema(
|
||||||
vol.Required(CONF_CLIENT_SECRET): cv.string,
|
{
|
||||||
}
|
vol.Required(CONF_CLIENT_ID): cv.string,
|
||||||
)
|
vol.Required(CONF_CLIENT_SECRET): cv.string,
|
||||||
},
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
),
|
||||||
extra=vol.ALLOW_EXTRA,
|
extra=vol.ALLOW_EXTRA,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -52,17 +58,21 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
if DOMAIN not in config:
|
if DOMAIN not in config:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
config_flow.OAuth2FlowHandler.async_register_implementation(
|
await async_import_client_credential(
|
||||||
hass,
|
hass,
|
||||||
config_entry_oauth2_flow.LocalOAuth2Implementation(
|
DOMAIN,
|
||||||
hass,
|
ClientCredential(
|
||||||
DOMAIN,
|
|
||||||
config[DOMAIN][CONF_CLIENT_ID],
|
config[DOMAIN][CONF_CLIENT_ID],
|
||||||
config[DOMAIN][CONF_CLIENT_SECRET],
|
config[DOMAIN][CONF_CLIENT_SECRET],
|
||||||
AUTHORIZATION_ENDPOINT,
|
|
||||||
TOKEN_ENDPOINT,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
_LOGGER.warning(
|
||||||
|
"Configuration of SENZ 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
|
||||||
|
|
||||||
|
14
homeassistant/components/senz/application_credentials.py
Normal file
14
homeassistant/components/senz/application_credentials.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
"""Application credentials platform for senz."""
|
||||||
|
|
||||||
|
from aiosenz import AUTHORIZATION_ENDPOINT, TOKEN_ENDPOINT
|
||||||
|
|
||||||
|
from homeassistant.components.application_credentials import AuthorizationServer
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
|
||||||
|
async def async_get_authorization_server(hass: HomeAssistant) -> AuthorizationServer:
|
||||||
|
"""Return authorization server."""
|
||||||
|
return AuthorizationServer(
|
||||||
|
authorize_url=AUTHORIZATION_ENDPOINT,
|
||||||
|
token_url=TOKEN_ENDPOINT,
|
||||||
|
)
|
@ -4,7 +4,7 @@
|
|||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/senz",
|
"documentation": "https://www.home-assistant.io/integrations/senz",
|
||||||
"requirements": ["aiosenz==1.0.0"],
|
"requirements": ["aiosenz==1.0.0"],
|
||||||
"dependencies": ["auth"],
|
"dependencies": ["application_credentials"],
|
||||||
"codeowners": ["@milanmeu"],
|
"codeowners": ["@milanmeu"],
|
||||||
"iot_class": "cloud_polling"
|
"iot_class": "cloud_polling"
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ APPLICATION_CREDENTIALS = [
|
|||||||
"home_connect",
|
"home_connect",
|
||||||
"neato",
|
"neato",
|
||||||
"netatmo",
|
"netatmo",
|
||||||
|
"senz",
|
||||||
"spotify",
|
"spotify",
|
||||||
"withings",
|
"withings",
|
||||||
"xbox",
|
"xbox",
|
||||||
|
@ -24,7 +24,6 @@ async def test_full_flow(
|
|||||||
"senz",
|
"senz",
|
||||||
{
|
{
|
||||||
"senz": {"client_id": CLIENT_ID, "client_secret": CLIENT_SECRET},
|
"senz": {"client_id": CLIENT_ID, "client_secret": CLIENT_SECRET},
|
||||||
"http": {"base_url": "https://example.com"},
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user