Skip to content

Commit

Permalink
[pre-commit.ci lite] apply automatic fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci-lite[bot] authored Dec 22, 2024
1 parent a78b38d commit ac16cf2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
3 changes: 1 addition & 2 deletions apps/predbat/inverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ def create_entity(self, entity_name, value, uom=None, device_class="None"):
attributes["unit_of_measurement"] = uom
if device_class is not None:
attributes["device_class"] = device_class

self.created_attributes[entity_id] = attributes

if self.base.get_state_wrapper(entity_id) is None:
Expand Down Expand Up @@ -2211,7 +2211,6 @@ def rest_getData(self, url):
else:
return None


def rest_setChargeTarget(self, target):
"""
Configure charge target % via REST
Expand Down
25 changes: 14 additions & 11 deletions apps/predbat/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def get_state(self, entity_id, default=None, attribute=None, refresh=False):
return None

def call_service(self, service, **kwargs):
#print("Calling service: {} {}".format(service, kwargs))
# print("Calling service: {} {}".format(service, kwargs))
if service == "number/set_value":
entity_id = kwargs.get("entity_id", None)
if not entity_id.startswith("number."):
Expand Down Expand Up @@ -415,12 +415,14 @@ def run_compute_metric_tests(my_predbat):
failed |= compute_metric_test(my_predbat, "cost_battery_cycle", cost=10.0, battery_cycle=25, metric_battery_cycle=0.1, assert_metric=10 + 25 * 0.1)
return failed


def dummy_sleep(seconds):
"""
Dummy sleep function
"""
pass


class DummyRestAPI:
def __init__(self):
self.commands = []
Expand All @@ -430,21 +432,22 @@ def dummy_rest_postCommand(self, url, json):
"""
Dummy rest post command
"""
#print("Dummy rest post command {} {}".format(url, json))
# print("Dummy rest post command {} {}".format(url, json))
self.commands.append([url, json])

def dummy_rest_getData(self, url):
if url == "dummy/runAll":
#print("Dummy rest get data {} returns {}".format(url, self.rest_data))
# print("Dummy rest get data {} returns {}".format(url, self.rest_data))
return self.rest_data
else:
return None

def get_commands(self):
commands = self.commands
self.commands = []
return commands


def test_adjust_battery_target(testname, ha, inv, prev_soc, soc, isCharging, isExporting, expect_soc=None):
failed = False
if expect_soc is None:
Expand All @@ -461,13 +464,12 @@ def test_adjust_battery_target(testname, ha, inv, prev_soc, soc, isCharging, isE
print("ERROR: Charge limit should be {} got {}".format(expect_soc, ha.get_state("number.charge_limit")))
failed = True


# REST Mode
dummy_rest = DummyRestAPI()
inv.rest_api = "dummy"
inv.rest_data = {}
inv.rest_data["Control"] = {}
inv.rest_data["Control"]["Target_SOC"] = prev_soc
inv.rest_data["Control"]["Target_SOC"] = prev_soc
inv.rest_postCommand = dummy_rest.dummy_rest_postCommand
inv.rest_getData = dummy_rest.dummy_rest_getData
dummy_rest.rest_data = copy.deepcopy(inv.rest_data)
Expand All @@ -476,17 +478,17 @@ def test_adjust_battery_target(testname, ha, inv, prev_soc, soc, isCharging, isE
inv.adjust_battery_target(soc, isCharging=True, isExporting=False)
rest_command = dummy_rest.get_commands()
if soc != prev_soc:
expect_data = [['dummy/setChargeTarget', {'chargeToPercent': expect_soc}]]
expect_data = [["dummy/setChargeTarget", {"chargeToPercent": expect_soc}]]
else:
expect_data = []
if json.dumps(expect_data) != json.dumps(rest_command):
print("ERROR: Rest command should be {} got {}".format(expect_data, rest_command))
failed = True

return failed

def run_inverter_tests():

def run_inverter_tests():
"""
Test the inverter functions
"""
Expand Down Expand Up @@ -536,7 +538,7 @@ def run_inverter_tests():
my_predbat.ha_interface.dummy_items = dummy_items
my_predbat.args["auto_restart"] = [{"service": "switch/turn_on", "entity_id": "switch.restart"}]
my_predbat.args["givtcp_rest"] = None
my_predbat.args['inverter_type'] = ["GE"]
my_predbat.args["inverter_type"] = ["GE"]
for entity_id in dummy_items.keys():
arg_name = entity_id.split(".")[1]
my_predbat.args[arg_name] = entity_id
Expand All @@ -552,6 +554,7 @@ def run_inverter_tests():

return failed


def simple_scenario(
name,
my_predbat,
Expand Down Expand Up @@ -4230,7 +4233,7 @@ def run_model_tests(my_predbat):
my_predbat,
0,
0,
assert_final_metric=import_rate * 120 * 1.5 - 2*import_rate*5*2,
assert_final_metric=import_rate * 120 * 1.5 - 2 * import_rate * 5 * 2,
assert_final_soc=0,
with_battery=False,
iboost_enable=True,
Expand Down

0 comments on commit ac16cf2

Please sign in to comment.