Exemplo n.º 1
0
 def test_set(self):
     entry = TimeProgEntry(0, TimeProgPeriod(0, 0, 0, 0))
     assert entry.state == 0
     assert entry.period == TimeProgPeriod(0, 0, 0, 0)
     state = 123
     period = TimeProgPeriod(21, 22, 23, 24)
     entry.set(state, period)
     assert entry.state == state
     assert entry.period == period
     assert (entry.period
             is not period)  # entry.period should be a "deepcopy" of period
Exemplo n.º 2
0
 def test_properties(self):
     state = 0
     period = TimeProgPeriod(0, 0, 0, 0)
     entry = TimeProgEntry(state, period)
     assert entry.state == state
     assert entry.period == period
     assert (entry.period
             is not period)  # entry.period should be a "deepcopy" of period
     entry.state = 123
     assert entry.state == 123
     period = TimeProgPeriod(21, 22, 23, 24)
     entry.period = period
     assert entry.period == period
     assert (entry.period
             is not period)  # entry.period should be a "deepcopy" of period
Exemplo n.º 3
0
 def test_set_entry_raises_IndexError(self):
     time_prog = TimeProgram(0, "Name", 10, 3, 15, 7)
     entry = TimeProgEntry(0, TimeProgPeriod(0, 0, 0, 0))
     with pytest.raises(IndexError):
         time_prog.set_entry(time_prog.number_of_days, 0, entry)
     with pytest.raises(IndexError):
         time_prog.set_entry(0, time_prog.entries_a_day, entry)
Exemplo n.º 4
0
 def test_from_json(self, state: int):
     entry = TimeProgEntry.from_json({
         "state": state,
         "start": "00:00",
         "end": "00:00"
     })
     assert entry.state == state
Exemplo n.º 5
0
 def test_entry(self, day: int, num: int):
     time_prog = TimeProgram(0, "Name", 10, 3, 10, 7)
     assert time_prog.entry(day, num) is None
     entry = TimeProgEntry(0, TimeProgPeriod(0, 0, 0, 0))
     time_prog.set_entry(day, num, entry)
     assert time_prog.entry(day, num) == entry
     assert (time_prog.entry(day, num) is not entry
             )  # time_prog.entry() should be a "deepcopy" of entry
Exemplo n.º 6
0
 def test_as_json(self):
     state = 123
     period = TimeProgPeriod(21, 22, 23, 24)
     assert TimeProgEntry(state, period).as_json() == {
         "state": state,
         "start": period.start_str,
         "end": period.end_str,
     }
Exemplo n.º 7
0
 def test_as_dict(self):
     state = 123
     period = TimeProgPeriod(21, 22, 23, 24)
     assert TimeProgEntry(state, period).as_dict() == {
         "state": state,
         "start": period.start,
         "end": period.end,
     }
Exemplo n.º 8
0
 def test_str(self):
     time_prog = TimeProgram(0, "Name", 10, 3, 10, 7)
     assert str(
         time_prog
     ) == "idx={:d}, name={!r}, ead={:d}, nos={:d}, ste={:d}, nod={:d}, entries=[{}]".format(
         0, "Name", 10, 3, 10, 7, "")
     time_prog.set_entry(0, 0, TimeProgEntry(0, TimeProgPeriod(0, 0, 0, 0)))
     assert str(
         time_prog
     ) == "idx={:d}, name={!r}, ead={:d}, nos={:d}, ste={:d}, nod={:d}, entries=[{}]".format(
         0, "Name", 10, 3, 10, 7, "...")
Exemplo n.º 9
0
 def test_set_entry_raises_ValueError(
     self,
     state: int,
     start_hour: int,
     start_minute: int,
     end_hour: int,
     end_minute: int,
 ):
     time_prog = TimeProgram(0, "Name", 10, 3, 15, 7)
     period = TimeProgPeriod(start_hour, start_minute, end_hour, end_minute)
     with pytest.raises(ValueError):
         time_prog.set_entry(0, 0, TimeProgEntry(state, period))
Exemplo n.º 10
0
 def put(self, id: int, day: int, num: int):
     """ Sets a specific time program entry of the heat pump. """
     _LOGGER.info(
         "*** [PUT%s] %s -- id=%d, day=%d, num=%d, payload=%s",
         " (read-only)" if settings.READ_ONLY else "",
         request.url,
         id,
         day,
         num,
         api.payload,
     )
     entry = HtTimeProgEntry.from_json(api.payload)
     with HtContext(ht_heatpump):
         if not settings.READ_ONLY:
             entry = ht_heatpump.set_time_prog_entry(id, day, num, entry)
     res = entry.as_json()
     _LOGGER.debug(
         "*** [PUT%s] %s -> %s",
         " (read-only)" if settings.READ_ONLY else "",
         request.url,
         res,
     )
     return res
