Adjust version comparison in HA Cloud account linking (#76978)

This commit is contained in:
Franck Nijhof 2022-08-18 14:06:50 +02:00 committed by GitHub
parent 1aef60c81c
commit c212fe7ca5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -18,6 +18,9 @@ CACHE_TIMEOUT = 3600
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
CURRENT_VERSION = AwesomeVersion(HA_VERSION) CURRENT_VERSION = AwesomeVersion(HA_VERSION)
CURRENT_PLAIN_VERSION = AwesomeVersion(
CURRENT_VERSION.string.removesuffix(f"{CURRENT_VERSION.modifier}")
)
@callback @callback
@ -35,7 +38,7 @@ async def async_provide_implementation(hass: HomeAssistant, domain: str):
for service in services: for service in services:
if ( if (
service["service"] == domain service["service"] == domain
and CURRENT_VERSION >= service["min_version"] and CURRENT_PLAIN_VERSION >= service["min_version"]
and ( and (
service.get("accepts_new_authorizations", True) service.get("accepts_new_authorizations", True)
or ( or (

View File

@ -57,6 +57,7 @@ async def test_setup_provide_implementation(hass):
return_value=[ return_value=[
{"service": "test", "min_version": "0.1.0"}, {"service": "test", "min_version": "0.1.0"},
{"service": "too_new", "min_version": "1000000.0.0"}, {"service": "too_new", "min_version": "1000000.0.0"},
{"service": "dev", "min_version": "2022.9.0"},
{ {
"service": "deprecated", "service": "deprecated",
"min_version": "0.1.0", "min_version": "0.1.0",
@ -73,6 +74,8 @@ async def test_setup_provide_implementation(hass):
"accepts_new_authorizations": False, "accepts_new_authorizations": False,
}, },
], ],
), patch(
"homeassistant.components.cloud.account_link.HA_VERSION", "2022.9.0.dev20220817"
): ):
assert ( assert (
await config_entry_oauth2_flow.async_get_implementations( await config_entry_oauth2_flow.async_get_implementations(
@ -101,6 +104,10 @@ async def test_setup_provide_implementation(hass):
await config_entry_oauth2_flow.async_get_implementations(hass, "legacy") await config_entry_oauth2_flow.async_get_implementations(hass, "legacy")
) )
dev_implementations = await config_entry_oauth2_flow.async_get_implementations(
hass, "dev"
)
assert "cloud" in implementations assert "cloud" in implementations
assert implementations["cloud"].domain == "cloud" assert implementations["cloud"].domain == "cloud"
assert implementations["cloud"].service == "test" assert implementations["cloud"].service == "test"
@ -111,6 +118,11 @@ async def test_setup_provide_implementation(hass):
assert legacy_implementations["cloud"].service == "legacy" assert legacy_implementations["cloud"].service == "legacy"
assert legacy_implementations["cloud"].hass is hass assert legacy_implementations["cloud"].hass is hass
assert "cloud" in dev_implementations
assert dev_implementations["cloud"].domain == "cloud"
assert dev_implementations["cloud"].service == "dev"
assert dev_implementations["cloud"].hass is hass
async def test_get_services_cached(hass): async def test_get_services_cached(hass):
"""Test that we cache services.""" """Test that we cache services."""