Skip to content

Package as Home Assistant app - #13

Open
dnviti wants to merge 3 commits into
NosIreland:masterfrom
dnviti:master
Open

Package as Home Assistant app#13
dnviti wants to merge 3 commits into
NosIreland:masterfrom
dnviti:master

Conversation

@dnviti

@dnviti dnviti commented May 11, 2026

Copy link
Copy Markdown

Converted into an homeassistant app

Copilot AI review requested due to automatic review settings May 11, 2026 17:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 thread config/config.py
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 thread config/config.py Outdated
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}")
Comment thread Dockerfile
FROM python:3-alpine

ARG BUILD_VERSION=latest
ARG BUILD_ARCH="aarch64|amd64"
Comment thread solismon3/config.yaml
@@ -0,0 +1,44 @@
name: "SolisMon3"
version: "latest"
Comment thread solismon3/DOCS.md
Comment on lines +5 to +6
Set these options in the Home Assistant app UI:

Comment thread solismon3/README.md

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 thread README.md
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
```
Comment thread config/config.py
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
Comment thread repository.yaml
@@ -0,0 +1,2 @@
name: SolisMon3 Home Assistant Apps
dnviti and others added 2 commits May 30, 2026 19:20
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants