Only update SpaceAPI, when state differs
All checks were successful
Build Container / Build Container (push) Successful in 4m29s
All checks were successful
Build Container / Build Container (push) Successful in 4m29s
This commit is contained in:
parent
81c960db6c
commit
fde2254e51
1 changed files with 18 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue