diff --git a/supervisor/docker/homeassistant.py b/supervisor/docker/homeassistant.py index 999877af1..c71f6d1d4 100644 --- a/supervisor/docker/homeassistant.py +++ b/supervisor/docker/homeassistant.py @@ -184,7 +184,7 @@ class DockerHomeAssistant(DockerInterface): } if restore_job_id: environment[ENV_RESTORE_JOB_ID] = restore_job_id - if self.sys_homeassistant.api.use_unix_socket: + if self.sys_homeassistant.api.supports_unix_socket: environment[ENV_CORE_API_SOCKET] = "/run/supervisor/core.sock" if self.sys_homeassistant.duplicate_log_file: environment[ENV_DUPLICATE_LOG_FILE] = "1" diff --git a/supervisor/homeassistant/api.py b/supervisor/homeassistant/api.py index 49b1ee8aa..e1ccb3231 100644 --- a/supervisor/homeassistant/api.py +++ b/supervisor/homeassistant/api.py @@ -15,6 +15,7 @@ from multidict import MultiMapping from ..const import SOCKET_CORE from ..coresys import CoreSys, CoreSysAttributes +from ..docker.const import ENV_CORE_API_SOCKET from ..exceptions import HomeAssistantAPIError, HomeAssistantAuthError from ..utils import version_is_new_enough from .const import LANDINGPAGE @@ -51,8 +52,11 @@ class HomeAssistantAPI(CoreSysAttributes): self._logged_transport: bool = False @property - def use_unix_socket(self) -> bool: - """Return True if Core supports Unix socket communication.""" + def supports_unix_socket(self) -> bool: + """Return True if the installed Core version supports Unix socket communication. + + Used to decide whether to configure the env var when starting Core. + """ return ( self.sys_homeassistant.version is not None and self.sys_homeassistant.version != LANDINGPAGE @@ -61,6 +65,24 @@ class HomeAssistantAPI(CoreSysAttributes): ) ) + @property + def use_unix_socket(self) -> bool: + """Return True if the running Core container is configured for Unix socket. + + Checks both version support and that the container was actually started + with the SUPERVISOR_CORE_API_SOCKET env var. This prevents failures + during Supervisor upgrades where Core is still running with a container + started by the old Supervisor. + """ + if not self.supports_unix_socket: + return False + meta_config = self.sys_homeassistant.core.instance.meta_config + if not meta_config or "Env" not in meta_config: + return False + return any( + env.startswith(f"{ENV_CORE_API_SOCKET}=") for env in meta_config["Env"] + ) + @property def session(self) -> aiohttp.ClientSession: """Return session for Core communication.