Skip to content

fix(homeassistant): explain why an entity read failed - #58

Merged
pedropombeiro merged 1 commit into
mainfrom
fix/explain-entity-read-failures
Aug 19, 2026
Merged

pedropombeiro merged 1 commit into
mainfrom
fix/explain-entity-read-failures

Conversation

@pedropombeiro

Copy link
Copy Markdown
Owner

Problem

With the token now resolving, the work laptop reaches Home Assistant but reports:

cannot read entity 'input_text.opencode_permission_response' from Home Assistant

That one message covers four unrelated causes — rejected token, missing helper, server error, unreachable host — so it names the symptom without narrowing the cause. Same shortcoming as the earlier "config unavailable".

Changes

fetchHaEntity returns the reason instead of collapsing everything to undefined:

Cause Message
401 / 403 HTTP 401, the long-lived token was rejected by Home Assistant
404 HTTP 404, entity input_text.… does not exist (create the input_text helper in Home Assistant)
other status HTTP 500
transport request to https://ha…/api failed (Unable to connect…)

setHaEntity now reports failures too. A failed clear was previously silent, leaving a stale value that the next request could mistake for a reply.

Verification

Real opencode process against a mock HA returning 401:

que_018de169c001S20EekvZxx3vov: poll started, entity=input_text.opencode_permission_response, timeout=60000ms
que_018de169c001S20EekvZxx3vov: cannot read entity input_text.opencode_permission_response from Home Assistant: HTTP 401, the long-lived token was rejected by Home Assistant
que_018de169c001S20EekvZxx3vov: timed out after 60000ms (30 polls, 0 responses for other requests, 30 failed reads)

All five read failures produce distinct messages (unit harness), and the healthy path still ends in reply accepted (HTTP 200). Existing receiver, negative-path, config and lifecycle suites still pass.

mise run typecheck, lint, build all pass.

Likely cause on the work laptop

The token resolves but Home Assistant rejects or cannot find the entity. Once this ships, the log will say which. The two candidates are a long-lived token that is expired or from a different HA instance, or a missing input_text.opencode_permission_response helper.

"cannot read entity" covered a rejected token, a missing helper, a server
error and an unreachable host, so it named the symptom without narrowing
the cause.

The read now reports which one occurred: 401 and 403 point at the
long-lived token, 404 says the entity does not exist and suggests
creating the input_text helper, other statuses are reported verbatim, and
transport errors include the URL and the underlying message.

Failures when clearing the entity are reported too. Previously a failed
clear was silent, which would leave a stale value that looks like a reply
to the next request.
@pedropombeiro
pedropombeiro merged commit f0d19eb into main Aug 19, 2026
2 checks passed
@pedropombeiro
pedropombeiro deleted the fix/explain-entity-read-failures branch August 19, 2026 07:19
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