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.

variable_value.py 865B

1234567891011121314151617181920212223242526272829303132
  1. from pyheatpump.db import RowClass
  2. from pyheatpump.db import sql
  3. from datetime import datetime
  4. from pprint import pprint
  5. class VariableValue(RowClass):
  6. type: str = None
  7. address: int = None
  8. time: datetime = None
  9. value: int = None
  10. def __init__(self, **kwargs):
  11. super().__init__(**kwargs)
  12. @staticmethod
  13. def get(type, address, time=datetime.now()):
  14. try:
  15. row = next(sql(
  16. """
  17. SELECT * FROM var_value
  18. WHERE
  19. type = '{}'
  20. AND address = {}
  21. AND time <= {}
  22. ORDER BY time DESC
  23. LIMIT 1
  24. """.format(
  25. type, address, int(time.strftime('%s'))+1)
  26. ))
  27. return VariableValue(**dict(row))
  28. except StopIteration as e:
  29. raise e