updated run_status determination

This commit is contained in:
2020-01-30 17:01:36 -06:00
parent 625081b45e
commit 2970ac9f5a
2 changed files with 38 additions and 7 deletions

View File

@@ -6,6 +6,6 @@
},
"deviceName": "flowmonitor",
"driverId": "0140",
"releaseVersion": "17",
"releaseVersion": "18",
"driverFileName": "flow-monitor.py"
}

View File

@@ -176,10 +176,11 @@ class start(threading.Thread, deviceBase):
self.GPM_IGNORE_LIMIT = 1.0
self.gpm_or_bpd = "gpm"
self.lowflow = 10.00
self.force_send = False
self.daemon = True
self.version = "17"
self.version = "18"
self.finished = threading.Event()
threading.Thread.start(self)
@@ -270,6 +271,14 @@ class start(threading.Thread, deviceBase):
persistence.store(PERSIST)
self.sendtodb("gpmorbpd", self.gpm_or_bpd, 0)
try:
self.lowflow = PERSIST["lowflow"]
except KeyError:
logger.warning("No low flow value in configuratin file. Will add one now")
PERSIST["lowflow"] = self.lowflow
persistence.store(PERSIST)
self.sendtodb("setlowflow", self.lowflow,0)
try:
self.flow_raw_min = PERSIST["flow_raw_min"]
self.flow_raw_max = PERSIST["flow_raw_max"]
@@ -347,8 +356,6 @@ class start(threading.Thread, deviceBase):
din1_val = 1 if mcu_status['din1'] == 'On' else 0 # Check DIGITAL INPUT 1 for run status
scaled_cloop = scale(cloop_val, self.flow_raw_min, self.flow_raw_max, self.flow_gpm_min, self.flow_gpm_max)
psi_val = scale(analog1_val, self.pressure_raw_min, self.pressure_raw_max, self.pressure_psi_min, self.pressure_psi_max)
if din1_val == 0 and scaled_cloop > 10:
din1_val = 1
if self.gpm_or_bpd == "gpm":
@@ -361,6 +368,20 @@ class start(threading.Thread, deviceBase):
if gpm_val < self.GPM_IGNORE_LIMIT:
gpm_val = 0
bpd_val = 0
#Determine run status
runstatus = 0
if din1_val == 0 and gpm_val == 0:
runstatus = 0 #Stopped
elif din1_val == 0 and gpm_val > 10:
runstatus = 1 #Assumed running might not have run indication
elif din1_val == 1 and gpm_val == 0:
runstatus = 3 #no flow warning
elif din1_val == 1 and gpm_val < self.lowflow:
runstatus = 4 #low flow warning
elif din1_val == 1 and gpm_val >= self.lowflow:
runstatus = 1 #running normally
now = time.time()
time_diff = now - last_measured_timestamp
if time_diff > 0 and time_diff < 180:
@@ -431,9 +452,9 @@ class start(threading.Thread, deviceBase):
self.sendtodb(psipressure_ch.meshify_name, psi_val, 0)
psipressure_ch.update(psi_val, now)
if runstatus_ch.check_if_send_needed(din1_val, now) or self.force_send:
self.sendtodb(runstatus_ch.meshify_name, din1_val, 0)
runstatus_ch.update(din1_val, now)
if runstatus_ch.check_if_send_needed(runstatus, now) or self.force_send:
self.sendtodb(runstatus_ch.meshify_name, runstatus, 0)
runstatus_ch.update(runstatus, now)
# Check for the clock hitting midnight for resetting the daily totalizer value
@@ -629,3 +650,13 @@ class start(threading.Thread, deviceBase):
except Exception as e:
logger.error("Error during flowmonitor_setgpmorbpd: {}".format(e))
return False
def flowmonitor_setlowflow(self, name, value):
"""Set the low flow limit"""
try:
self.lowflow = value
self.sendtodb("setlowflow", self.lowflow,0)
return True
except Exception as e:
logger.error("Error during flomonitor_setlowflow: {}".format(e))
return False