github nicois/foxess-control v1.0.12

latest releases: v1.0.23-beta.2, v1.0.23-beta.1, v1.0.22...
7 months ago

Fixed

  • Every FoxESS sensor silently freezes during a charge session's pre-window phase (surfaced 2026-04-25 by the new collect_ha_session.py trace collector). SmartOperationsSensor.native_value can return "scheduled" — a value added in 1.0.11-beta.9 to distinguish the charge card's pre-window state from the deferred state — but the sensor's _attr_options list was not updated when that phase value was introduced. HA's sensor base class rejects any state not in _attr_options and raises ValueError from async_write_ha_state(). Because DataUpdateCoordinator.async_update_listeners() iterates listeners sequentially and the exception was uncaught, every listener registered after SmartOperationsSensor stopped receiving updates. Observed blast radius on a live instance: coordinator polling succeeded every 5 minutes (success: True in the debug log), yet SoC, house load, generation, work mode, charge rate and every other FoxESS sensor had last_reported/last_changed frozen at their pre-session values for 50+ minutes. The smart_operations sensor itself stuck at idle (its last valid state) while the binary-sensor-class smart_charge_active — which registers earlier in the listener iteration — correctly showed on. Fixed by adding "scheduled" to _attr_options. Regression test TestSmartOperationsSensorOptionsCoverage parametrises over every string native_value can return and asserts each is in options — structurally prevents the class of defect.

Added

  • Repair surface for sensor state-write failures (C-026): the "scheduled-options" freeze above was invisible to the user until live tracing found it — the ValueError was log-only, and no Repair issue was raised while every sensor silently stopped updating for 50+ minutes. Defence-in-depth hardening: sensor listener callbacks now route through _safe_write_ha_state(), which wraps async_write_ha_state() in a narrow (ValueError, RuntimeError) try/except. On failure it logs, creates an HA Repair issue naming the offending entity and the error, and crucially does NOT re-raise — so listener iteration continues and other sensors still update. On the next successful write for that sensor, the Repair is dismissed automatically. Applied to SmartOperationsOverviewSensor and InverterOverrideStatusSensor (the two listener callbacks in smart_battery/sensor_base.py); the helper pattern scales to any future listener. New sensor_write_failed translation in strings.json provides the Repair card text. Seven-test regression suite (TestSensorListenerFailureSurfacesRepair) covers: Repair created with entity_id, recovery dismisses Repair, repeated failures don't spam (idempotent), listener iteration continues when one sensor raises, pattern applies to multiple sensor classes, helper logs the exception, happy-path is invisible.
  • schedule_write structured event emission: smart_battery/events.py has defined SCHEDULE_WRITE since 1.0.11-beta.7 but no call site was emitting it — grep showed the constant declared but never referenced. Live trace collection confirmed the gap: a 15-minute charge session captured tick_snapshot + algo_decision events but zero schedule_write records, despite confirmed inverter schedule writes. Inverter._post_schedule() now funnels every /op/v0/device/scheduler/enable call through a single path that emits one SCHEDULE_WRITE event per write (payload: groups list + API response + endpoint + call_site). Both Inverter.set_schedule and Inverter.set_work_mode route through it, so every code path that writes an inverter schedule (direct writes from _services.py / foxess_adapter.py, or self_use/force_charge/force_discharge via set_work_mode) produces exactly one event. Payload is JSON-serialisable so the replay harness can reconstruct exact API state changes; committed sample trace tests/replay_traces/sample_schedule_write.jsonl is picked up by the parametrised replay-regression test.
  • scripts/collect_ha_session.py — merged event + observation timeline collector: produces a single JSONL per session capturing both what the integration decided (algorithm decisions, schedule writes, session transitions, tick snapshots) and what the real inverter + house were doing at the same moments (SoC, house load, PV, grid flows, BMS temperature, work mode). This pairing is what simulator validation needs — feed the exogenous observations into the simulator, replay the decisions, and assert the simulator's resulting state agrees with HA's. Two modes: live (polls every 5 s, appends per-session files, auto-detects the log sensor across integration versions) and history (reconstructs a past time range via /api/history/period/). Paired systemd service systemd/foxess-collect-ha.service runs it continuously with Restart=always / 10-minute backoff between attempts (survives sustained HA outages without API-hammering). Credentials live in ~/.config/foxess-collect-ha.env (not in repo); systemd/foxess-collect-ha.env.example ships the template.
  • Soak-artefact run-directory collision fix: systemd/foxess-soak.service inlined its ExecStart script; systemd's own %/$-substitution layer swallowed ${TS}_${SHORT} and $$ before bash saw them, so every nightly run wrote into runs/_/ — overwriting the prior night's artefacts. Extracted to systemd/foxess-soak-run.sh so bash expands variables normally; runs now land in per-timestamped directories (runs/20260425_080536_d6dc5bc/...) as intended, enabling cross-run comparison.

Don't miss a new foxess-control release

NewReleases is sending notifications on new releases.