mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Allow account linking to phase out services (#75447)
This commit is contained in:
parent
fe97f6791d
commit
460837e453
@ -33,7 +33,20 @@ async def async_provide_implementation(hass: HomeAssistant, domain: str):
|
||||
services = await _get_services(hass)
|
||||
|
||||
for service in services:
|
||||
if service["service"] == domain and CURRENT_VERSION >= service["min_version"]:
|
||||
if (
|
||||
service["service"] == domain
|
||||
and CURRENT_VERSION >= service["min_version"]
|
||||
and (
|
||||
service.get("accepts_new_authorizations", True)
|
||||
or (
|
||||
(entries := hass.config_entries.async_entries(domain))
|
||||
and any(
|
||||
entry.data.get("auth_implementation") == DOMAIN
|
||||
for entry in entries
|
||||
)
|
||||
)
|
||||
)
|
||||
):
|
||||
return [CloudOAuth2Implementation(hass, domain)]
|
||||
|
||||
return []
|
||||
|
@ -11,7 +11,7 @@ from homeassistant.components.cloud import account_link
|
||||
from homeassistant.helpers import config_entry_oauth2_flow
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
from tests.common import async_fire_time_changed, mock_platform
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed, mock_platform
|
||||
|
||||
TEST_DOMAIN = "oauth2_test"
|
||||
|
||||
@ -38,6 +38,18 @@ def flow_handler(hass):
|
||||
|
||||
async def test_setup_provide_implementation(hass):
|
||||
"""Test that we provide implementations."""
|
||||
legacy_entry = MockConfigEntry(
|
||||
domain="legacy",
|
||||
version=1,
|
||||
data={"auth_implementation": "cloud"},
|
||||
)
|
||||
none_cloud_entry = MockConfigEntry(
|
||||
domain="no_cloud",
|
||||
version=1,
|
||||
data={"auth_implementation": "somethingelse"},
|
||||
)
|
||||
none_cloud_entry.add_to_hass(hass)
|
||||
legacy_entry.add_to_hass(hass)
|
||||
account_link.async_setup(hass)
|
||||
|
||||
with patch(
|
||||
@ -45,6 +57,21 @@ async def test_setup_provide_implementation(hass):
|
||||
return_value=[
|
||||
{"service": "test", "min_version": "0.1.0"},
|
||||
{"service": "too_new", "min_version": "1000000.0.0"},
|
||||
{
|
||||
"service": "deprecated",
|
||||
"min_version": "0.1.0",
|
||||
"accepts_new_authorizations": False,
|
||||
},
|
||||
{
|
||||
"service": "legacy",
|
||||
"min_version": "0.1.0",
|
||||
"accepts_new_authorizations": False,
|
||||
},
|
||||
{
|
||||
"service": "no_cloud",
|
||||
"min_version": "0.1.0",
|
||||
"accepts_new_authorizations": False,
|
||||
},
|
||||
],
|
||||
):
|
||||
assert (
|
||||
@ -57,15 +84,33 @@ async def test_setup_provide_implementation(hass):
|
||||
await config_entry_oauth2_flow.async_get_implementations(hass, "too_new")
|
||||
== {}
|
||||
)
|
||||
assert (
|
||||
await config_entry_oauth2_flow.async_get_implementations(hass, "deprecated")
|
||||
== {}
|
||||
)
|
||||
assert (
|
||||
await config_entry_oauth2_flow.async_get_implementations(hass, "no_cloud")
|
||||
== {}
|
||||
)
|
||||
|
||||
implementations = await config_entry_oauth2_flow.async_get_implementations(
|
||||
hass, "test"
|
||||
)
|
||||
|
||||
legacy_implementations = (
|
||||
await config_entry_oauth2_flow.async_get_implementations(hass, "legacy")
|
||||
)
|
||||
|
||||
assert "cloud" in implementations
|
||||
assert implementations["cloud"].domain == "cloud"
|
||||
assert implementations["cloud"].service == "test"
|
||||
assert implementations["cloud"].hass is hass
|
||||
|
||||
assert "cloud" in legacy_implementations
|
||||
assert legacy_implementations["cloud"].domain == "cloud"
|
||||
assert legacy_implementations["cloud"].service == "legacy"
|
||||
assert legacy_implementations["cloud"].hass is hass
|
||||
|
||||
|
||||
async def test_get_services_cached(hass):
|
||||
"""Test that we cache services."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user