Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions apps/predbat/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@
"default": False,
"enable": "lattice_control_enable",
},
{
"name": "lattice_schedule_shadow_enable",
"friendly_name": "Lattice Schedule Shadow (experimental)",
"type": "switch",
"default": False,
},
{
"name": "lattice_schedule_control_enable",
"friendly_name": "Lattice Schedule Control (experimental)",
"type": "switch",
"default": False,
"enable": "lattice_control_enable",
},
{
"name": "active",
"friendly_name": "Predbat Active",
Expand Down
3 changes: 3 additions & 0 deletions apps/predbat/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from utils import dp0, dp2, dp3, calc_percent_limit, find_charge_rate
from predbat_metrics import metrics
from inverter import Inverter
from lattice_schedule_integration import lattice_balance_writer, lattice_plan_writer
import time

"""
Expand All @@ -35,6 +36,7 @@ class Execute:
adjustment, and multi-inverter balancing.
"""

@lattice_plan_writer
def execute_plan(self):
status_extra = "" # extra status text added to Predbat notifications
status_hold_car = "" # car hold status text
Expand Down Expand Up @@ -945,6 +947,7 @@ def publish_inverter_data(self):
},
)

@lattice_balance_writer
def balance_inverters(self, test_mode=False):
"""
Attempt to balance multiple inverters
Expand Down
4 changes: 4 additions & 0 deletions apps/predbat/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from component_base import ComponentBase
from lattice_control import CAPABILITY_CHARGE_POWER_LIMIT, LatticeScalarDispatcher
from lattice_schedule_integration import lattice_async_writer
from lattice_topology import LatticeTopologyStore, TopologyValidationError

try:
Expand Down Expand Up @@ -1574,6 +1575,7 @@ def _plan_changed(self, plan_entries):
return True
return plan_entries != self._last_published_plan

@lattice_async_writer("gateway legacy plan publish")
async def publish_plan(self, plan_entries, timezone_str):
"""Build and publish an ExecutionPlan protobuf to the gateway.

Expand Down Expand Up @@ -1604,6 +1606,7 @@ async def publish_plan(self, plan_entries, timezone_str):
self._last_published_plan = plan_entries
self.log(f"Info: GatewayMQTT: Published execution plan v{self._plan_version} ({len(plan_entries)} entries)")

@lattice_async_writer("gateway legacy plan republish")
async def _republish_plan_if_stale(self):
"""Re-publish the last plan periodically so its embedded timestamp stays fresh.

Expand All @@ -1625,6 +1628,7 @@ async def _republish_plan_if_stale(self):
self._last_plan_publish_time = time.time()
self.log("Info: GatewayMQTT: Re-published execution plan (refreshed timestamp)")

@lattice_async_writer(lambda _gateway, command, **_kwargs: "gateway legacy command {}".format(command))
async def publish_command(self, command, **kwargs):
"""Build and publish a JSON command to the gateway.

Expand Down
7 changes: 6 additions & 1 deletion apps/predbat/lattice_schedule_authority.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ class AuthorityDecision:
command_id: str = ""
legacy_suppressed: bool = False
ending_transition_required: bool = False
installed_plan_digest: str = ""
durable_state_present: bool = False
fallback_allowed: bool = False
quarantined: bool = False
detail: str = ""
Expand Down Expand Up @@ -1062,9 +1064,11 @@ def _decision_from_snapshot(snapshot, now_ts_ms):
decision,
legacy_suppressed=True,
ending_transition_required=now_ts_ms >= installed["valid_until_ts_ms"],
installed_plan_digest=installed["applied_plan_digest"],
durable_state_present=record is not None,
fallback_allowed=False,
)
return decision
return replace(decision, durable_state_present=record is not None)


class LatticeScheduleAuthority:
Expand Down Expand Up @@ -1339,6 +1343,7 @@ async def legacy_decision(self, now_ts_ms):
return AuthorityDecision(
RESULT_UNKNOWN,
legacy_suppressed=True,
durable_state_present=snapshot is not _LOAD_FAILED,
quarantined=True,
detail="corrupt persisted authority state",
)
Expand Down
Loading
Loading