Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions image-builder/sovereign/appliance/bin/sovereign-conversation
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ class ConversationHandler(BaseHTTPRequestHandler):
"base_url": config["base_url"],
"has_access_token": homeassistant.has_access_token(HOME_ASSISTANT_TOKEN_PATH),
"allowlisted_entities": config["allowlisted_entities"],
"control_enabled": config["control_enabled"],
"controllable_entities": config["controllable_entities"],
}

def _handle_get_home_assistant(self):
Expand Down Expand Up @@ -318,6 +320,29 @@ class ConversationHandler(BaseHTTPRequestHandler):
},
})
return
# RFC-0019: a second, independent permission dimension -- required
# in every write, same as 'enabled'/'allowlisted_entities' above,
# not optional-with-a-default the way access_token is (that one
# is a credential-specific "leave unchanged" convenience, not the
# pattern for ordinary config fields in this endpoint).
if not isinstance(body.get("control_enabled"), bool):
self._send_json(400, {
"error": {"code": "INVALID_REQUEST", "message": "'control_enabled' must be a boolean"},
})
return
controllable_entities = body.get("controllable_entities")
if (
not isinstance(controllable_entities, list)
or len(controllable_entities) > MAX_ALLOWLISTED_ENTITIES
or not all(isinstance(entry, str) and entry for entry in controllable_entities)
):
self._send_json(400, {
"error": {
"code": "INVALID_REQUEST",
"message": f"'controllable_entities' must be a list of up to {MAX_ALLOWLISTED_ENTITIES} non-empty strings",
},
})
return
# None (the field omitted) means "leave the stored token
# unchanged" -- re-saving the allowlist must not require
# re-pasting the token every time (RFC-0018). An explicit empty
Expand All @@ -336,9 +361,18 @@ class ConversationHandler(BaseHTTPRequestHandler):
try:
homeassistant.write_config(
base_url, allowlisted_entities, body["enabled"],
control_enabled=body["control_enabled"], controllable_entities=controllable_entities,
access_token=access_token,
path=HOME_ASSISTANT_CONFIG_PATH, token_path=HOME_ASSISTANT_TOKEN_PATH,
)
except ValueError as error:
# RFC-0019: write_config() itself enforces controllable_entities
# is a subset of allowlisted_entities and light/switch-only --
# this is that invariant being violated, not a malformed
# request shape, so it's reported distinctly from the
# INVALID_REQUEST checks above even though it's still a 400.
self._send_json(400, {"error": {"code": "INVALID_CONTROL_CONFIGURATION", "message": str(error)}})
return
except OSError as error:
self._send_json(502, {
"error": {
Expand Down
18 changes: 18 additions & 0 deletions image-builder/sovereign/appliance/console/assets/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,16 @@ const HA_ENTITIES_PLACEHOLDER = "Sign in, save a connection, then load entities
// list (there is no partial-update endpoint).
let haAllowlist = [];

// RFC-0019: control_enabled/controllable_entities -- loaded and resent
// unchanged on every save the same way haAllowlist is, even though this
// pass builds no UI to edit them yet (that's Console's own follow-up
// per RFC-0019's Non-Goals). Without this, "Save connection" would
// silently wipe out control settings a household configured through
// some other path (a future settings page, or a direct API call),
// since POST /home-assistant always replaces the whole config object.
let haControlEnabled = false;
let haControllableEntities = [];

function setHaSettingsMessage(text, isError) {
haSettingsMessage.textContent = text;
haSettingsMessage.classList.toggle("error", Boolean(isError));
Expand Down Expand Up @@ -801,6 +811,8 @@ function resetHomeAssistantSettingsUI() {
haAccessTokenInput.value = "";
renderHaTokenStatus(false);
haAllowlist = [];
haControlEnabled = false;
haControllableEntities = [];
haEntitiesList.replaceChildren();
const placeholder = document.createElement("p");
placeholder.className = "placeholder";
Expand Down Expand Up @@ -834,6 +846,8 @@ async function loadHomeAssistantConfig() {
haAccessTokenInput.value = "";
renderHaTokenStatus(Boolean(data.has_access_token));
haAllowlist = Array.isArray(data.allowlisted_entities) ? data.allowlisted_entities.slice() : [];
haControlEnabled = Boolean(data.control_enabled);
haControllableEntities = Array.isArray(data.controllable_entities) ? data.controllable_entities.slice() : [];
renderHaStatus(data);
} catch (error) {
setHaSettingsMessage("Could not reach the device.", true);
Expand All @@ -845,6 +859,8 @@ async function saveHomeAssistantConfig(reportTo) {
enabled: haEnabledToggle.checked,
base_url: buildHaBaseUrl(),
allowlisted_entities: haAllowlist,
control_enabled: haControlEnabled,
controllable_entities: haControllableEntities,
};
// Omitted entirely (not even an empty string) means "leave the stored
// token unchanged" -- re-saving the allowlist must not require
Expand All @@ -868,6 +884,8 @@ async function saveHomeAssistantConfig(reportTo) {
haAccessTokenInput.value = "";
renderHaTokenStatus(Boolean(data.has_access_token));
haAllowlist = Array.isArray(data.allowlisted_entities) ? data.allowlisted_entities.slice() : [];
haControlEnabled = Boolean(data.control_enabled);
haControllableEntities = Array.isArray(data.controllable_entities) ? data.controllable_entities.slice() : [];
renderHaStatus(data);
reportTo("Saved.");
return;
Expand Down
Loading
Loading