Skip to content

Fix space status widget - #5

Open
Thebys wants to merge 1 commit into
mainfrom
fix-space-status
Open

Fix space status widget#5
Thebys wants to merge 1 commit into
mainfrom
fix-space-status

Conversation

@Thebys

@Thebys Thebys commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

The widget reported the space as open no matter what. SpaceAPI 0.13 returns
state as an object, not a boolean, so data.state was always truthy.

Three changes to js/main.js:

  • data.state.open instead of data.state — the actual bug
  • fetch /api/spaceapi same-origin through the nginx proxy
  • drop the Cache-Control / Pragma request headers: they make the request
    non-simple, and HA answers the resulting CORS preflight with 403 CORS preflight request failed: headers are not allowed: PRAGMA, CACHE-CONTROL.
    The ?t= cache buster already covers cache busting.

Verified against the live endpoint: before this, data.state evaluated to
true for both an open and a closed space.

Overlaps with #4

The same-origin switch here is the same change as #4. Merge #4 first and I'll
rebase, or close #4 in favour of this — either way works, just not both.

Follow-up, server side (not in this PR)

The nginx location from base48/servers-config@c340230 sets
Access-Control-Allow-Origin and Content-Type on top of what HA already
sends, so the response currently carries each of those headers twice
(add_header appends, it does not replace). Neither breaks the widget now
that it is same-origin, but both are worth removing.

Also worth considering: the widget polls every 20s per open tab and the
location sets no-store with proxy_buffering off, so every poll from every
visitor reaches HA. A short proxy_cache window would cut that a lot.

🤖 Generated with Claude Code

SpaceAPI 0.13 returns state as an object ({"open": bool, "lastchange": ts}),
not a boolean, so `data.state` was always truthy and the widget reported the
space as open regardless of its real state. Read `data.state.open`.

Fetch /api/spaceapi same-origin through the nginx proxy, and drop the
hand-written Cache-Control/Pragma request headers: they make the request
non-simple, and HA answers the resulting CORS preflight with 403 because its
allowed-header list is hardcoded. The ?t= cache buster already does the job.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@marmolak

marmolak commented Sep 1, 2026

Copy link
Copy Markdown
Member

Thank you mighty robot.

Looks like spaceapi on ha uses older version than on jessica.
https://base48.cz/api/base_status_spaceapi.json
"api_compatibility":["14","15"]

VS

https://ha.base48.cz/api/spaceapi
{"api":"0.13",
and some info about social networks missing.

Also, only:
https://base48.cz/api/base_status_spaceapi.json
is propagated to heatmap.

@marmolak

marmolak commented Sep 1, 2026

Copy link
Copy Markdown
Member

Older version of code (before a3c9184) doesn't use space api but it parses:
https://base48.cz/api/base_status.json
which is different format (it's directly from HA).

But main question is:
which version of spaceapi do you want to use?

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.

2 participants