developers.home-assistant/blog/2024-09-28-update-version-compare.md
Simone Chemelli 74654c71cb
Add new method version_is_newer to Update platform (#2307)
* add new method

* apply review comments

* section title

* Update docs/core/entity/update.md

Co-authored-by: G Johansson <goran.johansson@shiftit.se>

* apply review comments

* add blog post

* missing string

* Update blog/2024-09-19-update-version-compare.md

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update blog/2024-09-19-update-version-compare.md

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update blog/2024-09-19-update-version-compare.md

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* apply review comments

* Apply suggestions from code review

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* update filename date

---------

Co-authored-by: G Johansson <goran.johansson@shiftit.se>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2024-09-28 20:56:46 +02:00

1.3 KiB

author authorURL title
Simone Chemelli https://github.com/chemelli74 Version compare for Update platform can now be overwritten

With the merge of core PR #124797, which will land in Home Assistant Core 2024.10, there is a new method in the update platform: version_is_newer().

Before this change, the compare logic between firmware installed version, new available version and beta version was hardcoded:

def version_is_newer(self, latest_version: str, installed_version: str) -> bool:
    """Return True if latest_version is newer than installed_version."""
    return AwesomeVersion(latest_version) > installed_version

Now the new method allows developers to customize this comparison, writing their own method. Here's an example (implemented for Shelly gen1 devices):

def version_is_newer(self, latest_version: str, installed_version: str) -> bool:
    """Return True if available version is newer then installed version."""
    return AwesomeVersion(
        latest_version,
        find_first_match=True,
        ensure_strategy=[AwesomeVersionStrategy.SEMVER],
    ) > AwesomeVersion(
        installed_version,
        find_first_match=True,
        ensure_strategy=[AwesomeVersionStrategy.SEMVER],
    )