Dummy Waage - initial value from last one
This commit is contained in:
@@ -10,7 +10,7 @@ scales:
|
||||
scale_uuid: "46335715-8454-483b-a17b-571619c5015e"
|
||||
interface_type: dummy
|
||||
sms_alert_phonenumbers:
|
||||
- "+41765006124"
|
||||
- "+41765006123"
|
||||
read_scale_interval_sec: 300
|
||||
number_of_samples: 5
|
||||
swarm_alarm_threshold_gram: 500
|
||||
|
||||
+30
-1
@@ -17,6 +17,8 @@ import time
|
||||
import yaml
|
||||
import random
|
||||
import string
|
||||
import glob
|
||||
import re
|
||||
|
||||
# Root Path
|
||||
APP_ROOT = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
||||
@@ -31,6 +33,27 @@ with open("%s/bin/beielimon-config.yaml" % (APP_ROOT), 'r') as stream:
|
||||
# Constants
|
||||
INVALID_VALUE = -999
|
||||
|
||||
# Wegen der Dummy-Waage moechten wir den letzten Messwert holen koennen
|
||||
def GetLastStoredValue(scale_uuid):
|
||||
files = glob.glob("%s/data/weight-%s-????????.log" % (APP_ROOT,scale_uuid))
|
||||
if len(files) > 0:
|
||||
with open(sorted(files)[-1], "r") as f:
|
||||
for line in f: pass
|
||||
result = line
|
||||
|
||||
|
||||
# Beispiel: 2017-11-07 08:23,0
|
||||
m = re.match("(\d{4})-(\d{2})-(\d{2}) (\d\d:\d\d),(\d+)", result)
|
||||
if m:
|
||||
return int("%s" % (m.group(5)))
|
||||
else:
|
||||
return INVALID_VALUE
|
||||
|
||||
else:
|
||||
return INVALID_VALUE
|
||||
|
||||
|
||||
|
||||
class Scale(object):
|
||||
def __init__(self, scale_config):
|
||||
self.last_values = []
|
||||
@@ -110,7 +133,13 @@ class ScaleUSB_PCE(Scale):
|
||||
class ScaleDummy(Scale):
|
||||
def __init__(self,scale_config):
|
||||
Scale.__init__(self, scale_config)
|
||||
self.last_values = [ random.randint(500,1000) ]
|
||||
# Wir versuchen, den letzten Wert wieder zu holen
|
||||
last_value = GetLastStoredValue(self.scale_config['scale_uuid'])
|
||||
if last_value != INVALID_VALUE:
|
||||
self.last_values = [ last_value ]
|
||||
else:
|
||||
self.last_values = [ random.randint(500,1000) ]
|
||||
|
||||
|
||||
def Read(self):
|
||||
# Gewichts- Zu/Abnahme ist Random, manchmal gibt es einen
|
||||
|
||||
Reference in New Issue
Block a user