Skip to content

The agent that grows with you

fix(plugins): don't count the shipped homeassistant platform_toolsets row as Home Assistant use

skyeyesec333fa7c129ef5ee
diff --git a/hermes_cli/left_core_migration.py b/hermes_cli/left_core_migration.py
index 4dc83a89cc0..5c7441e646c 100644
--- a/hermes_cli/left_core_migration.py
+++ b/hermes_cli/left_core_migration.py
@@ -68,10 +68,15 @@ def platform_configured_on(home: Path, name: str) -> bool:
return platform.enabled or ("enabled" not in block and bool(str(platform.token or "").strip()))
-def _toolset_listed(config: dict, names: frozenset[str]) -> bool:
- """A toolset in *names* is selected in ``platform_toolsets`` or the top-level ``toolsets`` list."""
- selections = list((config.get("platform_toolsets") or {}).values()) if isinstance(
- config.get("platform_toolsets"), dict) else []
+def _toolset_listed(config: dict, names: frozenset[str], *, own_platform: str = "") -> bool:
+ """A toolset in *names* is selected in ``platform_toolsets`` or the top-level ``toolsets`` list.
+
+ *own_platform*'s row is skipped: it scopes that platform's own sessions, which only exist once the
+ platform is on (:func:`platform_configured_on`). The installers copy cli-config.yaml.example into
+ config.yaml, and it carried ``homeassistant: [hermes-homeassistant]`` until Home Assistant left core,
+ so that row alone is not use."""
+ rows = config.get("platform_toolsets")
+ selections = [sel for platform, sel in rows.items() if platform != own_platform] if isinstance(rows, dict) else []
selections.append(config.get("toolsets"))
return any(isinstance(sel, list) and any(str(item) in names for item in sel) for sel in selections)
@@ -79,9 +84,9 @@ def _toolset_listed(config: dict, names: frozenset[str]) -> bool:
def homeassistant_in_use(home: Path, *, process_env: bool = False) -> bool:
"""What made core run Home Assistant for *home*: ``HASS_TOKEN`` in its ``.env`` (it enabled both
the gateway platform and the tools), the platform on in its gateway config
- (:func:`platform_configured_on`), or the ``homeassistant`` / ``hermes-homeassistant`` toolset selected for a
- platform. *process_env* (the active home at startup only) also counts a ``HASS_TOKEN`` the
- process received from its environment (systemd unit, Docker, shell export)."""
+ (:func:`platform_configured_on`), or the ``homeassistant`` / ``hermes-homeassistant`` toolset selected for
+ another platform or in the top-level ``toolsets`` list. *process_env* (the active home at startup only)
+ also counts a ``HASS_TOKEN`` the process received from its environment (systemd unit, Docker, shell export)."""
from agent.secret_scope import load_env_file
if (load_env_file(home / ".env").get("HASS_TOKEN") or "").strip():
return True
@@ -94,7 +99,8 @@ def homeassistant_in_use(home: Path, *, process_env: bool = False) -> bool:
pass
if platform_configured_on(home, "homeassistant"):
return True
- return _toolset_listed(_read_config(home), frozenset({"homeassistant", "hermes-homeassistant"}))
+ return _toolset_listed(
+ _read_config(home), frozenset({"homeassistant", "hermes-homeassistant"}), own_platform="homeassistant")
def spotify_in_use(home: Path, *, process_env: bool = False) -> bool:
diff --git a/tests/hermes_cli/test_left_core_migration.py b/tests/hermes_cli/test_left_core_migration.py
index 1682f55ecff..4924e9cddb9 100644
--- a/tests/hermes_cli/test_left_core_migration.py
+++ b/tests/hermes_cli/test_left_core_migration.py
@@ -33,13 +33,35 @@ def _home(tmp_path: Path, name: str = "home", *, env: str = "", config: str = ""
return home
+# The uncommented platform_toolsets block cli-config.yaml.example carried (the homeassistant row from
+# 1aa7badb3c until fb9fc8a3dd). The installers (install.sh, install.ps1, the Docker hook) and
+# `hermes doctor` seed config.yaml from that file, so the block alone says nothing about use.
+_EXAMPLE_PLATFORM_TOOLSETS = (
+ "platform_toolsets:\n"
+ " cli: [hermes-cli]\n"
+ " telegram: [hermes-telegram]\n"
+ " discord: [hermes-discord]\n"
+ " whatsapp: [hermes-whatsapp]\n"
+ " slack: [hermes-slack]\n"
+ " signal: [hermes-signal]\n"
+ " homeassistant: [hermes-homeassistant]\n"
+ " qqbot: [hermes-qqbot]\n"
+ " yuanbao: [hermes-yuanbao]\n"
+ " teams: [hermes-teams]\n"
+ " google_chat: [hermes-google_chat]\n"
+)
+
+
@pytest.mark.parametrize(("env", "config"), [
("HASS_TOKEN=abc\n", ""),
("", "platforms:\n homeassistant:\n enabled: true\n"),
("", "gateway:\n platforms:\n homeassistant:\n enabled: true\n"),
("", "platforms:\n homeassistant:\n token: inline-token\n"),
("", "platform_toolsets:\n cli: [hermes-cli, homeassistant]\n"),
- ("", "platform_toolsets:\n homeassistant: [hermes-homeassistant]\n"),
+ ("", "toolsets: [hermes-cli, homeassistant]\n"),
+ # The Home Assistant row counts once the platform itself is on.
+ ("", "platforms:\n homeassistant:\n enabled: true\n"
+ "platform_toolsets:\n homeassistant: [hermes-homeassistant]\n"),
])
def test_homeassistant_in_use_matches_what_core_activated(tmp_path, env, config):
assert lcm.homeassistant_in_use(_home(tmp_path, env=env, config=config)) is True
@@ -51,6 +73,9 @@ def test_homeassistant_in_use_matches_what_core_activated(tmp_path, env, config)
("", "platforms:\n homeassistant:\n enabled: false\n token: t\n"),
("", "platform_toolsets:\n cli: [hermes-cli]\n"),
("OPENAI_API_KEY=sk\n", "platforms:\n telegram:\n enabled: true\n"),
+ # The platform's own row only scoped Home Assistant's own sessions, which need the platform on.
+ ("", "platform_toolsets:\n homeassistant: [hermes-homeassistant]\n"),
+ ("", _EXAMPLE_PLATFORM_TOOLSETS),
])
def test_homeassistant_not_in_use(tmp_path, env, config):
assert lcm.homeassistant_in_use(_home(tmp_path, env=env, config=config)) is False