diff --git a/pyproject.toml b/pyproject.toml index 92f0ada..286d0d9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "weheat" -version = "2026.9.2" +version = "2026.9.3" description = "Weheat Backend" authors = ["Jesper Raemaekers ", "Kjell van Straaten "] license = "MIT" diff --git a/setup.py b/setup.py index 56d941c..a57980a 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ # prerequisite: setuptools # http://pypi.python.org/pypi/setuptools NAME = "weheat" -VERSION = "2026.9.2" +VERSION = "2026.9.3" PYTHON_REQUIRES = ">=3.10" REQUIRES = [ "urllib3 >= 1.25.3, < 3.0.0", diff --git a/tests/test_heat_pump.py b/tests/test_heat_pump.py index 8f15677..1259e9a 100644 --- a/tests/test_heat_pump.py +++ b/tests/test_heat_pump.py @@ -104,21 +104,37 @@ def test_cooling_start_conditions_without_a_log(): @pytest.mark.parametrize( - ("power_in", "power_out", "expected"), + ("state", "power_in", "power_out", "expected"), [ - (500, 2000, 4.0), - # while cooling the output power is negative, the ratio stays positive - (521, -2671, pytest.approx(5.126, abs=0.001)), - (0, 2000, 0), + # heat into the water is what heating is for, so the ratio is positive + (70, 500, 2000, 4.0), + (150, 500, 2000, 4.0), + # heat out of the water is what cooling is for, so that is positive too + (132, 521, -2671, pytest.approx(5.126, abs=0.001)), + # only cooling itself flips: defrosting and the water check take heat out + # of the water too, but not as the point, so they stay negative + (90, 500, -1000, -2.0), + (136, 500, -1000, -2.0), + # heat moving the wrong way for the state stays visible as a negative + # ratio, rather than reading as a good one + (132, 690, 7404, pytest.approx(-10.73, abs=0.01)), + (70, 500, -500, -1.0), + # without a state there is no way to tell, so report what was measured + (None, 500, -500, -1.0), ], ) -def test_cop(power_in, power_out, expected): - """Test the coefficient of performance is a positive ratio in every state.""" - pump = heat_pump(cm_mass_power_in=power_in, cm_mass_power_out=power_out) +def test_cop(state, power_in, power_out, expected): + """Test the coefficient of performance follows the state it was measured in.""" + pump = heat_pump(state=state, cm_mass_power_in=power_in, cm_mass_power_out=power_out) assert pump.cop == expected +def test_cop_without_input_power(): + """Test nothing is drawn, so nothing is moved per unit drawn.""" + assert heat_pump(state=40, cm_mass_power_in=0, cm_mass_power_out=0).cop == 0 + + def test_cooling_available_from(): """Test the restart delay is counted from the last cooling cycle.""" pump = heat_pump( diff --git a/weheat/__init__.py b/weheat/__init__.py index 1e43f6d..019e00c 100644 --- a/weheat/__init__.py +++ b/weheat/__init__.py @@ -14,7 +14,7 @@ """ # noqa: E501 -__version__ = "2026.9.2" +__version__ = "2026.9.3" # import apis into sdk package from weheat.api.energy_log_api import EnergyLogApi diff --git a/weheat/abstractions/heat_pump.py b/weheat/abstractions/heat_pump.py index 0a4ef60..f3be9cd 100644 --- a/weheat/abstractions/heat_pump.py +++ b/weheat/abstractions/heat_pump.py @@ -343,12 +343,23 @@ def cop(self) -> Union[float, None]: if input is None or output is None: return None - if input > 0: - # While cooling or defrosting the output power is negative, as heat is removed from - # the water. The amount of energy moved per unit of input is still a positive ratio. - return abs(output) / input + if input <= 0: + return 0 - return 0 + state = self.heat_pump_state + if state is None: + # Without a known state there is no telling which way the heat is meant + # to go, so report the ratio as measured. + return output / input + + # Cooling is the one state where taking heat out of the water is the + # point, so only there does a negative output power give a positive + # ratio. Correcting the sign per state rather than taking the absolute + # value keeps heat that moves the wrong way visible as a negative ratio, + # which happens at the start of a cooling cycle. Defrosting takes heat + # out of the water as well, but as a cost rather than the point, so it + # is left to read as the loss it is. + return (-1 if state is self.State.COOLING else 1) * output / input @property def indoor_unit_water_pump_state(self) -> Union[bool, None]: diff --git a/weheat/api_client.py b/weheat/api_client.py index 1d2c365..3ac7139 100644 --- a/weheat/api_client.py +++ b/weheat/api_client.py @@ -86,7 +86,7 @@ def __init__( self.default_headers[header_name] = header_value self.cookie = cookie # Set default User-Agent. - self.user_agent = 'OpenAPI-Generator/2026.9.2/python' + self.user_agent = 'OpenAPI-Generator/2026.9.3/python' self.client_side_validation = configuration.client_side_validation async def __aenter__(self): diff --git a/weheat/configuration.py b/weheat/configuration.py index 59d77cf..7f65d1f 100644 --- a/weheat/configuration.py +++ b/weheat/configuration.py @@ -381,7 +381,7 @@ def to_debug_report(self): "OS: {env}\n"\ "Python Version: {pyversion}\n"\ "Version of the API: v1\n"\ - "SDK Package Version: 2026.9.2".\ + "SDK Package Version: 2026.9.3".\ format(env=sys.platform, pyversion=sys.version) def get_host_settings(self):