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.py 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. from pyheatpump.db import RowClass
  2. from pyheatpump.db import sql
  3. from datetime import date
  4. from pyheatpump.modbus import rtu
  5. from .variable_type import VariableType
  6. from .variable_value import VariableValue
  7. class Variable(RowClass):
  8. address: int = None
  9. unit: str = None
  10. last_update: date = None
  11. type: str = None
  12. def __init__(self, **kwargs):
  13. super().__init__(**kwargs)
  14. @staticmethod
  15. def getall():
  16. return dict([
  17. (row.slabel, Variable.getall_of_type(row))
  18. for _, row in VariableType.getall().items()
  19. ])
  20. @staticmethod
  21. def getall_of_type(type: VariableType) -> dict:
  22. return dict([
  23. (row['address'], Variable(**dict(row)))
  24. for row in sql(
  25. """
  26. SELECT * FROM variable
  27. WHERE type = '{}'
  28. AND address >= {}
  29. AND address <= {}
  30. """.format(type.slabel, type.start_address, type.end_address))
  31. ])
  32. @staticmethod
  33. def getall_values_of_type(type: VariableType) -> dict:
  34. return dict([
  35. (row['address'], row['value'])
  36. for row in sql(
  37. """
  38. SELECT var.address, val.value FROM variable var
  39. LEFT JOIN var_value val ON
  40. var.type = val.type
  41. AND var.address = val.address
  42. AND var.last_update = var.time
  43. WHERE
  44. var.type = '{}'
  45. AND var.address >= {}
  46. AND var.address <= {}
  47. """.format(type.slabel, type.start_address, type.end_address))
  48. ])
  49. def modbus_update(self):
  50. if self.type == 'A':
  51. pass
  52. elif self.type == 'I':
  53. pass
  54. elif self.type == 'D':
  55. pass