Conversation
…n and node table completion
- Implemented a new Lovelace dashboard for PV production with two views: 1. PV Panel Layout displaying daily energy production per panel. 2. Panel Connectivity showing the number of readings received today per panel. - Created template sensors for max-value aggregation of daily energy and readings across all panels, improving performance by offloading calculations to the server-side. - Enhanced unit tests for sensor state restoration, ensuring proper handling of restored states and fallback mechanisms during component startup.
…or daily energy and readings
There was a problem hiding this comment.
Pull request overview
This PR improves restart behavior for the PyTap Home Assistant integration by persisting/restoring coordinator node readings (“snapshots”) and enhancing sensor-side restoration so entities can remain available with last known values after restarts.
Changes:
- Persist and restore
node_snapshotsin the coordinator store, and merge restored snapshot + energy accumulator state intocoordinator.data["nodes"]on startup. - Enhance sensor entity restoration with
_coerce_restored_state_valueand an additional fallback to HA’s last state whenRestoreSensordata isn’t available. - Add PV production dashboard YAML + documentation, plus small logging level adjustments and updated docs/planning notes.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
custom_components/pytap/coordinator.py |
Adds node snapshot persistence and startup restoration/merging logic. |
custom_components/pytap/sensor.py |
Adds restored-state coercion helper and expands startup restore behavior for sensors. |
custom_components/pytap/pytap/core/parser.py |
Downgrades a node-table completion log line from warning to info. |
tests/test_sensor.py |
Adds unit tests for coercion and integration-style restart restoration scenarios. |
tests/test_coordinator_persistence.py |
Adds coverage for loading/saving node_snapshots. |
README.md |
Documents restart-safe availability behavior. |
docs/implementation.md |
Documents new persistence behavior (energy + node snapshots). |
planning/future_considerations.md |
Updates roadmap notes (binary sensor “will not implement”, removes barcode modification item). |
dashboards/tigo.yaml |
Adds template sensors for max aggregation used by the dashboard. |
dashboards/pv_production_dashboard.yaml |
Adds a multi-view Lovelace dashboard layout for panel visualization. |
dashboards/pv_production.md |
Adds setup/usage documentation for the dashboard and template sensors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| **Template sensors** — include `tigo.yaml` in your HA configuration (e.g. via `template: !include tigo.yaml` or a packages directory). It provides: | ||
|
|
||
| | Sensor | Entity ID | Purpose | | ||
| |--------|-----------|---------| | ||
| | Tigo Max Daily Energy | `sensor.tigo_max_daily_energy` | Highest `_daily_energy` across all 26 panels (kWh) | | ||
| | Tigo Max Readings Today | `sensor.tigo_max_readings_today` | Highest `_readings_today` across all 26 panels | | ||
|
|
There was a problem hiding this comment.
tigo.yaml defines an additional sensor.tigo_max_power used by the Page 3 “Panel Power” view in the dashboard YAML, but this doc’s template-sensor list only mentions the daily-energy and readings aggregators. Consider documenting the max-power sensor as well so setup instructions are complete.
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
| def _coerce_restored_state_value(raw_state: str, sensor_key: str) -> int | float | None: | ||
| """Convert a restored state string to a native numeric sensor value.""" | ||
| if raw_state in (STATE_UNKNOWN, STATE_UNAVAILABLE, "None", "none", ""): | ||
| return None | ||
|
|
||
| try: | ||
| numeric_value = float(raw_state) | ||
| except (TypeError, ValueError): | ||
| return None | ||
|
|
||
| if sensor_key == "readings_today": | ||
| return int(numeric_value) | ||
|
|
There was a problem hiding this comment.
_coerce_restored_state_value can return non-finite floats (e.g., 'nan', 'inf') and will raise in the readings_today path (int(float('nan')) throws). Add a finite check (e.g., math.isfinite) after parsing, and for readings_today only coerce when the value is a whole number to avoid silently truncating strings like '42.9'.
| ## tigo.yaml — Template Sensors | ||
|
|
||
| Server-side Jinja2 template sensors that aggregate all 24 panel values: | ||
|
|
||
| ```yaml | ||
| template: | ||
| - sensor: | ||
| - name: "Tigo Max Daily Energy" # sensor.tigo_max_daily_energy | ||
| state: "{{ [all 24 _daily_energy states] | map('float', 0) | max }}" | ||
|
|
||
| - name: "Tigo Max Readings Today" # sensor.tigo_max_readings_today | ||
| state: "{{ [all 24 _readings_today states] | map('float', 0) | max }}" | ||
| ``` |
There was a problem hiding this comment.
Later in the doc, the “tigo.yaml — Template Sensors” section again references aggregating “all 24 panel values” / “all 24 _daily_energy states”, but tigo.yaml in this PR enumerates 26 panels. Please update these placeholders to 26 (or make the wording panel-count-agnostic).
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This pull request introduces restart-safe sensor state restoration and improves the persistence and recovery of node and energy data in the PyTap Home Assistant integration. It also enhances logging clarity and robustness of sensor value restoration, and adds documentation for a new PV production dashboard.
Restart-safe state restoration and persistence:
README.mdand the implementation incoordinator.py, with new helpers for building, merging, and saving node snapshots. [1] [2] [3] [4] [5]Sensor restoration improvements:
_coerce_restored_state_valuehelper to convert string states to native numeric types. This ensures sensors do not become unavailable after a restart if prior data exists. [1] [2] [3] [4]Logging enhancements:
warningtoinfoincoordinator.pyandparser.pyfor infrastructure and node table events, reducing unnecessary warning noise and improving log clarity. [1] [2] [3]Documentation updates:
dashboards/pv_production.mdfile detailing the Lovelace dashboard for PV panel layout and connectivity, including color scaling formulas, grid arrangement, YAML structure, and template sensor aggregation.