Skip to content

Implement RFC-0019's allowlisted Home Assistant action capability - #19

Merged
kasunben merged 1 commit into
mainfrom
feat/home-assistant-actions
Aug 21, 2026
Merged

kasunben merged 1 commit into
mainfrom
feat/home-assistant-actions

Conversation

@kasunben

Copy link
Copy Markdown
Member

Summary

Implements the one mutating capability RFC-0019 (Accepted) maps: home_assistant.set_entity_state — this project's first capability with a real, physical effect, not just an information disclosure.

  • Capability implementation (sovereign_homeassistant.py) — reads current state before acting, so a proposal matching current state is a real, narrated no-op (changed: false) that never contacts Home Assistant's service-call endpoint. A real change is verified against the service call's own response (the changed-states list) before reporting success — never trusting a 200 status alone.
  • Three independent domain-scope enforcement points — this is the concrete fix for the gap RFC-0019's own review found and required before acceptance: write_config() rejects a non-light/switch domain at the source, a new _control_policy_check re-derives and re-confirms domain at the executor's stage-3 policy check, and the implementation itself checks a third time immediately before constructing the service-call URL. All three are independently tested, including an adversarial test that bypasses write_config() entirely (writing the config file directly) to prove the other two checks actually catch it — grounded in a real finding: Home Assistant's climate domain has real climate.turn_on/climate.turn_off services, so a bypassed check wouldn't fail safely by accident the way an invalid service name might.
  • A second, independent allowlist and policy toggle (controllable_entities/home_assistant_control_enabled), distinct from RFC-0018's own read allowlist/toggle — enabling reading never silently enables control. controllable_entities is enforced as a strict subset of allowlisted_entities at write time.
  • Extends the existing POST /api/v1/conversation/home-assistant endpoint rather than adding a new one — the two new fields are now required in every write, matching the existing full-replace semantics of enabled/base_url/allowlisted_entities.

A real regression this PR had to fix along the way

Extending the POST endpoint's required fields would have broken Console's already-shipped "Save connection" button — it currently sends only the three RFC-0018-era fields. Fixed by having console.js load, retain, and resend control_enabled/controllable_entities unchanged on every save, even though this PR builds no UI to edit them yet (that's Console's own follow-up, per RFC-0019's Non-Goals). Without this fix, every existing "Save connection" click would now 400.

Not included (explicit RFC-0019 follow-up, not this PR)

Console's settings UI for the control toggle and the controllable-entities picker. Real-hardware qualification also depends on the same unresolved external dependency RFC-0018 already disclosed — no Home Assistant instance exists on the household network yet.

Test plan

  • Full local test suite: 618 tests, all passing, no regressions.
  • New/updated tests across test_homeassistant_capabilities.py (config storage + domain validation, _control_policy_check, the implementation's no-op/success/not-confirmed paths, the adversarial domain-bypass test, full executor confirmation round trip), test_conversation.py (registry count, build_policy merging), test_conversation_service.py (extended /home-assistant endpoint validation including the new INVALID_CONTROL_CONFIGURATION rejection path, mutating-capability confirmation flow at the HTTP layer, cross-toggle independence).
  • Real-hardware qualification — not yet done; depends on a real Home Assistant instance being reachable on the household network (disclosed dependency, not a defect).
  • Console settings UI for control — explicit follow-up, not part of this PR.

🤖 Generated with Claude Code

home_assistant.set_entity_state (mutating/external/required) turns an
allowlisted light or switch entity on or off. Reads current state first
so a proposal matching it is a real, narrated no-op that never contacts
Home Assistant's service-call endpoint; a real change is verified
against the service call's own response before reporting success, never
trusting a 200 status alone.

Domain scope (light/switch only) is enforced at three independent
points, per RFC-0019's own review finding that a single point isn't
enough (Home Assistant's climate domain has real turn_on/turn_off
services, so a bypassed check wouldn't fail safely by accident):
write_config() rejects a bad domain at the source, a new
_control_policy_check re-derives and re-confirms it at the executor's
policy stage, and the implementation itself checks a third time
immediately before constructing the service-call URL.

Adds a second, independent allowlist and policy toggle
(controllable_entities/home_assistant_control_enabled), distinct from
RFC-0018's read allowlist/toggle, with controllable_entities enforced as
a strict subset of allowlisted_entities at write time. Extends the
existing POST /api/v1/conversation/home-assistant endpoint (now
requiring the two new fields in every write, matching the existing
full-replace fields) and fixes Console's existing save-connection flow
to round-trip them, since the endpoint's contract changed under it.
Console UI for editing control settings itself is not built here, per
RFC-0019's own Non-Goals.

Reuses RFC-0017's confirmation wire format completely unchanged for
this project's first mutating capability -- no new fields, no new
halting behavior.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@kasunben
kasunben marked this pull request as ready for review August 21, 2026 22:50
@kasunben
kasunben merged commit 05baf85 into main Aug 21, 2026
1 check passed
kasunben added a commit that referenced this pull request Aug 21, 2026
PR #19 shipped home_assistant.set_entity_state, the extended
home-assistant.json config surface, and the Console compatibility fix
for the endpoint's new required fields. Console's own settings UI for
the control toggle/picker remains the one real gap, alongside the
already-disclosed real-hardware qualification blocker.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant