Skip to content

Commit

Permalink
V1.19.02
Browse files Browse the repository at this point in the history
  • Loading branch information
jgyates committed Apr 3, 2024
1 parent bd47a7a commit f849906
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
39 changes: 33 additions & 6 deletions addon/genmopeka.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,16 @@ def ConvertTankReading(self, reading_mm):

if reading_mm > self.max_mm:
reading_mm = self.max_mm
reading_inches = self.MmToInches(reading_mm)
tanksize = self.max_mm - self.min_mm
return round(((reading_mm - self.min_mm) / tanksize) * 100, 2)

gallons_left = self.CubicInToGallons(self.Tank.V_from_h(reading_inches))
try:
cubic_inches = self.Tank.V_from_h(reading_inches)
except Exception as e1:
self.LogError("Error in fluids geometry: " + str(e1))
self.LogDebug("max mm:" + str(self.max_mm) + " reading mm: " + reading_mm)
return None
gallons_left = self.CubicInToGallons(cubic_inches)
self.LogDebug("Gallons Left: " + str(gallons_left))
if gallons_left >= self.TankVolume:
percent = 100
Expand All @@ -561,6 +567,8 @@ def ConvertTankReading(self, reading_mm):
def TankCheckThread(self):

time.sleep(1)

LastTankReading = [None,None,None,None]

while True:
try:
Expand All @@ -583,32 +591,51 @@ def TankCheckThread(self):
if reading != None:
self.LogDebug("Tank1 = " + str(reading))
dataforgenmon["Percentage"] = reading
LastTankReading[0] = reading
else:
dataforgenmon["Percentage"] = 0
# if we get an error, but have a last valid reading, use hte last valid reading,
# otherwise it is zero as there is no sensor because we never got a good reading
if LastTankReading[0] == None:
dataforgenmon["Percentage"] = 0
else:
dataforgenmon["Percentage"] = LastTankReading[0]

if len(self.bd_tank_address) >= 2:
reading = self.GetTankReading(self.bd_tank_address[1])
if reading != None:
self.LogDebug("Tank2 = " + str(reading))
dataforgenmon["Percentage2"] = reading
LastTankReading[1] = reading
else:
dataforgenmon["Percentage2"] = 0
if LastTankReading[1] == None:
dataforgenmon["Percentage2"] = 0
else:
dataforgenmon["Percentage2"] = LastTankReading[1]


if len(self.bd_tank_address) >= 3:
reading = self.GetTankReading(self.bd_tank_address[2])
if reading != None:
self.LogDebug("Tank3 = " + str(reading))
dataforgenmon["Percentage3"] = reading
LastTankReading[2] = reading
else:
dataforgenmon["Percentage3"] = 0
if LastTankReading[2] == None:
dataforgenmon["Percentage3"] = 0
else:
dataforgenmon["Percentage3"] = LastTankReading[2]

if len(self.bd_tank_address) >= 4:
reading = self.GetTankReading(self.bd_tank_address[3])
if reading != None:
self.LogDebug("Tank4 = " + str(reading))
dataforgenmon["Percentage4"] = reading
LastTankReading[3] = reading
else:
dataforgenmon["Percentage4"] = 0
if LastTankReading[3] == None:
dataforgenmon["Percentage4"] = 0
else:
dataforgenmon["Percentage4"] = LastTankReading[3]

if len(dataforgenmon) != 0:
dataforgenmon["Tank Name"] = "Mopeka Sensor Tank"
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ All notable changes to this project will be documented in this file.
- Minor update for better error reporting with email failures
- Corrected issue with login page errors in developer console
- Update to mymail.py to support optional HTML format of outbound email
- Update to genmopeka.py add on to ignore invalid readings from mopeka sensor.

## V1.19.01 -2023-12-06
- Update to genmonmaint.sh to ask about serial connection type on install (thanks @skipfire)
Expand Down

0 comments on commit f849906

Please sign in to comment.