Delay deprecation checks until Home Assistant is fully initialized

This aims to delay the async_get_system_info() call until the hassio
integration is fully initialized, to make sure the installation method
is determined correctly.
This commit is contained in:
Stefan Agner
2025-06-24 00:01:30 +02:00
parent 2f736a5bf3
commit 1415d6cf0b

View File

@ -17,6 +17,7 @@ from homeassistant.const import (
ATTR_ENTITY_ID, ATTR_ENTITY_ID,
ATTR_LATITUDE, ATTR_LATITUDE,
ATTR_LONGITUDE, ATTR_LONGITUDE,
EVENT_HOMEASSISTANT_STARTED,
RESTART_EXIT_CODE, RESTART_EXIT_CODE,
SERVICE_RELOAD, SERVICE_RELOAD,
SERVICE_SAVE_PERSISTENT_STATES, SERVICE_SAVE_PERSISTENT_STATES,
@ -25,6 +26,7 @@ from homeassistant.const import (
SERVICE_TURN_ON, SERVICE_TURN_ON,
) )
from homeassistant.core import ( from homeassistant.core import (
Event,
HomeAssistant, HomeAssistant,
ServiceCall, ServiceCall,
ServiceResponse, ServiceResponse,
@ -404,45 +406,50 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa:
hass.data[DATA_EXPOSED_ENTITIES] = exposed_entities hass.data[DATA_EXPOSED_ENTITIES] = exposed_entities
async_set_stop_handler(hass, _async_stop) async_set_stop_handler(hass, _async_stop)
info = await async_get_system_info(hass) async def _async_check_deprecation(event: Event) -> None:
"""Check and create deprecation issues after startup."""
info = await async_get_system_info(hass)
installation_type = info["installation_type"][15:] installation_type = info["installation_type"][15:]
if installation_type in {"Core", "Container"}: if installation_type in {"Core", "Container"}:
deprecated_method = installation_type == "Core" deprecated_method = installation_type == "Core"
bit32 = _is_32_bit() bit32 = _is_32_bit()
arch = info["arch"] arch = info["arch"]
if bit32 and installation_type == "Container": if bit32 and installation_type == "Container":
arch = info.get("container_arch", arch) arch = info.get("container_arch", arch)
ir.async_create_issue( ir.async_create_issue(
hass, hass,
DOMAIN, DOMAIN,
"deprecated_container", "deprecated_container",
learn_more_url=DEPRECATION_URL, learn_more_url=DEPRECATION_URL,
is_fixable=False, is_fixable=False,
severity=IssueSeverity.WARNING, severity=IssueSeverity.WARNING,
translation_key="deprecated_container", translation_key="deprecated_container",
translation_placeholders={"arch": arch}, translation_placeholders={"arch": arch},
) )
deprecated_architecture = bit32 and installation_type != "Container" deprecated_architecture = bit32 and installation_type != "Container"
if deprecated_method or deprecated_architecture: if deprecated_method or deprecated_architecture:
issue_id = "deprecated" issue_id = "deprecated"
if deprecated_method: if deprecated_method:
issue_id += "_method" issue_id += "_method"
if deprecated_architecture: if deprecated_architecture:
issue_id += "_architecture" issue_id += "_architecture"
ir.async_create_issue( ir.async_create_issue(
hass, hass,
DOMAIN, DOMAIN,
issue_id, issue_id,
learn_more_url=DEPRECATION_URL, learn_more_url=DEPRECATION_URL,
is_fixable=False, is_fixable=False,
severity=IssueSeverity.WARNING, severity=IssueSeverity.WARNING,
translation_key=issue_id, translation_key=issue_id,
translation_placeholders={ translation_placeholders={
"installation_type": installation_type, "installation_type": installation_type,
"arch": arch, "arch": arch,
}, },
) )
# Delay deprecation check to make sure installation method is determined correctly
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STARTED, _async_check_deprecation)
return True return True