Skip to content

Commit f249024

Browse files
committed
Handle landing page correctly
1 parent c961ae3 commit f249024

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

supervisor/resolution/evaluations/core_version.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22

33
from datetime import datetime, timedelta
44

5-
from awesomeversion import AwesomeVersion, AwesomeVersionException
5+
from awesomeversion import (
6+
AwesomeVersion,
7+
AwesomeVersionException,
8+
AwesomeVersionStrategy,
9+
)
610

711
from ...const import CoreState
812
from ...coresys import CoreSys
13+
from ...homeassistant.const import LANDINGPAGE
914
from ..const import UnsupportedReason
1015
from .base import EvaluateBase
1116

@@ -40,6 +45,10 @@ async def evaluate(self) -> bool:
4045
):
4146
return False
4247

48+
# Skip evaluation for landingpage version
49+
if current == LANDINGPAGE:
50+
return False
51+
4352
try:
4453
# Calculate if the current version was released more than 2 years ago
4554
# Home Assistant releases happen monthly, so approximately 24 versions per 2 years
@@ -55,7 +64,10 @@ async def evaluate(self) -> bool:
5564
cutoff_month = two_years_ago.month
5665

5766
# Create a cutoff version based on the date 2 years ago
58-
cutoff_version = AwesomeVersion(f"{cutoff_year}.{cutoff_month}")
67+
cutoff_version = AwesomeVersion(
68+
f"{cutoff_year}.{cutoff_month}",
69+
ensure_strategy=AwesomeVersionStrategy.CALVER,
70+
)
5971

6072
# Compare current version with the cutoff
6173
return current < cutoff_version

tests/resolution/evaluation/test_evaluate_core_version.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from supervisor.const import CoreState
1010
from supervisor.coresys import CoreSys
11+
from supervisor.homeassistant.const import LANDINGPAGE
1112
from supervisor.homeassistant.module import HomeAssistant
1213
from supervisor.resolution.evaluations.core_version import EvaluateCoreVersion
1314

@@ -22,6 +23,7 @@
2223
(f"{datetime.now().year - 2}.1", True), # 2 years old, unsupported
2324
(f"{datetime.now().year - 3}.1", True), # 3 years old, unsupported
2425
("2021.6.0", True), # Very old version, unsupported
26+
("landingpage", False), # Landingpage version, should be supported
2527
(None, False), # No current version info, check skipped
2628
],
2729
)
@@ -96,6 +98,29 @@ async def test_core_version_invalid_format(coresys: CoreSys):
9698
assert evaluation.reason not in coresys.resolution.unsupported
9799

98100

101+
async def test_core_version_landingpage(coresys: CoreSys):
102+
"""Test evaluation with landingpage version."""
103+
evaluation = EvaluateCoreVersion(coresys)
104+
await coresys.core.set_state(CoreState.RUNNING)
105+
106+
with (
107+
patch.object(
108+
HomeAssistant,
109+
"version",
110+
new=PropertyMock(return_value=LANDINGPAGE),
111+
),
112+
patch.object(
113+
HomeAssistant,
114+
"latest_version",
115+
new=PropertyMock(return_value=AwesomeVersion("2024.12.0")),
116+
),
117+
):
118+
assert evaluation.reason not in coresys.resolution.unsupported
119+
await evaluation()
120+
# Landingpage should never be marked as unsupported
121+
assert evaluation.reason not in coresys.resolution.unsupported
122+
123+
99124
async def test_did_run(coresys: CoreSys):
100125
"""Test that the evaluation ran as expected."""
101126
evaluation = EvaluateCoreVersion(coresys)

0 commit comments

Comments
 (0)