The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(homeassistant): detect the supervised launch through is_supervised_gateway_launch
kshitijk4poor7b660e66ee3d
diff --git a/plugins/platforms/homeassistant/adapter.py b/plugins/platforms/homeassistant/adapter.pyindex 002e4adf872..97799251330 100644--- a/plugins/platforms/homeassistant/adapter.py+++ b/plugins/platforms/homeassistant/adapter.py@@ -7,7 +7,6 @@ import asyncioimport errnoimport jsonimport logging-import osimport sysimport timeimport uuid@@ -21,6 +20,7 @@ except ImportError:AIOHTTP_AVAILABLE = Falseaiohttp = None # type: ignore[assignment]+from gateway.restart import is_supervised_gateway_launchfrom gateway.config import Platform, PlatformConfigfrom gateway.platforms.base import gateway_trust_env, BasePlatformAdapter, SendResultfrom gateway.platforms.event import MessageEvent, MessageType@@ -70,12 +70,12 @@ _TRIGGERED = ("cleared", "triggered") # binary_sensor wording, indexed by ``stadef _connect_error_detail(exc: BaseException) -> str:"""Annotate macOS Local Network Privacy denials so launchd HA failures are actionable (#71206).- Only a launchd-supervised gateway on macOS (``HERMES_SUPERVISED_CHILD`` is set by the generated plist)- can be denied this way; the same errno elsewhere is a genuinely unreachable host.+ Only a supervised (launchd) gateway on macOS can be denied this way; the same errno from a+ Terminal-run gateway or on another OS is a genuinely unreachable host."""text = str(exc)os_error = getattr(exc, "os_error", None) or exc.__cause__ or exc- if (sys.platform == "darwin" and os.environ.get("HERMES_SUPERVISED_CHILD")+ if (sys.platform == "darwin" and is_supervised_gateway_launch()and getattr(os_error, "errno", None) == errno.EHOSTUNREACH):return (f"{text} — macOS Local Network Privacy is blocking this launchd gateway from the LAN. "diff --git a/tests/gateway/test_homeassistant.py b/tests/gateway/test_homeassistant.pyindex f1c1ce27d26..a013b21f34f 100644--- a/tests/gateway/test_homeassistant.py+++ b/tests/gateway/test_homeassistant.py@@ -321,22 +321,25 @@ class TestWsUrlConstruction:class TestLocalNetworkConnectHint:- @pytest.mark.macos_only- def test_ehostunreach_under_launchd_names_the_remedy(self, monkeypatch):- """Only the launchd-supervised gateway can be denied by Local Network Privacy; the same errno from a- Terminal-run gateway is a genuinely unreachable host and must not be blamed on macOS (#71206)."""+ def test_ehostunreach_outside_launchd_is_a_plain_unreachable_host(self, monkeypatch):+ """The same errno from a Terminal-run gateway (or another OS) must not be blamed on macOS."""from plugins.platforms.homeassistant.adapter import _connect_error_detail- err = OSError(errno.EHOSTUNREACH, "No route to host")monkeypatch.delenv("HERMES_SUPERVISED_CHILD", raising=False)+ monkeypatch.delenv("XPC_SERVICE_NAME", raising=False)+ err = OSError(errno.EHOSTUNREACH, "No route to host")assert _connect_error_detail(err) == str(err)+ assert _connect_error_detail(RuntimeError("auth failed")) == "auth failed"++ @pytest.mark.macos_only+ def test_ehostunreach_under_launchd_names_the_remedy(self, monkeypatch):+ """Only the launchd-supervised gateway can be denied by Local Network Privacy (#71206)."""+ from plugins.platforms.homeassistant.adapter import _connect_error_detailmonkeypatch.setenv("HERMES_SUPERVISED_CHILD", "1")+ err = OSError(errno.EHOSTUNREACH, "No route to host")detail = _connect_error_detail(err)assert detail.startswith(str(err))assert "Local Network" in detailassert "hermes gateway install" in detailassert "71206" in detail- # Unrelated failures stay untouched.- assert _connect_error_detail(RuntimeError("auth failed")) == "auth failed"-