Skip to content

feat(homeassistant): split tool vs platform env vars#29199

Open
StartupBros wants to merge 1 commit into
NousResearch:mainfrom
StartupBros:feat/ha-tool-platform-env-split
Open

feat(homeassistant): split tool vs platform env vars#29199
StartupBros wants to merge 1 commit into
NousResearch:mainfrom
StartupBros:feat/ha-tool-platform-env-split

Conversation

@StartupBros

@StartupBros StartupBros commented May 20, 2026

Copy link
Copy Markdown

Split out from the original combined PR per CONTRIBUTING.md ("one logical change per PR"). The websocket connection-lifecycle fixes that were bundled here previously will land as a separate PR.

Problem

Today HASS_TOKEN / HASS_URL configure BOTH:

  • the HA tool surface (skill calls into HA REST API via tools/homeassistant_tool.py)
  • the gateway websocket platform (persistent notifications back to HA via gateway/platforms/homeassistant.py)

Fine for the default single-target setup, but blocks operators who want:

  • a tool-only setup (websocket intentionally disabled)
  • the tool surface and the notification surface pointing at different HA instances (local proxy for tools, remote endpoint for notifications, or vice versa)

Solution — backward-compatible env split

Var Effect
HASS_TOKEN / HASS_URL Still works, still configures both surfaces — existing deployments unchanged
HASS_TOOL_TOKEN / HASS_TOOL_URL Overrides the tool surface only
HASS_PLATFORM_TOKEN / HASS_PLATFORM_URL Overrides the websocket platform only
HASS_PLATFORM_DISABLE=1 Suppresses websocket startup entirely (tool-only)

Surface coverage (every HA env-var touchpoint)

The original split-only PR only updated the adapter + tool readers and missed every consumer that maps the env to something downstream. This revision covers them all:

  • gateway/config.py — env-override reader prefers HASS_PLATFORM_* with HASS_* fallback; HASS_PLATFORM_DISABLE honored
  • gateway/platforms/homeassistant.py — adapter reads PLATFORM tokens first
  • gateway/run.py — startup warning string lists all three accepted token vars
  • tools/homeassistant_tool.py — REST tool prefers HASS_TOOL_*
  • tools/send_message_tool.py_send_homeassistant notify path prefers HASS_TOOL_*
  • hermes_cli/dump.py — diagnostics report HA as "present" if any of the three token vars is set
  • hermes_cli/setup.py — setup-status summary treats any of the three as present
  • hermes_cli/tools_config.py — wizard keeps single-target HASS_TOKEN/HASS_URL prompts (advanced operators set the new vars in ~/.hermes/.env directly; documented in the wizard schema)
  • tools/environments/local.py — sandboxed-tool env propagation list includes all 5 new var names so they reach child processes
  • tests/conftest.py — test env scrub includes the new token vars so cross-test leakage stays prevented

Test plan

All 139 HA-related tests pass:

  • tests/gateway/test_homeassistant.py — new tests: test_returns_true_with_platform_token, test_platform_disable_skips_ha_platform, test_platform_specific_env_overrides_shared_values; existing test_no_env_no_platform updated to scrub the new vars too
  • tests/tools/test_homeassistant_tool.py — new TestGetConfig class covers tool-specific precedence and legacy fallback; test_available_with_tool_specific_token added
  • tests/tools/test_send_message_missing_platforms.py — new test_tool_env_var_fallback covers the notify path

Manual:

  • HASS_TOKEN=... HASS_PLATFORM_DISABLE=1 → tool available, websocket platform not started
  • HASS_TOOL_TOKEN=A HASS_PLATFORM_TOKEN=B → tool uses A, websocket uses B
  • Only HASS_TOKEN set → behavior unchanged (backward compat)

@alt-glitch alt-glitch added type/feature New feature or request comp/gateway Gateway runner, session dispatch, delivery area/config Config system, migrations, profiles P3 Low — cosmetic, nice to have labels May 20, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Competes with #21676 (open, same HA tool/platform env-var split). Also addresses #25065 (HASS_TOKEN force-enables platform). This PR bundles the env-var split with websocket lifecycle fixes — #21676 is the narrower predecessor.

Today HASS_TOKEN / HASS_URL configure BOTH:
- the HA tool surface (skill calls into HA REST API)
- the gateway's websocket platform (persistent notifications back to HA)

Fine for the default single-target setup, but blocks operators who want:
- a tool-only setup (websocket intentionally disabled)
- the tool surface and the notification surface pointing at different HA
  instances (local proxy for tools, remote endpoint for notifications, or
  vice versa)

Backward-compatible defaults:

- HASS_TOKEN / HASS_URL still work and still configure both surfaces —
  existing deployments unchanged
- HASS_TOOL_TOKEN / HASS_TOOL_URL override the tool surface only
- HASS_PLATFORM_TOKEN / HASS_PLATFORM_URL override the websocket only
- HASS_PLATFORM_DISABLE=1 suppresses websocket startup entirely

Surface coverage:

- gateway/config.py — env override reads PLATFORM_* with TOKEN/URL fallback
- gateway/platforms/homeassistant.py — adapter prefers PLATFORM_*
- tools/homeassistant_tool.py — tool prefers TOOL_*
- tools/send_message_tool.py — notify path prefers TOOL_*
- hermes_cli/dump.py — diagnostics treat any of the 3 token vars as present
- hermes_cli/setup.py — setup summary treats any of the 3 token vars as present
- tools/environments/local.py — sandboxed tool env propagation includes new vars
- tests/conftest.py — test env scrub includes new token vars
- hermes_cli/tools_config.py — wizard prompt keeps the single-target default
  but documents the split for advanced operators

Tests: 139 HA tests pass; new coverage in test_homeassistant.py
(env-split + HASS_PLATFORM_DISABLE), test_homeassistant_tool.py
(TestGetConfig), test_send_message_missing_platforms.py
(test_tool_env_var_fallback).
@StartupBros StartupBros force-pushed the feat/ha-tool-platform-env-split branch from 2372c58 to d7f266e Compare May 20, 2026 16:49
@StartupBros StartupBros changed the title feat(homeassistant): split tool vs platform env vars + connection-lifecycle fixes feat(homeassistant): split tool vs platform env vars May 20, 2026
@StartupBros

Copy link
Copy Markdown
Author

Status re: @alt-glitch's note above: #21676 closed in favor of this. This PR covers 6 touchpoints #21676 missed: hermes_cli/dump.py, hermes_cli/setup.py, hermes_cli/tools_config.py, tools/environments/local.py, tests/conftest.py, and the warning copy in gateway/run.py. The websocket lifecycle change that #21676 bundled with the env split is now its own PR (#29388) per CONTRIBUTING.md's one-logical-change rule.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config Config system, migrations, profiles comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants