123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- from pyheatpump.db import RowClass
- from pyheatpump.db import sql
- from datetime import date
- from pyheatpump.modbus import rtu
-
- from .variable_type import VariableType
- from .variable_value import VariableValue
-
- class Variable(RowClass):
- address: int = None
- unit: str = None
- last_update: date = None
- type: str = None
-
- def __init__(self, **kwargs):
- super().__init__(**kwargs)
-
-
- @staticmethod
- def getall():
- return dict([
- (row.slabel, Variable.getall_of_type(row))
- for _, row in VariableType.getall().items()
- ])
-
-
- @staticmethod
- def getall_of_type(type: VariableType) -> dict:
- return dict([
- (row['address'], Variable(**dict(row)))
- for row in sql(
- """
- SELECT * FROM variable
- WHERE type = '{}'
- AND address >= {}
- AND address <= {}
- """.format(type.slabel, type.start_address, type.end_address))
- ])
-
-
- @staticmethod
- def getall_values_of_type(type: VariableType) -> dict:
- return dict([
- (row['address'], row['value'])
- for row in sql(
- """
- SELECT var.address, val.value FROM variable var
- LEFT JOIN var_value val ON
- var.type = val.type
- AND var.address = val.address
- AND var.last_update = var.time
- WHERE
- var.type = '{}'
- AND var.address >= {}
- AND var.address <= {}
- """.format(type.slabel, type.start_address, type.end_address))
- ])
-
-
- def modbus_update(self):
- if self.type == 'A':
- pass
- elif self.type == 'I':
- pass
- elif self.type == 'D':
- pass
|