Добавил еще одно устройство в проект: HART модем, получающий накопленный расход от расходометра.
This commit is contained in:
@@ -181,3 +181,27 @@ class MbPumpService(MbService):
|
||||
'half_auto_control': None
|
||||
}
|
||||
|
||||
|
||||
class MbHartService(MbService):
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self._lock = Lock()
|
||||
self._curr_state = None
|
||||
|
||||
def _load_current_state(self):
|
||||
# D?: flow_meter
|
||||
values = self.mb.read_holding_registers(600, 1)
|
||||
if values is None:
|
||||
raise AssertionError('failed to load current state')
|
||||
with self._lock:
|
||||
self._curr_state = {
|
||||
'accumulated_flow': values[0]
|
||||
}
|
||||
|
||||
def get_stats(self):
|
||||
with self._lock:
|
||||
# копируем данные, если они есть в текущем состоянии (иначе пустые поля)
|
||||
return self._curr_state or {
|
||||
'accumulated_flow': None
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user