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_type.py 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from pyheatpump.db import RowClass
  2. from pyheatpump.db import sql
  3. class VariableType(RowClass):
  4. slabel: str = None
  5. label: str = None
  6. type: str = None
  7. start_address: int = None
  8. end_address: int = None
  9. def __init__(self, **kwargs):
  10. super().__init__(**kwargs)
  11. if self.slabel is None and self.label is not None:
  12. self.slabel = self.label[0]
  13. def select():
  14. try:
  15. elt = next(super().select('slabel', 'var_type'))
  16. except StopIteration:
  17. print('No element exists')
  18. def save(self):
  19. q = ['UPDATE var_type SET']
  20. updates = []
  21. if self.start_address is not None:
  22. updates.append(f'start_address = {self.start_address}')
  23. if self.end_address is not None:
  24. updates.append(f'end_address = {self.end_address}')
  25. if len(updates) == 0:
  26. return
  27. q.append(','.join(updates))
  28. q.append(f"WHERE slabel LIKE '{self.slabel}'")
  29. return sql(' '.join(q))
  30. @staticmethod
  31. def getall():
  32. return dict([
  33. (row['label'], VariableType(**dict(row)))
  34. for row in sql('SELECT * FROM var_type') ])