diff --git a/gsy_framework/constants_limits.py b/gsy_framework/constants_limits.py index b0cb57fa..c5527c3c 100644 --- a/gsy_framework/constants_limits.py +++ b/gsy_framework/constants_limits.py @@ -39,6 +39,7 @@ class GeneralSettings: # Max energy price (market maker rate) in ct / kWh DEFAULT_MARKET_MAKER_RATE = 30 # 0.3 Eur + DEFAULT_FEED_IN_TARIFF = 0 # interval between offer/bid postings DEFAULT_UPDATE_INTERVAL = 1 # in minutes MIN_UPDATE_INTERVAL = 1 # in minutes @@ -273,8 +274,8 @@ class GlobalConfig: RANDOM_SEED = 0 MARKET_MAKER_RATE = ConstSettings.GeneralSettings.DEFAULT_MARKET_MAKER_RATE POWER_FLOW = False + FEED_IN_TARIFF = 0 CONFIG_TYPE = ConfigurationType.SIMULATION.value - FEED_IN_TARIFF = 20 # Default simulation settings gsy-e side: start_date = instance((datetime.combine(START_DATE, datetime.min.time()))) diff --git a/gsy_framework/validators/heat_pump_validator.py b/gsy_framework/validators/heat_pump_validator.py index 2dbcf11d..3dcb6daa 100644 --- a/gsy_framework/validators/heat_pump_validator.py +++ b/gsy_framework/validators/heat_pump_validator.py @@ -1,4 +1,4 @@ -from gsy_framework.constants_limits import ConstSettings +from gsy_framework.constants_limits import ConstSettings, GlobalConfig from gsy_framework.exceptions import GSyDeviceException from gsy_framework.validators.base_validator import BaseValidator from gsy_framework.validators.utils import validate_range_limit @@ -67,20 +67,23 @@ def _validate_temp(cls, **kwargs): @classmethod def validate_rate(cls, **kwargs): """Validate energy rate related arguments.""" - if not(kwargs.get("initial_buying_rate") - and kwargs.get("final_buying_rate") - and kwargs.get("update_interval")): + if (kwargs.get("initial_buying_rate") is None + and kwargs.get("final_buying_rate") is None + and kwargs.get("update_interval") is None): return - if (not kwargs.get("initial_buying_rate") - or not kwargs.get("final_buying_rate") - or not kwargs.get("update_interval")): + if (kwargs.get("initial_buying_rate") is None + or kwargs.get("update_interval") is None): raise GSyDeviceException( {"misconfiguration": [ "All pricing parameters of heat pump should be provided:" - "initial_buying_rate, final_buying_rate, update_interval"]}) + "initial_buying_rate, update_interval"]}) + + if kwargs.get("update_interval") == 0: + raise GSyDeviceException( + {"misconfiguration": ["update_interval should not be zero"]}) buying_rate_arg_names = [ - "initial_buying_rate", "preferred_buying_rate", "final_buying_rate"] + "initial_buying_rate", "preferred_buying_rate"] for buying_rate_arg_name in buying_rate_arg_names: cls._check_range( name=buying_rate_arg_name, value=kwargs[buying_rate_arg_name], @@ -89,7 +92,9 @@ def validate_rate(cls, **kwargs): initial_buying_rate = kwargs["initial_buying_rate"] preferred_buying_rate = kwargs["preferred_buying_rate"] - final_buying_rate = kwargs["final_buying_rate"] + final_buying_rate = ( + kwargs.get("final_buying_rate") if kwargs.get("final_buying_rate") + else GlobalConfig.MARKET_MAKER_RATE) validate_range_limit( initial_buying_rate, preferred_buying_rate, final_buying_rate, diff --git a/tests/test_savings_kpi.py b/tests/test_savings_kpi.py index 45d6a284..95d73022 100644 --- a/tests/test_savings_kpi.py +++ b/tests/test_savings_kpi.py @@ -7,6 +7,8 @@ class FakeEndpointBuffer: + """Fake class for EndpointBuffer""" + grid_uuid = str(uuid4()) house1_uuid = str(uuid4()) house2_uuid = str(uuid4()) @@ -35,19 +37,19 @@ class FakeEndpointBuffer: ]} ]} core_stats = { - grid_uuid: {"const_fee_rate": 1, "feed_in_tariff": 20.0, "market_maker_rate": 30.0}, - house1_uuid: {"const_fee_rate": 0.5, "feed_in_tariff": 20.0, "market_maker_rate": 30.0} + grid_uuid: {"const_fee_rate": 1, "feed_in_tariff": 0.0, "market_maker_rate": 30.0}, + house1_uuid: {"const_fee_rate": 0.5, "feed_in_tariff": 0.0, "market_maker_rate": 30.0} } current_market_slot = "2021-09-13T12:45" @pytest.fixture(name="savings_kpi") -def savings_kpi_fixture(): +def fixture_savings_kpi(): return SavingsKPI() @pytest.fixture(name="kpi") -def kpi_fixture(): +def fixture_kpi(): return KPI() @@ -106,12 +108,12 @@ def test_market_maker_rate_including_path_grid_fees(kpi, savings_kpi): endpoint_buffer.current_market_slot) house1_core_stats = endpoint_buffer.core_stats.get(endpoint_buffer.house1_uuid, {}) - expected_mmr_minus_glp = savings_kpi._get_market_maker_rate_including_path_grid_fees( + actual_mmr_minus_glp = savings_kpi._get_market_maker_rate_including_path_grid_fees( house1_core_stats, kpi.area_uuid_cum_grid_fee_mapping[endpoint_buffer.house1_uuid]) - actual_mmr_minus_glp = GlobalConfig.market_maker_rate + ( + expected_mmr_minus_glp = GlobalConfig.market_maker_rate + ( endpoint_buffer.core_stats[endpoint_buffer.grid_uuid]["const_fee_rate"] + endpoint_buffer.core_stats[endpoint_buffer.house1_uuid]["const_fee_rate"]) - assert actual_mmr_minus_glp == expected_mmr_minus_glp + assert expected_mmr_minus_glp == actual_mmr_minus_glp diff --git a/tests/test_validators/test_heatpump_validator.py b/tests/test_validators/test_heatpump_validator.py index da3cd938..83f06273 100644 --- a/tests/test_validators/test_heatpump_validator.py +++ b/tests/test_validators/test_heatpump_validator.py @@ -1,3 +1,5 @@ +from copy import copy + import pytest from gsy_framework.exceptions import GSyDeviceException @@ -90,6 +92,19 @@ def test_heatpump_validator_checks_price_params(hp_validator_class, hp_params): with pytest.raises(GSyDeviceException): hp_validator_class().validate(**{**hp_params, "preferred_buying_rate": 31}) + hp_validator_class().validate(**{**hp_params}) + + wrong_price_params = copy(hp_params) + wrong_price_params["initial_buying_rate"] = 0 + wrong_price_params["update_interval"] = 0 # not allowed value + with pytest.raises(GSyDeviceException): + hp_validator_class().validate(**wrong_price_params) + + for none_param_key in ["update_interval", "initial_buying_rate"]: + wrong_price_params[none_param_key] = None + with pytest.raises(GSyDeviceException): + hp_validator_class().validate(**wrong_price_params) + @staticmethod def test_heatpump_validator_checks_profile_params(): with pytest.raises(GSyDeviceException):