Package as Home Assistant app - #13
Open
dnviti wants to merge 3 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR packages SolisMon3 as a Home Assistant add-on (“app” type) by adding add-on repository metadata, Home Assistant configuration/docs, and updating the container build/publish flow to use GHCR.
Changes:
- Added Home Assistant add-on repository files (
repository.yaml,solismon3/config.yaml,solismon3/README.md,solismon3/DOCS.md,solismon3/CHANGELOG.md). - Updated runtime configuration to load settings from Home Assistant options (
/data/options.json) with env var overrides. - Updated Docker image publishing to GHCR and refreshed Dockerfile labels/copy steps for the add-on container.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| solismon3/README.md | Adds add-on-focused README for Home Assistant. |
| solismon3/DOCS.md | Documents Home Assistant option fields and Prometheus port behavior. |
| solismon3/config.yaml | Introduces the Home Assistant add-on manifest (options/schema/ports/image). |
| solismon3/CHANGELOG.md | Adds a changelog entry for the Home Assistant packaging. |
| repository.yaml | Declares the repository as a Home Assistant add-on repository. |
| README.md | Updates GHCR image references and adds Home Assistant setup notes. |
| Dockerfile | Adds Home Assistant OCI labels/build args and updates build steps. |
| config/config.py | Switches from static constants to Home Assistant options/env-driven configuration. |
| .gitignore | Adds common Python cache ignores. |
| .github/workflows/docker-image.yml | Adds a workflow to build/push a multi-arch GHCR image. |
| .dockerignore | Reduces Docker build context and excludes non-runtime files. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+46
to
+47
| MQTT_USER = _setting("mqtt_user", "foo") # MQTT auth user | ||
| MQTT_PASS = _setting("mqtt_pass", "bar") # MQTT auth password |
Comment on lines
+23
to
+28
| normalized = str(value).strip().lower() | ||
| if normalized in {"1", "true", "yes", "on"}: | ||
| return True | ||
| if normalized in {"0", "false", "no", "off"}: | ||
| return False | ||
| raise ValueError(f"Invalid boolean value: {value}") |
| FROM python:3-alpine | ||
|
|
||
| ARG BUILD_VERSION=latest | ||
| ARG BUILD_ARCH="aarch64|amd64" |
| @@ -0,0 +1,44 @@ | |||
| name: "SolisMon3" | |||
| version: "latest" | |||
Comment on lines
+5
to
+6
| Set these options in the Home Assistant app UI: | ||
|
|
|
|
||
| SolisMon3 reads metrics directly from a Solis inverter WiFi stick and publishes them to MQTT, Prometheus, or both. | ||
|
|
||
| Configure the inverter, MQTT, scrape interval, Prometheus, and debug settings from the Home Assistant app options before starting the app. |
Comment on lines
+84
to
+88
| ### Home Assistant app | ||
| This repository can be added to Home Assistant as an app repository: | ||
| ``` | ||
| https://github.com/dnviti/solismon3 | ||
| ``` |
| PROMETHEUS = _setting("prometheus", False, _bool) # Enable Prometheus exporter | ||
| PROMETHEUS_PORT = _setting("prometheus_port", 18000, int) # Port to use for Prometheus exporter | ||
| MODIFIED_METRICS = _setting("modified_metrics", True, _bool) # Enable modified metrics | ||
| DEBUG = _setting("debug", False, _bool) # Enable debugging, helpfull to diagnose problems |
| @@ -0,0 +1,2 @@ | |||
| name: SolisMon3 Home Assistant Apps | |||
The monitor could be permanently killed by routine, transient conditions (inverter briefly unreachable, flaky Wi-Fi stick, MQTT broker down) and would slowly leak sockets/threads on a long-running host. This reworks the app so any error is logged and the process keeps running, actively retrying until it recovers and then continuing its work. main.py: - Remove all exit()/SystemExit paths; scrape_solis() now logs and returns True/False instead of terminating. Bounded read retries return False (no exit, no hot-loop, no stale/unbound regs consumption). - Run scraping in a background daemon thread (scrape_loop) that retries with exponential backoff capped at CHECK_INTERVAL on failure and resets to the normal cadence on success, so it recovers fast and never hangs or hammers. - Guarantee Modbus connection teardown in a finally (fixes fd/thread leak) and always disconnect the MQTT client. - Build metrics into a local dict and publish atomically on success, so a failed cycle keeps the last good snapshot (and avoids a dict-resize race). - Prometheus collect() now only serves the latest snapshot (instant, never blocks/raises); the exporter start retries a port-bind failure instead of exiting. - Guard timestamp parsing and register indexing against malformed frames. - Install SIGTERM/SIGINT handlers for clean, logged shutdown (Docker/Home Assistant stop with SIGTERM, which previously killed it with no cleanup). config/config.py: - Make config parsing total: a bad env var / option logs a warning and falls back to the default instead of raising at import time. - Clamp CHECK_INTERVAL to >= 1 to prevent a negative value crashing sleep() and a zero value busy-looping. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Make solismon resilient: never crash, retry until recovered
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Converted into an homeassistant app