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

1#!/usr/bin/env python3

2"""RAMSES RF - Test the Schema processor."""

3

4 from typing import Any

5

6 import voluptuous as vol

7

8 from ramses_rf.schemas import (

9 SCH_TCS_DHW,

10 SCH_TCS_ZONES_ZON,

11 SZ_ACTUATORS,

12 SZ_CLASS,

13 SZ_DHW_VALVE,

14 SZ_HTG_VALVE,

15 SZ_SENSOR,

16)

17

18 from .helpers import assert_raises

19

20

21 def test_dhw_schema() -> None:

22 """Test the DHW schema.

23

24 dhw:

25 sensor: 07:777777

26 hotwater_valve: 13:111111

27 heating_valve: 13:222222

28 """

29

30 for dict_ in (

31 SCH_TCS_DHW({}),

32 {SZ_SENSOR: None, SZ_DHW_VALVE: None, SZ_HTG_VALVE: None},

33 ):

34 assert dict_ == {SZ_SENSOR: None, "hotwater_valve": None, "heating_valve": None}

35

36 for key in (SZ_SENSOR, SZ_DHW_VALVE, SZ_HTG_VALVE):

37 assert_raises(vol.error.MultipleInvalid, SCH_TCS_DHW, {key: "99:000000"})

38 assert SCH_TCS_DHW({key: None}) == {

39 SZ_SENSOR: None,

40 SZ_DHW_VALVE: None,

41 SZ_HTG_VALVE: None,

42 }

43

44

45 def test_zone_schema() -> None:

46 """Test the zone schema.

47

48 '01':

49 class: radiator_valve

50 sensor: 22:032844

51 actuators:

52 - 04:111111

53 - 04:222222

54 """

55

56 dict_: dict[str, Any]

57

58 for dict_ in (

59 SCH_TCS_ZONES_ZON({}),

60 {SZ_CLASS: None, SZ_SENSOR: None, SZ_ACTUATORS: []},

61 ):

62 assert dict_ == {SZ_CLASS: None, SZ_SENSOR: None, SZ_ACTUATORS: []}

63

64 for key in (SZ_CLASS, SZ_SENSOR):

65 assert_raises(vol.error.MultipleInvalid, SCH_TCS_ZONES_ZON, {key: "99:000000"})

66 assert SCH_TCS_ZONES_ZON({key: None}) == {

67 SZ_CLASS: None,

68 SZ_SENSOR: None,

69 SZ_ACTUATORS: [],

70 }

71

72 assert SCH_TCS_ZONES_ZON({SZ_CLASS: "radiator_valve"}) == {

73 SZ_CLASS: "radiator_valve",

74 SZ_SENSOR: None,

75 SZ_ACTUATORS: [],

76 }

77

78 assert SCH_TCS_ZONES_ZON({SZ_SENSOR: "34:111111"}) == {

79 SZ_CLASS: None,

80 SZ_ACTUATORS: [],

81 SZ_SENSOR: "34:111111",

82 }

83

84 for val in (

85 None,

86 "_invalid_",

87 "13:111111",

88 ): # NOTE: should be a *list* of device_ids

89 assert_raises(vol.error.MultipleInvalid, SCH_TCS_ZONES_ZON, {SZ_ACTUATORS: val})

90

91 for xxx in ([], ["13:111111"], ["13:222222", "13:111111"]):

92 assert SCH_TCS_ZONES_ZON({SZ_ACTUATORS: xxx}) == {

93 SZ_CLASS: None,

94 SZ_ACTUATORS: xxx,

95 SZ_SENSOR: None,

96 }