-
Notifications
You must be signed in to change notification settings - Fork 748
Check Core version and raise unsupported if older than 2 years #6148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1cb14d6
Check Core version and raise unsupported if older than 2 years
agners 417ef54
Handle landing page correctly
agners 3eaa6ef
Handle non-parseable versions gracefully
agners 07bc8ff
Extend and fix test coverage
agners d2a9a6f
Improve Job condition error
agners b99fa27
Fix pytest
agners 8ed8c69
Block execution of fetch_data and store reload jobs
agners c91868d
Use latest known Core version as reference
agners e5edc09
Improve version comparision logic
agners 1286921
Use Home Assistant Core instead of just Core
agners efa54bc
Sort const alphabetically
agners 286553a
Update tests/resolution/evaluation/test_evaluate_home_assistant_core_…
agners File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
supervisor/resolution/evaluations/home_assistant_core_version.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| """Evaluation class for Core version.""" | ||
|
|
||
| import logging | ||
|
|
||
| from awesomeversion import ( | ||
| AwesomeVersion, | ||
| AwesomeVersionException, | ||
| AwesomeVersionStrategy, | ||
| ) | ||
|
|
||
| from ...const import CoreState | ||
| from ...coresys import CoreSys | ||
| from ...homeassistant.const import LANDINGPAGE | ||
| from ..const import UnsupportedReason | ||
| from .base import EvaluateBase | ||
|
|
||
| _LOGGER: logging.Logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def setup(coresys: CoreSys) -> EvaluateBase: | ||
| """Initialize evaluation-setup function.""" | ||
| return EvaluateHomeAssistantCoreVersion(coresys) | ||
|
|
||
|
|
||
| class EvaluateHomeAssistantCoreVersion(EvaluateBase): | ||
| """Evaluate the Home Assistant Core version.""" | ||
|
|
||
| @property | ||
| def reason(self) -> UnsupportedReason: | ||
| """Return a UnsupportedReason enum.""" | ||
| return UnsupportedReason.HOME_ASSISTANT_CORE_VERSION | ||
|
|
||
| @property | ||
| def on_failure(self) -> str: | ||
| """Return a string that is printed when self.evaluate is True.""" | ||
| return f"Home Assistant Core version '{self.sys_homeassistant.version}' is more than 2 years old!" | ||
|
|
||
| @property | ||
| def states(self) -> list[CoreState]: | ||
| """Return a list of valid states when this evaluation can run.""" | ||
| return [CoreState.RUNNING, CoreState.SETUP] | ||
|
|
||
| async def evaluate(self) -> bool: | ||
| """Run evaluation.""" | ||
| if not (current := self.sys_homeassistant.version) or not ( | ||
| latest := self.sys_homeassistant.latest_version | ||
| ): | ||
| return False | ||
|
|
||
| # Skip evaluation for landingpage version | ||
| if current == LANDINGPAGE: | ||
| return False | ||
|
|
||
| try: | ||
| # We use the latest known version as reference instead of current date. | ||
| # This is crucial because when update information refresh is disabled due to | ||
| # unsupported Core version, using date would create a permanent unsupported state. | ||
| # Even if the user updates to the last known version, the system would remain | ||
| # unsupported in 4+ years. By using latest known version, updating Core to the | ||
| # last known version makes the system supported again, allowing update refresh. | ||
| # | ||
| # Home Assistant uses CalVer versioning (2024.1, 2024.2, etc.) with monthly releases. | ||
| # We consider versions more than 2 years behind as unsupported. | ||
| if ( | ||
| latest.strategy != AwesomeVersionStrategy.CALVER | ||
| or latest.year is None | ||
| or latest.minor is None | ||
| ): | ||
| return True # Invalid latest version format | ||
|
|
||
| # Calculate 24 months back from latest version | ||
| cutoff_month = int(latest.minor) | ||
| cutoff_year = int(latest.year) - 2 | ||
|
|
||
| # Create cutoff version | ||
| cutoff_version = AwesomeVersion( | ||
| f"{cutoff_year}.{cutoff_month}", | ||
| ensure_strategy=AwesomeVersionStrategy.CALVER, | ||
| ) | ||
|
|
||
| # Compare current version with the cutoff | ||
| return current < cutoff_version | ||
|
|
||
| except (AwesomeVersionException, ValueError, IndexError) as err: | ||
| # This is run regularly, avoid log spam by logging at debug level | ||
| _LOGGER.debug( | ||
| "Failed to parse Home Assistant version '%s' or latest version '%s': %s", | ||
| current, | ||
| latest, | ||
| err, | ||
| ) | ||
| # Consider non-parseable versions as unsupported | ||
| return True | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.