Remove Xbox YAML configuration (#94094)

This commit is contained in:
G Johansson 2023-06-06 08:22:12 +02:00 committed by GitHub
parent 4b4660994c
commit 9cbb993296
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 67 deletions

View File

@ -6,7 +6,6 @@ from dataclasses import dataclass
from datetime import timedelta from datetime import timedelta
import logging import logging
import voluptuous as vol
from xbox.webapi.api.client import XboxLiveClient from xbox.webapi.api.client import XboxLiveClient
from xbox.webapi.api.provider.catalog.const import SYSTEM_PFN_ID_MAP from xbox.webapi.api.provider.catalog.const import SYSTEM_PFN_ID_MAP
from xbox.webapi.api.provider.catalog.models import AlternateIdType, Product from xbox.webapi.api.provider.catalog.models import AlternateIdType, Product
@ -20,17 +19,14 @@ from xbox.webapi.api.provider.smartglass.models import (
SmartglassConsoleStatus, SmartglassConsoleStatus,
) )
from homeassistant.components import application_credentials
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 Platform
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import ( from homeassistant.helpers import (
aiohttp_client, aiohttp_client,
config_entry_oauth2_flow, config_entry_oauth2_flow,
config_validation as cv, config_validation as cv,
) )
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
from homeassistant.helpers.typing import ConfigType
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from . import api from . import api
@ -38,20 +34,7 @@ from .const import DOMAIN
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
CONFIG_SCHEMA = vol.Schema( CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
vol.All(
cv.deprecated(DOMAIN),
{
DOMAIN: vol.Schema(
{
vol.Required(CONF_CLIENT_ID): cv.string,
vol.Required(CONF_CLIENT_SECRET): cv.string,
}
)
},
),
extra=vol.ALLOW_EXTRA,
)
PLATFORMS = [ PLATFORMS = [
Platform.BINARY_SENSOR, Platform.BINARY_SENSOR,
@ -61,40 +44,6 @@ PLATFORMS = [
] ]
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the xbox component."""
hass.data[DOMAIN] = {}
if DOMAIN not in config:
return True
await application_credentials.async_import_client_credential(
hass,
DOMAIN,
application_credentials.ClientCredential(
config[DOMAIN][CONF_CLIENT_ID], config[DOMAIN][CONF_CLIENT_SECRET]
),
)
async_create_issue(
hass,
DOMAIN,
"deprecated_yaml",
breaks_in_ha_version="2022.9.0",
is_fixable=False,
severity=IssueSeverity.WARNING,
translation_key="deprecated_yaml",
)
_LOGGER.warning(
"Configuration of Xbox integration in YAML is deprecated and "
"will be removed in Home Assistant 2022.9.; Your existing configuration "
"(including OAuth Application Credentials) has been imported into "
"the UI automatically and can be safely removed from your "
"configuration.yaml file"
)
return True
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up xbox from a config entry.""" """Set up xbox from a config entry."""
implementation = ( implementation = (
@ -118,7 +67,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
coordinator = XboxUpdateCoordinator(hass, client, consoles) coordinator = XboxUpdateCoordinator(hass, client, consoles)
await coordinator.async_config_entry_first_refresh() await coordinator.async_config_entry_first_refresh()
hass.data[DOMAIN][entry.entry_id] = { hass.data.setdefault(DOMAIN, {})[entry.entry_id] = {
"client": XboxLiveClient(auth), "client": XboxLiveClient(auth),
"consoles": consoles, "consoles": consoles,
"coordinator": coordinator, "coordinator": coordinator,

View File

@ -13,11 +13,5 @@
"create_entry": { "create_entry": {
"default": "[%key:common::config_flow::create_entry::authenticated%]" "default": "[%key:common::config_flow::create_entry::authenticated%]"
} }
},
"issues": {
"deprecated_yaml": {
"title": "The Xbox YAML configuration is being removed",
"description": "Configuring the Xbox in configuration.yaml is being removed in Home Assistant 2022.9.\n\nYour existing OAuth Application Credentials and access settings have been imported into the UI automatically. Remove the YAML configuration from your configuration.yaml file and restart Home Assistant to fix this issue."
}
} }
} }

View File

@ -3,6 +3,10 @@ from http import HTTPStatus
from unittest.mock import patch from unittest.mock import patch
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.xbox.const import DOMAIN, OAUTH2_AUTHORIZE, OAUTH2_TOKEN from homeassistant.components.xbox.const import DOMAIN, OAUTH2_AUTHORIZE, OAUTH2_TOKEN
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
@ -33,13 +37,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, "application_credentials", {})
hass, await async_import_client_credential(
"xbox", hass, DOMAIN, ClientCredential(CLIENT_ID, CLIENT_SECRET), "imported-cred"
{
"xbox": {"client_id": CLIENT_ID, "client_secret": CLIENT_SECRET},
"http": {"base_url": "https://example.com"},
},
) )
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(