From f1458e8e2a4c0884f9e82164f56215e9d48a6b99 Mon Sep 17 00:00:00 2001 From: booysenn Date: Sun, 3 Sep 2023 20:01:22 +0200 Subject: [PATCH] Add support to use weather adjustment when running a program --- pyopensprinkler/program.py | 10 ++++--- tests/test_program.py | 54 +++++++++++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/pyopensprinkler/program.py b/pyopensprinkler/program.py index 1d78e14..05e7c6b 100644 --- a/pyopensprinkler/program.py +++ b/pyopensprinkler/program.py @@ -37,9 +37,11 @@ async def _set_variables(self, params=None): content = await self._controller.request("/cp", params) return content["result"] - async def _manual_run(self): + async def _manual_run(self, uwt=None): """Run program""" - params = {"pid": self._index, "uwt": 0} + if uwt is None: + uwt = self.use_weather_adjustments + params = {"pid": self._index, "uwt": int(uwt)} content = await self._controller.request("/mp", params) return content["result"] @@ -72,9 +74,9 @@ async def set_enabled(self, value): else: return await self._set_variable("en", 0) - async def run(self): + async def run(self, uwt=None): """Run program""" - return await self._manual_run() + return await self._manual_run(uwt) async def set_name(self, name): dlist = self._get_program_data().copy() diff --git a/tests/test_program.py b/tests/test_program.py index 6b9c308..7333e0e 100644 --- a/tests/test_program.py +++ b/tests/test_program.py @@ -1,5 +1,7 @@ -import pytest +import asyncio +import pytest +from const import FIRMWARE_VERSION @pytest.fixture async def program(controller): @@ -32,6 +34,56 @@ async def test_odd_even_restriction(self, controller, program): assert program.odd_even_restriction == 0 assert program.odd_even_restriction_name is None + @pytest.mark.skipif(FIRMWARE_VERSION <= 216, reason="only for version 217 and above") + @pytest.mark.asyncio + async def test_program_manual_run(self, controller, program): + await program.set_station_duration(0, 25) + # controller.set_water_level only works from version 219 + if FIRMWARE_VERSION >= 219: + await controller.set_water_level(20) + else: + await controller._set_option('o23', 20) + + await program._manual_run() + await asyncio.sleep(1) + await controller.refresh() + assert (controller.stations[0].end_time - controller.stations[0].start_time) == 25 + + await program._manual_run(1) + await asyncio.sleep(1) + await controller.refresh() + assert (controller.stations[0].end_time - controller.stations[0].start_time) == 5 + + await program._manual_run(0) + await asyncio.sleep(1) + await controller.refresh() + assert (controller.stations[0].end_time - controller.stations[0].start_time) == 25 + + @pytest.mark.skipif(FIRMWARE_VERSION <= 216, reason="only for version 217 and above") + @pytest.mark.asyncio + async def test_program_run(self, controller, program): + await program.set_station_duration(0, 25) + # controller.set_water_level only works from version 219 + if FIRMWARE_VERSION >= 219: + await controller.set_water_level(20) + else: + await controller._set_option('o23', 20) + + await program.run() + await asyncio.sleep(1) + await controller.refresh() + assert (controller.stations[0].end_time - controller.stations[0].start_time) == 25 + + await program.run(1) + await asyncio.sleep(1) + await controller.refresh() + assert (controller.stations[0].end_time - controller.stations[0].start_time) == 5 + + await program.run(0) + await asyncio.sleep(1) + await controller.refresh() + assert (controller.stations[0].end_time - controller.stations[0].start_time) == 25 + @pytest.mark.asyncio async def test_program_schedule_type(self, controller, program): assert program.program_schedule_type == 0