M6-T08: add energy_cost expose provider + post-billing state publish
- expose.py: _energy_cost_provider yields buy/sell_price_now + import_cost_total /export_revenue_total (total_increasing, monetary), value_getters read from energy_cost_period; 2-element identifiers so the existing HA Discovery builder (which indexes identifiers[1]) works. Other providers/mechanism untouched. - main.py: energy-cost job calls publish_states after computing periods (no-op when MQTT/Discovery off). Tests added. Note: energy-cost sensors lack an availability heartbeat (ha_discovery mechanism limitation, out of scope here).
This commit is contained in:
@@ -109,6 +109,15 @@ def _run_scheduled_energy_cost() -> None:
|
||||
session: Session = session_local()
|
||||
try:
|
||||
compute_closed_periods(session)
|
||||
# After billing periods are computed, push fresh energy-cost state values
|
||||
# to MQTT/HA. publish_states is internally guarded by _should_publish
|
||||
# (MQTT disabled / not connected → no-op), so this never raises due to
|
||||
# unconfigured MQTT and does not block the billing job.
|
||||
try:
|
||||
from app.services.ha_discovery import publish_states
|
||||
publish_states(session)
|
||||
except Exception:
|
||||
logger.exception("_run_scheduled_energy_cost: publish_states failed (non-fatal)")
|
||||
except Exception:
|
||||
logger.exception("_run_scheduled_energy_cost: unexpected error")
|
||||
finally:
|
||||
|
||||
Reference in New Issue
Block a user