Allow downgrade to "hassos" from "haos" (#2970)
* Add "os_name" as possible URL variable * Replace "os_name" for downgrades to OS versions before 6.0
This commit is contained in:
parent
5f376c2a27
commit
16f2f63081
|
@ -26,6 +26,7 @@ class HassOS(CoreSysAttributes):
|
|||
self._available: bool = False
|
||||
self._version: Optional[AwesomeVersion] = None
|
||||
self._board: Optional[str] = None
|
||||
self._os_name: Optional[str] = None
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
|
@ -55,18 +56,30 @@ class HassOS(CoreSysAttributes):
|
|||
"""Return board name."""
|
||||
return self._board
|
||||
|
||||
@property
|
||||
def os_name(self) -> Optional[str]:
|
||||
"""Return OS name."""
|
||||
return self._os_name
|
||||
|
||||
def _get_download_url(self, version: AwesomeVersion) -> str:
|
||||
raw_url = self.sys_updater.ota_url
|
||||
if raw_url is None:
|
||||
raise HassOSUpdateError("Don't have an URL for OTA updates!", _LOGGER.error)
|
||||
|
||||
update_board = self.board
|
||||
update_os_name = self.os_name
|
||||
|
||||
# OS version 6 and later renamed intel-nuc to generic-x86-64...
|
||||
if update_board == "intel-nuc" and version >= 6.0:
|
||||
update_board = "generic-x86-64"
|
||||
|
||||
url = raw_url.format(version=str(version), board=update_board)
|
||||
# The OS name used to be hassos before renaming to haos...
|
||||
if version < 6.0:
|
||||
update_os_name = "hassos"
|
||||
|
||||
url = raw_url.format(
|
||||
version=str(version), board=update_board, os_name=update_os_name
|
||||
)
|
||||
return url
|
||||
|
||||
async def _download_raucb(self, url: str, raucb: Path) -> None:
|
||||
|
@ -115,13 +128,13 @@ class HassOS(CoreSysAttributes):
|
|||
except NotImplementedError:
|
||||
_LOGGER.info("No Home Assistant Operating System found")
|
||||
return
|
||||
else:
|
||||
self._available = True
|
||||
self.sys_host.supported_features.cache_clear()
|
||||
|
||||
# Store meta data
|
||||
self._available = True
|
||||
self.sys_host.supported_features.cache_clear()
|
||||
self._version = AwesomeVersion(cpe.get_version()[0])
|
||||
self._board = cpe.get_target_hardware()[0]
|
||||
self._os_name = cpe.get_product()[0]
|
||||
|
||||
await self.sys_dbus.rauc.update()
|
||||
|
||||
|
|
|
@ -20,3 +20,39 @@ async def test_ota_url_generic_x86_64_rename(coresys: CoreSys) -> None:
|
|||
url = coresys.updater.ota_url.format(version=str(version6), board="generic-x86-64")
|
||||
|
||||
assert coresys.hassos._get_download_url(version6) == url
|
||||
|
||||
|
||||
def test_ota_url_os_name(coresys: CoreSys) -> None:
|
||||
"""Test download URL generated with os_name."""
|
||||
|
||||
board = "generic-x86-64"
|
||||
os_name = "haos"
|
||||
versionstr = "6.0"
|
||||
|
||||
url = "https://github.com/home-assistant/operating-system/releases/download/{version}/{os_name}_{board}-{version}.raucb"
|
||||
url_formatted = url.format(version=versionstr, board=board, os_name=os_name)
|
||||
|
||||
coresys.hassos._board = board
|
||||
coresys.hassos._os_name = os_name
|
||||
coresys.updater._data = {"ota": url}
|
||||
|
||||
url = coresys.hassos._get_download_url(AwesomeVersion(versionstr))
|
||||
assert url == url_formatted
|
||||
|
||||
|
||||
def test_ota_url_os_name_rel_5_downgrade(coresys: CoreSys) -> None:
|
||||
"""Test download URL generated with os_name."""
|
||||
|
||||
board = "generic-x86-64"
|
||||
versionstr = "5.9"
|
||||
|
||||
# On downgrade below 6.0 we need to use hassos as os_name.
|
||||
url = "https://github.com/home-assistant/operating-system/releases/download/{version}/{os_name}_{board}-{version}.raucb"
|
||||
url_formatted = url.format(version=versionstr, board=board, os_name="hassos")
|
||||
|
||||
coresys.hassos._board = board
|
||||
coresys.hassos._os_name = "haos"
|
||||
coresys.updater._data = {"ota": url}
|
||||
|
||||
url = coresys.hassos._get_download_url(AwesomeVersion(versionstr))
|
||||
assert url == url_formatted
|
||||
|
|
Loading…
Reference in New Issue