further rework
- dump all every full hour - finish all streams properly on exit
This commit is contained in:
15
secop.py
15
secop.py
@@ -21,7 +21,6 @@ class SecopStream(Stream):
|
||||
|
||||
def init(self):
|
||||
self._buffer = []
|
||||
print('send idn', 'tmo:', self.socket.timeout)
|
||||
self.send('*IDN?')
|
||||
resend = True
|
||||
messages = []
|
||||
@@ -64,14 +63,18 @@ class SecopStream(Stream):
|
||||
def ping(self):
|
||||
self.send('ping')
|
||||
|
||||
def events(self):
|
||||
def get_tags(self, key):
|
||||
return dict(self.tags, device=self.original_id.get(key[0], self.device))
|
||||
|
||||
def event_generator(self):
|
||||
try:
|
||||
cnt = 0
|
||||
for msg in self.get_lines():
|
||||
match = UPDATE.match(msg)
|
||||
if match:
|
||||
cmd, id, data = match.groups()
|
||||
key = tuple(id.split(':'))
|
||||
cmd, ident, data = match.groups()
|
||||
mod, _, param = ident.partition(':')
|
||||
key = (mod, param or 'value')
|
||||
cvt = self.convert.get(key)
|
||||
if cvt:
|
||||
data = json.loads(data)
|
||||
@@ -85,12 +88,10 @@ class SecopStream(Stream):
|
||||
ts = data[1].get('t', time.time())
|
||||
value = cvt(data[0])
|
||||
cnt += 1
|
||||
yield key, value, error, ts, dict(
|
||||
self.tags, device=self.original_id.get(key[0], self.device))
|
||||
yield key, value, error, ts, self.get_tags(key)
|
||||
elif msg == 'active':
|
||||
# from now on, no more waiting
|
||||
self.notimeout()
|
||||
#print('SECOP', self.uri, 'cnt=', cnt)
|
||||
|
||||
except Exception as e:
|
||||
print(self.uri, repr(e))
|
||||
|
||||
Reference in New Issue
Block a user