Show info from Clubassistant
All checks were successful
docker-image / docker (push) Successful in 9m52s

Since we now have so many animations, show them in a random order
This commit is contained in:
Stefan Bethke 2025-06-15 18:03:33 +02:00
commit 024345a17d
4 changed files with 76 additions and 3 deletions

View file

@ -5,6 +5,7 @@ from bottle_log import LoggingPlugin
from bottle_websocket import websocket, GeventWebSocketServer
from geventwebsocket.websocket import WebSocket
from buba.animations.clubassistant import Clubassistant
from buba.animations.dbf import DBFAnimation
from buba.animations.icalevents import IcalEvents
from buba.animations.snake import SnakeAnimation
@ -36,8 +37,10 @@ animator.add(DBFAnimation, ds100="AHS", station="Altona", count=9)
animator.add(IcalEvents, url="https://cloud.hamburg.ccc.de/remote.php/dav/public-calendars/QJAdExziSnNJEz5g?export",
title="CCCHH Events")
animator.add(Spaceapi, "https://spaceapi.hamburg.ccc.de", "CCCHH")
animator.add(Clubassistant, "https://club-assistant.ccchh.net", config.clubassistant_token)
animator.add(SnakeAnimation)
@app.route("/static/<filepath>")
def server_static(filepath):
return static_file(filepath, root=config.staticpath)

View file

@ -0,0 +1,62 @@
"""
Data from club-assistant.hamburg.ccc.de
"""
import json
from threading import Thread
from time import sleep
import requests
from buba.bubaanimator import BubaAnimation
default_endpoints = [
{
"endpoint": "sensor.total_measured_power",
"name": "Current Power",
},
{
"endpoint": "sensor.hauptraum_scd41_co2",
"name": "Hauptraum CO2",
},
{
"endpoint": "sensor.werkstatt_scd41_co2",
"name": "Werkstatt CO2",
},
{
"endpoint": "sensor.temperatur_und_feuchtigkeitssensor_hauptraum_humidity",
"name": "Hauptraum Luftfeuchte",
},
{
"endpoint": "sensor.temperatur_und_feuchtigkeitssensor_lotschlauch_humidity",
"name": "Lötschlauch Luftfeuchte",
}
]
class Clubassistant(BubaAnimation):
def __init__(self, buba, url, token, endpoints=None):
if endpoints is None:
endpoints = default_endpoints
super().__init__(buba)
self.url = url
self.token = token
self.endpoints = endpoints
self.data = []
self.load()
Thread(target=self.update, daemon=True).start()
def load(self):
data = []
for e in self.endpoints:
res = requests.get(self.url + "/api/states/" + e["endpoint"], headers={'Authorization': 'Bearer ' + self.token})
res.raise_for_status()
js = json.loads(res.text)
data.append([e["name"], f"{js['state']}{js['attributes']['unit_of_measurement']}"])
self.data = data
def update(self):
while True:
self.load()
sleep(60)
def run(self):
self.pages("Club Assistant", self.data)

View file

@ -16,6 +16,7 @@ class AppConfig:
self.url = getenv('BUBA_URL', 'http://localhost:3000')
(self.listen_host, self.listen_port) = getenv('BUBA_LISTEN', '127.0.0.1:3000').split(':')
self.serial = getenv('BUBA_SERIAL', '/dev/ttyUSB0')
self.clubassistant_token = getenv('BUBA_CLUBASSISTANT_TOKEN', None)
if self.debug is not None and self.debug.lower not in ('0', 'f', 'false'):
self.debug = True

View file

@ -1,4 +1,5 @@
import logging
import random
from dataclasses import dataclass
from datetime import datetime, timedelta
from itertools import islice
@ -139,12 +140,18 @@ class BubaAnimator:
Thread(target=self.run, daemon=True).start()
def run(self):
last = -1
while True:
if len(self.animations) == 0:
self.log.debug("No animations, sleeping...")
sleep(2)
else:
for a in self.animations:
while True:
next = random.randint(0, len(self.animations) - 1)
if next != last:
break
last = next
a = self.animations[next]
self.log.debug(f"Starting animation: {a}")
a.run()