def test_get_fault_list(self, hthp: HtHeatpump): fault_list = hthp.get_fault_list() # [ { "index": 29, # fault list index # "error": 20, # error code # "datetime": datetime.datetime(...), # date and time of the entry # "message": "EQ_Spreizung", # error message # }, # # ... # ] assert isinstance(fault_list, list), "'fault_list' must be of type list" assert len(fault_list) == hthp.get_fault_list_size() for entry in fault_list: assert isinstance(entry, dict), "'entry' must be of type dict" index = entry["index"] assert isinstance(index, int), "'index' must be of type int" assert 0 <= index < hthp.get_fault_list_size() error = entry["error"] assert isinstance(error, int), "'error' must be of type int" assert error >= 0 dt = entry["datetime"] assert isinstance( dt, datetime.datetime), "'dt' must be of type datetime" msg = entry["message"] assert isinstance(msg, str), "'msg' must be of type str"
def test_get_fault_list_in_several_pieces(self, hthp: HtHeatpump): args = [] cmd = "" fault_list_size = hthp.get_fault_list_size() while len(cmd) < 255 * 2: # request has do be done in 3 parts item = random.randint(0, fault_list_size - 1) cmd += ",{}".format(item) args.append(item) fault_list = hthp.get_fault_list(*args) # [ { "index": 29, # fault list index # "error": 20, # error code # "datetime": datetime.datetime(...), # date and time of the entry # "message": "EQ_Spreizung", # error message # }, # # ... # ] assert isinstance(fault_list, list), "'fault_list' must be of type list" assert len(fault_list) == len(args) for entry in fault_list: assert isinstance(entry, dict), "'entry' must be of type dict" index = entry["index"] assert isinstance(index, int), "'index' must be of type int" assert 0 <= index < fault_list_size error = entry["error"] assert isinstance(error, int), "'error' must be of type int" assert error >= 0 dt = entry["datetime"] assert isinstance( dt, datetime.datetime), "'dt' must be of type datetime" msg = entry["message"] assert isinstance(msg, str), "'msg' must be of type str"
def test_get_fault_list_with_indices(self, hthp: HtHeatpump): size = hthp.get_fault_list_size() for cnt in range(size + 1): indices = random.sample(range(size), cnt) fault_list = hthp.get_fault_list(*indices) assert isinstance(fault_list, list), "'fault_list' must be of type list" assert len(fault_list) == (cnt if cnt > 0 else size) for entry in fault_list: assert isinstance(entry, dict), "'entry' must be of type dict" index = entry["index"] assert isinstance(index, int), "'index' must be of type int" assert 0 <= index < hthp.get_fault_list_size() error = entry["error"] assert isinstance(error, int), "'error' must be of type int" assert error >= 0 dt = entry["datetime"] assert isinstance( dt, datetime.datetime), "'dt' must be of type datetime" msg = entry["message"] assert isinstance(msg, str), "'msg' must be of type str"
def test_get_fault_list_with_index(self, hthp: HtHeatpump): size = hthp.get_fault_list_size() assert isinstance(size, int), "'size' must be of type int" assert size >= 0 for i in range(size): fault_list = hthp.get_fault_list(i) assert isinstance(fault_list, list), "'fault_list' must be of type list" assert len(fault_list) == 1 entry = fault_list[0] assert isinstance(entry, dict), "'entry' must be of type dict" index = entry["index"] assert isinstance(index, int), "'index' must be of type int" assert 0 <= index < hthp.get_fault_list_size() error = entry["error"] assert isinstance(error, int), "'error' must be of type int" assert error >= 0 dt = entry["datetime"] assert isinstance( dt, datetime.datetime), "'dt' must be of type datetime" msg = entry["message"] assert isinstance(msg, str), "'msg' must be of type str"
def test_get_last_fault(self, hthp: HtHeatpump): fault = hthp.get_last_fault() # (29, 20, datetime.datetime(...), "EQ_Spreizung") assert isinstance(fault, tuple), "'fault' must be of type tuple" assert len(fault) == 4 index, error, dt, msg = fault assert isinstance(index, int), "'index' must be of type int" assert 0 <= index < hthp.get_fault_list_size() assert isinstance(error, int), "'error' must be of type int" assert error >= 0 assert isinstance(dt, datetime.datetime), "'dt' must be of type datetime" assert isinstance(msg, str), "'msg' must be of type str"
def test_get_fault_list_with_index_raises_IOError(self, hthp: HtHeatpump): with pytest.raises(IOError): hthp.get_fault_list(-1) with pytest.raises(IOError): hthp.get_fault_list(hthp.get_fault_list_size())
def test_get_fault_list_size(self, hthp: HtHeatpump): size = hthp.get_fault_list_size() assert isinstance(size, int), "'size' must be of type int" assert size >= 0