Only update SpaceAPI, when state differs #12

Merged
lilly merged 1 commit from update_status_when_changed into main 2026-10-12 21:37:41 +02:00
Showing only changes of commit fde2254e51 - Show all commits

Only update SpaceAPI, when state differs
All checks were successful
Build Container / Build Container (push) Successful in 4m29s

bitwhisker 2026-10-12 21:26:28 +02:00
Signed by: bitwhisker
SSH key fingerprint: SHA256:KybIk/tusSKao6eLGY+ILlFa1rCrzwx66/acBAcKUqE

View file

@ -23,6 +23,23 @@ class SpaceApiClient:
)
async def set_status(self, is_open: bool):
current_is_open = await self.get_status()
if current_is_open == is_open:
logger.info(f"club status is already set to open={is_open}")
return
logger.info(f"Setting club status to open={is_open} via spaceapid")
await self.http.put("/state/open", data=str(is_open).encode("ASCII"))
async def get_status(self) -> bool | None:
logger.debug("Getting space data via spaceapid")
resp = await self.http.get("/")
data: dict = await resp.json()
if (state := data.get("state")) is not None:
is_open = state.get("open")
logger.info(f"Got club status open={is_open} via spaceapid")
return is_open
logger.warning("SpaceAPI response had no state object")
return None