Coverage for tests/tests/test_api_schedule.py: 0%

41 statements  

« prev     ^ index     » next       coverage.py v7.11.3, created at 2026-01-05 21:46 +0100

1#!/usr/bin/env python3 

2"""RAMSES RF - Test the Schedule functions.""" 

3 

4import json 

5from copy import deepcopy 

6from pathlib import Path, PurePath 

7 

8import pytest 

9 

10from ramses_rf import Gateway 

11from ramses_rf.const import SZ_SCHEDULE, SZ_ZONE_IDX 

12from ramses_rf.system import Evohome 

13from ramses_rf.system.schedule import ( 

14 SCH_SCHEDULE_DHW_OUTER, 

15 SCH_SCHEDULE_ZON_OUTER, 

16 SZ_ENABLED, 

17 SZ_HEAT_SETPOINT, 

18 SZ_SWITCHPOINTS, 

19 fragz_to_full_sched, 

20 full_sched_to_fragz, 

21) 

22from ramses_rf.system.zones import ZoneSchedule 

23 

24from .helpers import TEST_DIR, load_test_gwy 

25 

26WORK_DIR = f"{TEST_DIR}/schedules" 

27 

28 

29def pytest_generate_tests(metafunc: pytest.Metafunc) -> None: 

30 def id_fnc(param: Path) -> str: 

31 return PurePath(param).name 

32 

33 folders = [f for f in Path(WORK_DIR).iterdir() if f.is_dir() and f.name[:1] != "_"] 

34 metafunc.parametrize("dir_name", folders, ids=id_fnc) 

35 

36 

37async def test_schedule_get(dir_name: Path) -> None: 

38 """Compare the schedule built from a log file with the expected results.""" 

39 

40 with open(f"{dir_name}/schedule.json") as f: 

41 schedule = json.load(f) 

42 

43 gwy: Gateway = await load_test_gwy(dir_name) 

44 assert isinstance(gwy.tcs, Evohome) # mypy 

45 try: 

46 zone: ZoneSchedule = gwy.tcs.dhw if gwy.tcs.dhw else gwy.tcs.zones[0] 

47 assert isinstance(zone, ZoneSchedule) 

48 assert zone.schedule == schedule[SZ_SCHEDULE] 

49 assert zone._schedule._full_schedule == schedule 

50 

51 finally: 

52 await gwy.stop() 

53 

54 

55async def test_schedule_helpers(dir_name: Path) -> None: 

56 """Compare the schedule helpers are consistent and have symmetry.""" 

57 

58 with open(f"{dir_name}/schedule.json") as f: 

59 schedule = json.load(f) 

60 

61 new_schedule = deepcopy(schedule) 

62 

63 if schedule[SZ_ZONE_IDX] == "HW": 

64 SCH_SCHEDULE_DHW_OUTER(schedule) 

65 schedule[SZ_ZONE_IDX] = "00" 

66 else: 

67 SCH_SCHEDULE_ZON_OUTER(schedule) 

68 

69 assert schedule == fragz_to_full_sched(full_sched_to_fragz(schedule)) 

70 

71 if new_schedule[SZ_ZONE_IDX] == "HW": 

72 new_schedule[SZ_ZONE_IDX] = "00" 

73 new_schedule[SZ_SCHEDULE][-1][SZ_SWITCHPOINTS][-1][SZ_ENABLED] = not ( 

74 schedule[SZ_SCHEDULE][-1][SZ_SWITCHPOINTS][-1][SZ_ENABLED] 

75 ) 

76 else: 

77 new_schedule[SZ_SCHEDULE][-1][SZ_SWITCHPOINTS][-1][SZ_HEAT_SETPOINT] = ( 

78 schedule[SZ_SCHEDULE][-1][SZ_SWITCHPOINTS][-1][SZ_HEAT_SETPOINT] + 1 

79 ) 

80 

81 # the schedule code relies upon the following inequality... 

82 # i.e. if the schedule has changed, then the first fragment will be different 

83 assert full_sched_to_fragz(new_schedule)[0] != (full_sched_to_fragz(schedule)[0])