Skip to content

Fix space status widget - #5

Merged
Thebys merged 2 commits into
mainfrom
fix-space-status
Sep 12, 2026
Merged

Fix space status widget#5
Thebys merged 2 commits 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?

@marmolak

marmolak commented Sep 7, 2026

Copy link
Copy Markdown
Member

This solves only the web part so it's LGTM.

Other parts can be solved in different MR's.

/api/spaceapi proxies to Home Assistant, which serves SpaceAPI 0.13 and
fails validation against the current 15.json on api_compatibility. That
field is a hardcoded constant in the integration (SPACEAPI_VERSION), so
no amount of YAML reaches it.

/api/base_status_spaceapi.json is regenerated every minute from the same
Home Assistant sensor, validates clean against 15.json, and is already
what the external directories read — mapall.space, HackerspacesGlobe,
MapsOfMaking and MakersMap, ~2800 requests a day against 3 for the proxy.
Both carry state.open, so this is a URL change and nothing else.

It also drops the request-time dependency on Home Assistant: the file
keeps serving the last known state if HA or the tunnel is down, where
the proxy would fail the request. HA's own endpoint reports the space as
open whenever the sensor is unavailable, which is the wrong direction for
a door status.
@Thebys
Thebys merged commit 726d9c2 into main Sep 12, 2026
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