Projet de remplacement du "RPiPasserelle" d'Otec.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_variable_value.py 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env python3
  2. import pytest
  3. from datetime import datetime
  4. from pyheatpump.variable_types import app, get_variable_types, set_variable_types, ROUTES
  5. from pyheatpump.models import *
  6. def test_last_update(set_test_db, var_types):
  7. for _, var_type in var_types.items():
  8. for _, variable in var_type.get_variables().items():
  9. try:
  10. if not variable.last_update:
  11. continue
  12. time = datetime.fromtimestamp(variable.last_update)
  13. val = VariableValue.get(variable.type,
  14. variable.address,
  15. time)
  16. assert val is not None
  17. assert variable.last_update == val.time
  18. except StopIteration:
  19. assert False
  20. def test_var_value_getval(set_test_db, var_types):
  21. var_type = var_types['Analog']
  22. for _, variable in var_type.get_variables().items():
  23. try:
  24. if not variable.last_update:
  25. continue
  26. time = datetime.fromtimestamp(variable.last_update)
  27. value = VariableValue.get(variable.type,
  28. variable.address,
  29. time).get_value()
  30. assert type(value) == float
  31. except StopIteration:
  32. assert False
  33. var_type = var_types['Integer']
  34. for _, variable in var_type.get_variables().items():
  35. try:
  36. if not variable.last_update:
  37. continue
  38. time = datetime.fromtimestamp(variable.last_update)
  39. value = VariableValue.get(variable.type,
  40. variable.address,
  41. time).get_value()
  42. assert type(value) == int
  43. except StopIteration:
  44. assert False
  45. var_type = var_types['Digital']
  46. for _, variable in var_type.get_variables().items():
  47. try:
  48. if not variable.last_update:
  49. continue
  50. time = datetime.fromtimestamp(variable.last_update)
  51. value = VariableValue.get(variable.type,
  52. variable.address,
  53. time).get_value()
  54. assert type(value) == bool
  55. except StopIteration:
  56. assert False