Skip to content

Commit

Permalink
Attempt to fix freeze not restoring discharge rate issue (#1944)
Browse files Browse the repository at this point in the history
* Attempt to fix freeze not restoring discharge rate issue

#1941

* Update code-quality.yml

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

* Update custom-dictionary-workspace.txt

* [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 Feb 1, 2025
1 parent 54c403c commit 26b8970
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 46 deletions.
1 change: 1 addition & 0 deletions .cspell/custom-dictionary-workspace.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ sunsynk
tasmota
tdata
tdiff
testname
thirdparty
timea
timeb
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ jobs:
with:
python-version: 3.x
- uses: pre-commit/[email protected]
- uses: pre-commit-ci/lite-action@v1.0.1
- uses: pre-commit-ci/lite-action@v1.1.0
if: always()
4 changes: 4 additions & 0 deletions apps/predbat/inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1143,9 +1143,13 @@ def mimic_target_soc(self, current_charge_limit, discharge=False):
self.alt_charge_discharge_enable("eco", True) # ECO Mode
if self.inv_output_charge_control == "current":
self.set_current_from_power("charge", charge_power) # Write previous current setting to inverter
if self.inv_output_charge_control == "current":
self.set_current_from_power("discharge", discharge_power) # Reset discharge power too
elif self.soc_percent > float(current_charge_limit):
# If current SOC is above Target SOC, turn Grid Charging off
self.alt_charge_discharge_enable("charge", False)
if self.inv_output_charge_control == "current":
self.set_current_from_power("charge", (0)) # Set charge current to zero (i.e hold SOC)
self.base.log(f"Current SOC {self.soc_percent}% is greater than Target SOC {current_charge_limit}. Grid Charge disabled.")
elif self.soc_percent == float(current_charge_limit): # If SOC target is reached
self.alt_charge_discharge_enable("charge", True) # Make sure charging is on
Expand Down
2 changes: 1 addition & 1 deletion apps/predbat/octopus.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def load_octopus_slots(self, octopus_slots, octopus_intelligent_consider_full):

# Sort slots by start time
slots_sorted = sorted(slots_decoded, key=lambda x: x[0])

# Add in the current charging slot
for slot in slots_sorted:
start_minutes, end_minutes, kwh, source, location = slot
Expand Down
54 changes: 10 additions & 44 deletions apps/predbat/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,7 @@ def run_car_charging_smart_test(test_name, my_predbat, battery_size=10.0, limit=

return failed


def run_load_octopus_slot_test(testname, my_predbat, slots, expected_slots, consider_full, car_soc, car_limit, car_loss):
"""
Run a test for load_octopus_slot
Expand All @@ -1421,6 +1422,7 @@ def run_load_octopus_slot_test(testname, my_predbat, slots, expected_slots, cons
failed = True
return failed


def run_load_octopus_slots_tests(my_predbat):
"""
Test for load octopus slots
Expand All @@ -1445,62 +1447,26 @@ def run_load_octopus_slots_tests(my_predbat):
expected_slots3 = []
expected_slots4 = []
now_utc = my_predbat.now_utc
midnight_utc = my_predbat.midnight_utc\

midnight_utc = my_predbat.midnight_utc
reset_rates(my_predbat, 10, 5)
my_predbat.rate_min = 4

# Created 8 slots in total in the next 16 hours
soc = 2.0
soc2 = 2.0
for i in range(8):
start = now_utc + timedelta(minutes=i*60)
start = now_utc + timedelta(minutes=i * 60)
end = start + timedelta(minutes=30)
soc += 5
soc2 += 2.5
slots.append(
{
"start": start.strftime(TIME_FORMAT),
"end": end.strftime(TIME_FORMAT),
"charge_in_kwh": -5,
"source": "null",
"location": "AT_HOME"
})
slots.append({"start": start.strftime(TIME_FORMAT), "end": end.strftime(TIME_FORMAT), "charge_in_kwh": -5, "source": "null", "location": "AT_HOME"})
minutes_start = int((start - midnight_utc).total_seconds() / 60)
minutes_end = int((end - midnight_utc).total_seconds() / 60)
expected_slots.append(
{"start": minutes_start,
"end": minutes_end,
"kwh": 5.0,
"average": 4,
"cost": 20.0,
"soc": 0.0
})
expected_slots2.append(
{"start": minutes_start,
"end": minutes_end,
"kwh": 0.0,
"average": 4,
"cost": 0.0,
"soc": 0.0
})
expected_slots3.append(
{"start": minutes_start,
"end": minutes_end,
"kwh": 5.0 if soc <= 12.0 else 0.0,
"average": 4,
"cost": 20.0 if soc <= 12.0 else 0.0,
"soc": min(soc, 12.0)
})
expected_slots4.append(
{"start": minutes_start,
"end": minutes_end,
"kwh": 5.0 if soc <= 24.0 else 0.0,
"average": 4,
"cost": 20.0 if soc <= 24.0 else 0.0,
"soc": min(soc2, 12.0)
})

expected_slots.append({"start": minutes_start, "end": minutes_end, "kwh": 5.0, "average": 4, "cost": 20.0, "soc": 0.0})
expected_slots2.append({"start": minutes_start, "end": minutes_end, "kwh": 0.0, "average": 4, "cost": 0.0, "soc": 0.0})
expected_slots3.append({"start": minutes_start, "end": minutes_end, "kwh": 5.0 if soc <= 12.0 else 0.0, "average": 4, "cost": 20.0 if soc <= 12.0 else 0.0, "soc": min(soc, 12.0)})
expected_slots4.append({"start": minutes_start, "end": minutes_end, "kwh": 5.0 if soc <= 24.0 else 0.0, "average": 4, "cost": 20.0 if soc <= 24.0 else 0.0, "soc": min(soc2, 12.0)})

failed |= run_load_octopus_slot_test("test1", my_predbat, slots, expected_slots, False, 2.0, 0.0, 1.0)
failed |= run_load_octopus_slot_test("test2", my_predbat, slots, expected_slots2, True, 2.0, 0.0, 1.0)
failed |= run_load_octopus_slot_test("test3", my_predbat, slots, expected_slots3, True, 2.0, 12.0, 1.0)
Expand Down

0 comments on commit 26b8970

Please sign in to comment.