Skip to content

Commit

Permalink
Add support to use weather adjustment when running a program
Browse files Browse the repository at this point in the history
  • Loading branch information
booysenn committed Sep 3, 2023
1 parent 2dbc5dd commit f1458e8
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
10 changes: 6 additions & 4 deletions pyopensprinkler/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}

Check warning on line 44 in pyopensprinkler/program.py

View check run for this annotation

Codecov / codecov/patch

pyopensprinkler/program.py#L42-L44

Added lines #L42 - L44 were not covered by tests
content = await self._controller.request("/mp", params)
return content["result"]

Expand Down Expand Up @@ -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)

Check warning on line 79 in pyopensprinkler/program.py

View check run for this annotation

Codecov / codecov/patch

pyopensprinkler/program.py#L79

Added line #L79 was not covered by tests

async def set_name(self, name):
dlist = self._get_program_data().copy()
Expand Down
54 changes: 53 additions & 1 deletion tests/test_program.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest
import asyncio

import pytest
from const import FIRMWARE_VERSION

@pytest.fixture
async def program(controller):
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f1458e8

Please sign in to comment.