123456789101112131415161718192021222324252627282930313233343536373839404142 |
- from pyheatpump.db import RowClass
- from pyheatpump.db import sql
-
- class VariableType(RowClass):
- slabel: str = None
- label: str = None
- type: str = None
- start_address: int = None
- end_address: int = None
-
- def __init__(self, **kwargs):
- super().__init__(**kwargs)
-
- if self.slabel is None and self.label is not None:
- self.slabel = self.label[0]
-
-
- def select():
- try:
- elt = next(super().select('slabel', 'var_type'))
- except StopIteration:
- print('No element exists')
-
- def save(self):
- q = ['UPDATE var_type SET']
- updates = []
- if self.start_address is not None:
- updates.append(f'start_address = {self.start_address}')
- if self.end_address is not None:
- updates.append(f'end_address = {self.end_address}')
- if len(updates) == 0:
- return
- q.append(','.join(updates))
- q.append(f"WHERE slabel LIKE '{self.slabel}'")
-
- return sql(' '.join(q))
-
- @staticmethod
- def getall():
- return dict([
- (row['label'], VariableType(**dict(row)))
- for row in sql('SELECT * FROM var_type') ])
|