From 2e9096ad390af8126fc09c7328cdc54d2e5424fb Mon Sep 17 00:00:00 2001 From: PauloRadatz Date: Mon, 7 Oct 2024 11:26:43 -0400 Subject: [PATCH] Storage Tests completed --- src/py_dss_interface/configurations.json | 7 + .../models/Storages/StoragesF.py | 20 -- .../models/Storages/StoragesS.py | 5 +- tests/py_dss_interface/test_pvsystems.py | 4 + tests/py_dss_interface/test_storages.py | 340 ++++++++++++++++++ 5 files changed, 353 insertions(+), 23 deletions(-) create mode 100644 tests/py_dss_interface/test_storages.py diff --git a/src/py_dss_interface/configurations.json b/src/py_dss_interface/configurations.json index aea99e76..f0c10759 100644 --- a/src/py_dss_interface/configurations.json +++ b/src/py_dss_interface/configurations.json @@ -196,6 +196,13 @@ "F" ] }, + { + "name": "Storages", + "types": [ + "S", + "F" + ] + }, { "name": "SwtControls", diff --git a/src/py_dss_interface/models/Storages/StoragesF.py b/src/py_dss_interface/models/Storages/StoragesF.py index 56f34200..fc29d563 100644 --- a/src/py_dss_interface/models/Storages/StoragesF.py +++ b/src/py_dss_interface/models/Storages/StoragesF.py @@ -25,139 +25,119 @@ def _pu_soc_read(self) -> float: return float(self._dss_obj.StoragesF(ctypes.c_int32(0), ctypes.c_double(0))) def _pu_soc_write(self, argument) -> float: - argument = Base._check_float_param(argument) return float(self._dss_obj.StoragesF(ctypes.c_int32(1), ctypes.c_double(argument))) def _amp_limit_read(self) -> float: return float(self._dss_obj.StoragesF(ctypes.c_int32(2), ctypes.c_double(0))) def _amp_limit_write(self, argument) -> float: - argument = Base._check_float_param(argument) return float(self._dss_obj.StoragesF(ctypes.c_int32(3), ctypes.c_double(argument))) def _amp_limit_gain_read(self) -> float: return float(self._dss_obj.StoragesF(ctypes.c_int32(4), ctypes.c_double(0))) def _amp_limit_gain_write(self, argument) -> float: - argument = Base._check_float_param(argument) return float(self._dss_obj.StoragesF(ctypes.c_int32(5), ctypes.c_double(argument))) def _charge_trigger_read(self) -> float: return float(self._dss_obj.StoragesF(ctypes.c_int32(6), ctypes.c_double(0))) def _charge_trigger_write(self, argument) -> float: - argument = Base._check_float_param(argument) return float(self._dss_obj.StoragesF(ctypes.c_int32(7), ctypes.c_double(argument))) def _discharge_trigger_read(self) -> float: return float(self._dss_obj.StoragesF(ctypes.c_int32(8), ctypes.c_double(0))) def _discharge_trigger_write(self, argument) -> float: - argument = Base._check_float_param(argument) return float(self._dss_obj.StoragesF(ctypes.c_int32(9), ctypes.c_double(argument))) def _eff_charge_read(self) -> float: return float(self._dss_obj.StoragesF(ctypes.c_int32(10), ctypes.c_double(0))) def _eff_charge_write(self, argument) -> float: - argument = Base._check_float_param(argument) return float(self._dss_obj.StoragesF(ctypes.c_int32(11), ctypes.c_double(argument))) def _eff_discharge_read(self) -> float: return float(self._dss_obj.StoragesF(ctypes.c_int32(12), ctypes.c_double(0))) def _eff_discharge_write(self, argument) -> float: - argument = Base._check_float_param(argument) return float(self._dss_obj.StoragesF(ctypes.c_int32(13), ctypes.c_double(argument))) def _kp_read(self) -> float: return float(self._dss_obj.StoragesF(ctypes.c_int32(14), ctypes.c_double(0))) def _kp_write(self, argument) -> float: - argument = Base._check_float_param(argument) return float(self._dss_obj.StoragesF(ctypes.c_int32(15), ctypes.c_double(argument))) def _kv_read(self) -> float: return float(self._dss_obj.StoragesF(ctypes.c_int32(16), ctypes.c_double(0))) def _kv_write(self, argument) -> float: - argument = Base._check_float_param(argument) return float(self._dss_obj.StoragesF(ctypes.c_int32(17), ctypes.c_double(argument))) def _kva_read(self) -> float: return float(self._dss_obj.StoragesF(ctypes.c_int32(18), ctypes.c_double(0))) def _kva_write(self, argument) -> float: - argument = Base._check_float_param(argument) return float(self._dss_obj.StoragesF(ctypes.c_int32(19), ctypes.c_double(argument))) def _kvar_read(self) -> float: return float(self._dss_obj.StoragesF(ctypes.c_int32(20), ctypes.c_double(0))) def _kvar_write(self, argument) -> float: - argument = Base._check_float_param(argument) return float(self._dss_obj.StoragesF(ctypes.c_int32(21), ctypes.c_double(argument))) def _kvdc_read(self) -> float: return float(self._dss_obj.StoragesF(ctypes.c_int32(22), ctypes.c_double(0))) def _kvdc_write(self, argument) -> float: # TODO waiting Davis to answer the order - argument = Base._check_float_param(argument) return float(self._dss_obj.StoragesF(ctypes.c_int32(23), ctypes.c_double(argument))) def _kw_read(self) -> float: return float(self._dss_obj.StoragesF(ctypes.c_int32(24), ctypes.c_double(0))) def _kw_write(self, argument) -> float: - argument = Base._check_float_param(argument) return float(self._dss_obj.StoragesF(ctypes.c_int32(25), ctypes.c_double(argument))) def _kwh_rated_read(self) -> float: return float(self._dss_obj.StoragesF(ctypes.c_int32(26), ctypes.c_double(0))) def _kwh_rated_write(self, argument) -> float: - argument = Base._check_float_param(argument) return float(self._dss_obj.StoragesF(ctypes.c_int32(27), ctypes.c_double(argument))) def _kw_rated_read(self) -> float: return float(self._dss_obj.StoragesF(ctypes.c_int32(28), ctypes.c_double(0))) def _kw_rated_write(self, argument) -> float: - argument = Base._check_float_param(argument) return float(self._dss_obj.StoragesF(ctypes.c_int32(29), ctypes.c_double(argument))) def _limit_current_read(self) -> float: return float(self._dss_obj.StoragesF(ctypes.c_int32(30), ctypes.c_double(0))) def _limit_current_write(self, argument) -> float: - argument = Base._check_float_param(argument) return float(self._dss_obj.StoragesF(ctypes.c_int32(31), ctypes.c_double(argument))) def _pf_read(self) -> float: return float(self._dss_obj.StoragesF(ctypes.c_int32(32), ctypes.c_double(0))) def _pf_write(self, argument) -> float: - argument = Base._check_float_param(argument) return float(self._dss_obj.StoragesF(ctypes.c_int32(33), ctypes.c_double(argument))) def _pi_tol_read(self) -> float: return float(self._dss_obj.StoragesF(ctypes.c_int32(34), ctypes.c_double(0))) def _pi_tol_write(self, argument) -> float: - argument = Base._check_float_param(argument) return float(self._dss_obj.StoragesF(ctypes.c_int32(35), ctypes.c_double(argument))) def _safe_voltage_read(self) -> float: return float(self._dss_obj.StoragesF(ctypes.c_int32(36), ctypes.c_double(0))) def _safe_voltage_write(self, argument) -> float: - argument = Base._check_float_param(argument) return float(self._dss_obj.StoragesF(ctypes.c_int32(37), ctypes.c_double(argument))) def _time_charge_trig_read(self) -> float: return float(self._dss_obj.StoragesF(ctypes.c_int32(38), ctypes.c_double(0))) def _time_charge_trig_write(self, argument) -> float: - argument = Base._check_float_param(argument) return float(self._dss_obj.StoragesF(ctypes.c_int32(39), ctypes.c_double(argument))) diff --git a/src/py_dss_interface/models/Storages/StoragesS.py b/src/py_dss_interface/models/Storages/StoragesS.py index c9ed8144..3e99fbed 100644 --- a/src/py_dss_interface/models/Storages/StoragesS.py +++ b/src/py_dss_interface/models/Storages/StoragesS.py @@ -12,11 +12,10 @@ class StoragesS(Base): - def _name_read(self): + def _name_read(self) -> str: result = ctypes.c_char_p(self._dss_obj.StoragesS(ctypes.c_int32(0), ctypes.c_int32(0))) return result.value.decode('ascii') - def _name_write(self, argument): - argument = Base._check_string_param(argument) + def _name_write(self, argument: str) -> str: result = ctypes.c_char_p(self._dss_obj.StoragesS(ctypes.c_int32(1), argument.encode('ascii'))) return result.value.decode('ascii') diff --git a/tests/py_dss_interface/test_pvsystems.py b/tests/py_dss_interface/test_pvsystems.py index f2e94b9c..bff37b52 100644 --- a/tests/py_dss_interface/test_pvsystems.py +++ b/tests/py_dss_interface/test_pvsystems.py @@ -60,6 +60,10 @@ def test_pvsystems_first(self, dss): actual = dss.pvsystems.first() assert actual == expected + expected = 'pv1' + actual = dss.pvsystems.name + assert actual == expected + def test_pvsystems_next(self, dss): dss.text(r"New PVSystem.PV2 phases=3 " r"bus1=680 " diff --git a/tests/py_dss_interface/test_storages.py b/tests/py_dss_interface/test_storages.py new file mode 100644 index 00000000..be8e0593 --- /dev/null +++ b/tests/py_dss_interface/test_storages.py @@ -0,0 +1,340 @@ +# -*- coding: utf-8 -*- +# @Time : 10/7/2024 10:05 AM +# @Author : Paulo Radatz +# @Email : pradatz@epri.com +# @File : test_storages.py +# @Software: PyCharm + +import pytest + + +class TestBus13Storages: + + @pytest.fixture(scope='function') + def dss(self, solve_snap_13bus): + dss = solve_snap_13bus + dss.text("New Storage.St phases=3 bus1=SourceBus kv=13.8 pf=0.98 kWrated=100 %reserve=20 kva=110 effcurve=Eff " + "kWhrated=1000 %stored=70 %idlingkW=10 " + "%effcharge=90 %effdischarge=90 state=charging dispmode=default model=1") + return dss + + def test_first(self, dss): + expected = 1 + actual = dss.storages.first() + assert actual == expected + + dss.storages.name = "st" + + # expected = 'st' + # actual = dss.storages.name + # assert actual == expected + + def test_next(self, dss): + expected = 1 + actual = dss.storages.first() + assert actual == expected + + expected = 0 + actual = dss.storages.next() + assert actual == expected + + def test_count(self, dss): + expected = 1 + actual = dss.storages.count + assert actual == expected + + def test_read_idx(self, dss): + expected = 1 + actual = dss.storages.idx + assert actual == expected + + def test_write_idx(self, dss): + expected = 1 + dss.storages.idx = expected + actual = dss.storages.idx + assert actual == expected + + def test_read_state(self, dss): + expected = -1 + actual = dss.storages.state + assert actual == expected + + def test_write_state(self, dss): + expected = 1 + dss.storages.state = expected + actual = dss.storages.state + assert actual == expected + + def test_read_control_mode(self, dss): + expected = 0 + actual = dss.storages.control_mode + assert actual == expected + + def test_write_control_mode(self, dss): + expected = 1 + dss.storages.control_mode = expected + actual = dss.storages.control_mode + assert actual == expected + + def test_read_safe_mode(self, dss): + expected = 0 + actual = dss.storages.safe_mode + assert actual == expected + + def test_read_var_follow_inverter(self, dss): + expected = 0 + actual = dss.storages.var_follow_inverter + assert actual == expected + + def test_write_var_follow_inverter(self, dss): + expected = 1 + dss.storages.var_follow_inverter = expected + actual = dss.storages.var_follow_inverter + assert actual == expected + + def test_names(self, dss): + expected = ["st"] + actual = dss.storages.names + assert actual == expected + + def test_register_names(self, dss): + expected = ['kWh', 'kvarh', 'Max kW', 'Max kVA', 'Hours', 'Price($)'] + actual = dss.storages.register_names + assert actual == expected + + def test_register_values(self, dss): + expected = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0] + actual = dss.storages.register_values + assert actual == expected + + def test_read_pu_soc(self, dss): + expected = 0.7000000000000001 + actual = dss.storages.pu_soc + assert actual == expected + + def test_write_pu_soc(self, dss): + expected = 1 + dss.storages.pu_soc = expected + actual = dss.storages.pu_soc + assert actual == expected + + def test_read_amp_limit(self, dss): + expected = -1 + actual = dss.storages.amp_limit + assert actual == expected + + def test_write_amp_limit(self, dss): + expected = 1 + dss.storages.amp_limit = expected + actual = dss.storages.amp_limit + assert actual == expected + + def test_read_amp_limit_gain(self, dss): + expected = 0.8 + actual = dss.storages.amp_limit_gain + assert actual == expected + + def test_write_amp_limit_gain(self, dss): + expected = 1 + dss.storages.amp_limit_gain = expected + actual = dss.storages.amp_limit_gain + assert actual == expected + + def test_read_charge_trigger(self, dss): + expected = 0 + actual = dss.storages.charge_trigger + assert actual == expected + + def test_write_charge_trigger(self, dss): + expected = 1 + dss.storages.charge_trigger = expected + actual = dss.storages.charge_trigger + assert actual == expected + + def test_read_discharge_trigger(self, dss): + expected = 0 + actual = dss.storages.discharge_trigger + assert actual == expected + + def test_write_discharge_trigger(self, dss): + expected = 1 + dss.storages.discharge_trigger = expected + actual = dss.storages.discharge_trigger + assert actual == expected + + def test_read_eff_charge(self, dss): + expected = 90 + actual = dss.storages.eff_charge + assert actual == expected + + def test_write_eff_charge(self, dss): + expected = 1 + dss.storages.eff_charge = expected + actual = dss.storages.eff_charge + assert actual == expected + + def test_read_eff_discharge(self, dss): + expected = 90 + actual = dss.storages.eff_discharge + assert actual == expected + + def test_write_eff_discharge(self, dss): + expected = 1 + dss.storages.eff_discharge = expected + actual = dss.storages.eff_discharge + assert actual == expected + + def test_read_kp(self, dss): + expected = 0.01 + actual = dss.storages.kp + assert actual == expected + + def test_write_kp(self, dss): + expected = 1 + dss.storages.kp = expected + actual = dss.storages.kp + assert actual == expected + + def test_read_kv(self, dss): + expected = 13.8 + actual = dss.storages.kv + assert actual == expected + + def test_write_kv(self, dss): + expected = 1 + dss.storages.kv = expected + actual = dss.storages.kv + assert actual == expected + + def test_read_kva(self, dss): + expected = 110 + actual = dss.storages.kva + assert actual == expected + + def test_write_kva(self, dss): + expected = 1 + dss.storages.kva = expected + actual = dss.storages.kva + assert actual == expected + + def test_read_kvar(self, dss): + expected = 0 + actual = dss.storages.kvar + assert actual == expected + + def test_write_kvar(self, dss): + expected = 1 + dss.storages.kvar = expected + actual = dss.storages.kvar + assert actual == expected + + def test_read_kvdc(self, dss): + expected = 8 + actual = dss.storages.kvdc + assert actual == expected + + def test_write_kvdc(self, dss): + expected = 1 + dss.storages.kvdc = expected + actual = dss.storages.kvdc + assert actual == expected + + def test_read_kw(self, dss): + expected = -100 + actual = dss.storages.kw + assert actual == expected + + def test_write_kw(self, dss): + expected = 1 + dss.storages.kw = expected + actual = dss.storages.kw + assert actual == expected + + def test_read_kwh_rated(self, dss): + expected = 1000 + actual = dss.storages.kwh_rated + assert actual == expected + + def test_write_kwh_rated(self, dss): + expected = 1 + dss.storages.kwh_rated = expected + actual = dss.storages.kwh_rated + assert actual == expected + + def test_read_kw_rated(self, dss): + expected = 100 + actual = dss.storages.kw_rated + assert actual == expected + + def test_write_kw_rated(self, dss): + expected = 1 + dss.storages.kw_rated = expected + actual = dss.storages.kw_rated + assert actual == expected + + def test_read_limit_current(self, dss): + expected = 0 + actual = dss.storages.limit_current + assert actual == expected + + def test_write_limit_current(self, dss): + expected = 1 + dss.storages.limit_current = expected + actual = dss.storages.limit_current + assert actual == expected + + def test_read_pf(self, dss): + expected = 0.98 + actual = dss.storages.pf + assert actual == expected + + def test_write_pf(self, dss): + expected = 1 + dss.storages.pf = expected + actual = dss.storages.pf + assert actual == expected + + def test_read_pi_tol(self, dss): + expected = 0 + actual = dss.storages.pi_tol + assert actual == expected + + def test_write_pi_tol(self, dss): + expected = 1 + dss.storages.pi_tol = expected + actual = dss.storages.pi_tol + assert actual == expected + + def test_read_safe_voltage(self, dss): + expected = 80 + actual = dss.storages.safe_voltage + assert actual == expected + + def test_write_safe_voltage(self, dss): + expected = 1 + dss.storages.safe_voltage = expected + actual = dss.storages.safe_voltage + assert actual == expected + + def test_read_time_charge_trig(self, dss): + expected = 2 + actual = dss.storages.time_charge_trig + assert actual == expected + + def test_write_time_charge_trig(self, dss): + expected = 1 + dss.storages.time_charge_trig = expected + actual = dss.storages.time_charge_trig + assert actual == expected + + def test_read_name(self, dss): + expected = "st" + actual = dss.storages.name + assert actual == expected + + def test_write_name(self, dss): + expected = "st" + dss.storages.name = expected + actual = dss.storages.name + assert actual == expected +