Skip to content

Commit

Permalink
Add subcommand make-dashboard, for creating a Grafana Dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Apr 19, 2024
1 parent d835ada commit 208b5ae
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Define MQTT and sensor configuration separately from implementation.
The data logger uses a YAML file now, for example like `etc/mois.yaml`.
- Added subcommand `make-config`, for creating a configuration blueprint
- Added subcommand `make-dashboard`, for creating a Grafana Dashboard

## v0.0.2 - 2024-04-15
- Publish as `ds18b20-datalogger` package
Expand Down
3 changes: 3 additions & 0 deletions ds18b20_datalogger/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ def main():
elif subcommand == "make-config":
config_template = files("ds18b20_datalogger") / "datalogger.yaml"
print(config_template.read_text(), file=sys.stdout) # noqa: T201
elif subcommand == "make-dashboard":
dashboard = files("ds18b20_datalogger") / "grafana-dashboard.json"
print(dashboard.read_text(), file=sys.stdout) # noqa: T201
else:
raise ValueError(f"Subcommand unknown: {subcommand}")
9 changes: 9 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import subprocess
import typing as t

Expand Down Expand Up @@ -28,3 +29,11 @@ def test_cli_make_config():
config = yaml.safe_load(output)
assert "mqtt" in config
assert "one-wire" in config


def test_cli_make_dashboard():
exitcode, output = invoke("ds18b20-datalogger make-dashboard")
dashboard = json.loads(output)
assert "annotations" in dashboard
assert "panels" in dashboard
assert "title" in dashboard

0 comments on commit 208b5ae

Please sign in to comment.