Compare commits

..

3 commits

Author SHA1 Message Date
bdbd84ab97 add instructions on how to run 2026-01-14 14:31:52 +02:00
99763d9881 now with dependency to viewlib, and sample main.py 2026-01-14 14:27:03 +02:00
e9e33def3f initial 2026-01-14 14:00:41 +02:00
5 changed files with 3805 additions and 1 deletions

View file

@ -2,4 +2,28 @@
## Introduction ## Introduction
Use this template together with [Watt42's viewlib](https://source.c3.uber5.com/watt42-public/watt42_viewlib). Use this template together with [Watt42's viewlib](https://source.c3.uber5.com/watt42-public/watt42_viewlib).
## How to Run
1. Make sure you've got [poetry](https://python-poetry.org/) installed. You can
install it by running the below (on MacOS/Linux), or [check installation
instructions](https://python-poetry.org/docs/#installing-with-the-official-installer):
```bash
curl -sSL https://install.python-poetry.org | python3 -
```
2. Install dependencies using Poetry:
```bash
poetry install
```
3. Run the View app locally (replace `YOUR_ID` and `YOUR_TOKEN` with your actual
Watt42 System ID and API Token):
```bash
WATT42_SYSTEM_ID=YOUR_ID WATT42_API_TOKEN=YOUR_TOKEN poetry run panel serve main.py --port 5050
```

40
main.py Normal file
View file

@ -0,0 +1,40 @@
import json
import os
import panel
from typing import Any
from watt42_viewlib import attach_w42_state
panel.extension('echarts', 'ace', 'jsoneditor')
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 state_to_text(state: dict[str, Any]) -> str:
return f"## Watt42 State:\n\nTop lines (as json):\n\n```\n{'\n'.join(json.dumps(state, indent=2).split('\n')[:15])}\n```\n\nReplace this with some awesome visuals"
state_as_text = panel.bind(state_to_text, w42_state)
state_pane = panel.pane.Markdown(state_as_text, sizing_mode='stretch_width')
sidebar_content = """
This example shows how to build a front end for a Watt42 system: Watt42 API
manages the state of the system, this app visualizes it.
Find instructions on [how to use this example
here](https://source.c3.uber5.com/watt42-public/watt42_viewlib/src/branch/main/README.md#how-to-use).
"""
_ = panel.template.FastListTemplate(
title="Sample Watt42 App",
sidebar=[panel.pane.Markdown(sidebar_content, sizing_mode='stretch_width')],
main=[
state_pane,
w42_state,
],
).servable()

3711
poetry.lock generated Normal file

File diff suppressed because it is too large Load diff

2
poetry.toml Normal file
View file

@ -0,0 +1,2 @@
[virtualenvs]
in-project = true

27
pyproject.toml Normal file
View file

@ -0,0 +1,27 @@
[tool.poetry]
name = "watt42-view"
version = "0.1.0"
description = "Watt42 View, a browser-based app to visualize a Watt42 system, and to interact with it"
authors = ["Chris Oloff <chris@uber5.com>"]
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.12"
watt42-viewlib = {git = "https://source.c3.uber5.com/watt42-public/watt42_viewlib.git"}
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
[tool.basedpyright]
venvPath = "."
venv = ".venv"
# verboseOutput = true
# include = ["."]
# extraPaths = ["."]
reportMissingTypeStubs = false
[basedpyright.analysis]
extraPaths = ["."]
autoImportCompletions = true