Exemplo n.º 11
0
 def test_from_json(self):
     time_prog = TimeProgram.from_json({
         "index": 0,
         "name": "Name",
         "ead": 10,
         "nos": 3,
         "ste": 10,
         "nod": 7
     })
     assert time_prog.index == 0
     assert time_prog.name == "Name"
     assert time_prog.entries_a_day == 10
     assert time_prog.number_of_states == 3
     assert time_prog.step_size == 10
     assert time_prog.number_of_days == 7
     assert len(time_prog._entries) == time_prog.number_of_days
     assert all([
         len(entries_of_day) == time_prog.entries_a_day
         for entries_of_day in time_prog._entries
     ])
     time_prog = TimeProgram.from_json({
         "index":
         0,
         "name":
         "Name",
         "ead":
         10,
         "nos":
         3,
         "ste":
         10,
         "nod":
         7,
         "entries": [[None for _ in range(time_prog.entries_a_day)]
                     for _ in range(time_prog.number_of_days)],
     })
     assert len(time_prog._entries) == time_prog.number_of_days
     assert all([
         len(entries_of_day) == time_prog.entries_a_day
         for entries_of_day in time_prog._entries
     ])
     assert all(
         time_prog.entry(day, num) is None
         for num in range(time_prog.entries_a_day)
         for day in range(time_prog.number_of_days))
     time_prog = TimeProgram.from_json({
         "index":
         0,
         "name":
         "Name",
         "ead":
         10,
         "nos":
         3,
         "ste":
         10,
         "nod":
         7,
         "entries": [[{
             "state": 1,
             "start": "00:00",
             "end": "23:50"
         } for _ in range(time_prog.entries_a_day)]
                     for _ in range(time_prog.number_of_days)],
     })
     assert len(time_prog._entries) == time_prog.number_of_days
     assert all([
         len(entries_of_day) == time_prog.entries_a_day
         for entries_of_day in time_prog._entries
     ])
     assert all(
         time_prog.entry(day, num) == TimeProgEntry(
             1, TimeProgPeriod(0, 0, 23, 50))
         for num in range(time_prog.entries_a_day)
         for day in range(time_prog.number_of_days))
Exemplo n.º 12
0
 def test_eq(self):
     assert TimeProgEntry(0, TimeProgPeriod(0, 0, 0,
                                            0)) != None  # noqa: E711
     with pytest.raises(TypeError):
         TimeProgEntry(0, TimeProgPeriod(0, 0, 0, 0)) != 123
     assert TimeProgEntry(0, TimeProgPeriod(0, 0, 0, 0)) == TimeProgEntry(
         0, TimeProgPeriod(0, 0, 0, 0))
     assert TimeProgEntry(0, TimeProgPeriod(0, 0, 0, 0)) != TimeProgEntry(
         1, TimeProgPeriod(0, 0, 0, 0))
     assert TimeProgEntry(0, TimeProgPeriod(0, 0, 0, 0)) != TimeProgEntry(
         0, TimeProgPeriod(0, 0, 0, 1))
     assert TimeProgEntry(0, TimeProgPeriod(0, 0, 0, 0)) != TimeProgEntry(
         0, TimeProgPeriod(0, 0, 1, 0))
     assert TimeProgEntry(0, TimeProgPeriod(0, 0, 0, 0)) != TimeProgEntry(
         0, TimeProgPeriod(0, 1, 0, 1))
     assert TimeProgEntry(0, TimeProgPeriod(0, 0, 0, 0)) != TimeProgEntry(
         0, TimeProgPeriod(1, 0, 1, 0))
Exemplo n.º 13
0
 def test_str(self, state: int):
     assert str(TimeProgEntry.from_str(
         str(state), "00:00", "00:00")) == "state={:d}, time={!s}".format(
             state, TimeProgPeriod.from_str("00:00", "00:00"))
Exemplo n.º 14
0
 def test_from_str(self, state: int):
     entry = TimeProgEntry.from_str(str(state), "00:00", "00:00")
     assert entry.state == state
Exemplo n.º 15
0
 def test_from_str_raises_ValueError(self, state: str):
     with pytest.raises(ValueError):
         TimeProgEntry.from_str(state, "00:00", "00:00")