#!/usr/bin/env python3 import pytest from datetime import datetime from pyheatpump.variable_types import app, get_variable_types, set_variable_types, ROUTES from pyheatpump.models import * def test_last_update(set_test_db, var_types): for _, var_type in var_types.items(): for _, variable in var_type.get_variables().items(): try: if not variable.last_update: continue time = datetime.fromtimestamp(variable.last_update) val = VariableValue.get(variable.type, variable.address, time) assert val is not None assert variable.last_update == val.time except StopIteration: assert False def test_var_value_getval(set_test_db, var_types): var_type = var_types['Analog'] for _, variable in var_type.get_variables().items(): try: if not variable.last_update: continue time = datetime.fromtimestamp(variable.last_update) value = VariableValue.get(variable.type, variable.address, time).get_value() assert type(value) == float except StopIteration: assert False var_type = var_types['Integer'] for _, variable in var_type.get_variables().items(): try: if not variable.last_update: continue time = datetime.fromtimestamp(variable.last_update) value = VariableValue.get(variable.type, variable.address, time).get_value() assert type(value) == int except StopIteration: assert False var_type = var_types['Digital'] for _, variable in var_type.get_variables().items(): try: if not variable.last_update: continue time = datetime.fromtimestamp(variable.last_update) value = VariableValue.get(variable.type, variable.address, time).get_value() assert type(value) == bool except StopIteration: assert False