watt42_viewlib/geyser_on_off.py

24 lines
650 B
Python
Raw Normal View History

import os
import panel
from typing import Any
from watt42_viewlib import attach_w42_state
SYSTEM_ID = os.environ.get("WATT42_SYSTEM_ID", "invalid-system-id")
API_TOKEN = os.environ.get("WATT42_API_TOKEN", "invalid-api-token")
w42_state = panel.rx(None)
attach_w42_state(rx_var=w42_state, system_id=SYSTEM_ID, token=API_TOKEN)
def get_geyser_state(state: dict[str, Any]) -> bool:
if not state:
return False
return state.get("is_geyser_on", False)
geyser_state = panel.rx(get_geyser_state)(w42_state)
indicator = panel.indicators.BooleanStatus(value=geyser_state, name="W42 Connected", color="success")
_ = indicator.servable()