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 authored and root committed Sep 19, 2024
1 parent 3963fe5 commit 8a59531
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pyopensprinkler/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,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"]

Expand Down Expand Up @@ -152,9 +154,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()
Expand Down
69 changes: 69 additions & 0 deletions tests/test_program.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import asyncio

import pytest
from const import FIRMWARE_VERSION


@pytest.fixture
Expand Down Expand Up @@ -32,6 +35,72 @@ 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 8a59531

Please sign in to comment.