Skip to content

Commit

Permalink
Minor fixes for freeze changes (#1474)
Browse files Browse the repository at this point in the history
* Minor fixes for freeze changes

* [pre-commit.ci lite] apply automatic fixes

* Region step in 2 hours

* [pre-commit.ci lite] apply automatic fixes

---------

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
  • Loading branch information
springfall2008 and pre-commit-ci-lite[bot] authored Sep 22, 2024
1 parent 612ad23 commit 905c1a0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions apps/predbat/inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,10 @@ def write_and_poll_switch(self, name, entity_id, new_value):
if isinstance(current_state, str):
current_state = current_state.lower() in ["on", "enable", "true"]

if current_state == new_value:
self.base.log("Inverter {} No write needed for {} as {} == {}".format(self.id, name, new_value, current_state))
return True

retry = 0
while current_state != new_value and retry < 6:
retry += 1
Expand Down
16 changes: 14 additions & 2 deletions apps/predbat/predbat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5429,6 +5429,9 @@ def optimise_charge_limit_price_threads(
if region_start and (charge_window[window_n]["start"] > region_end or charge_window[window_n]["end"] < region_start):
continue

if charge_window[window_n]["start"] in self.manual_all_times:
continue

if window_n in all_n:
if window_prices[window_n] > highest_price_charge:
highest_price_charge = window_prices[window_n]
Expand All @@ -5445,6 +5448,9 @@ def optimise_charge_limit_price_threads(
if region_start and (discharge_window[window_n]["start"] > region_end or discharge_window[window_n]["end"] < region_start):
continue

if discharge_window[window_n]["start"] in self.manual_all_times:
continue

try_discharge[window_n] = 100
if window_n in all_d:
if not self.calculate_discharge_oncharge:
Expand Down Expand Up @@ -6736,13 +6742,16 @@ def optimise_all_windows(self, best_metric, metric_keep):
)
if self.calculate_regions:
region_size = int(16 * 60)
while region_size >= 2 * 60:
min_region_size = int(2 * 60)
while region_size >= min_region_size:
self.log(">> Region optimisation pass width {}".format(region_size))
for region in range(0, self.end_record + self.minutes_now, region_size):
hit_end = False
for region in range(0, self.end_record + self.minutes_now, min_region_size):
region_end = min(region + region_size, self.end_record + self.minutes_now)

if region_end < self.minutes_now:
continue

(
self.charge_limit_best,
ignore_discharge_limits,
Expand Down Expand Up @@ -6782,6 +6791,9 @@ def optimise_all_windows(self, best_metric, metric_keep):
best_carbon=best_carbon,
tried_list=tried_list,
)
# Reached the end of the window
if region_end >= self.end_record + self.minutes_now:
break
region_size = int(region_size / 2)

# Keep the freeze but not the full discharge as that will be re-introduced later
Expand Down
1 change: 0 additions & 1 deletion apps/predbat/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,6 @@ async def html_config_post(self, request):
Save the Predbat config from an HTML page
"""
postdata = await request.post()
self.log("Post data: {}".format(postdata))
for pitem in postdata:
new_value = postdata[pitem]
if pitem:
Expand Down

0 comments on commit 905c1a0

Please sign in to comment.