code beautifying

This commit is contained in:
2019-07-16 14:27:12 +02:00
parent e297149772
commit 6821364273

View File

@ -6,28 +6,6 @@ import logging
import json
class JsonifyEncoder(json.JSONEncoder):
def default(self, o):
res = None
try:
res = o.jsonify()
except (TypeError, AttributeError):
if type(o) == datetime.timedelta:
res = o.total_seconds()
else:
res = super().default(o)
return res
def datapointObjectHook(j):
if type(j) == dict and 'type' in j and 'args' in j:
klass = eval(j['type'])
o = klass(**j['args'])
return o
else:
return j
class DatapointException(Exception): pass
class AbstractModbusDatapoint(object):
@ -171,6 +149,27 @@ class DiscreteInputDatapoint(ReadOnlyDatapoint):
class JsonifyEncoder(json.JSONEncoder):
def default(self, o):
res = None
try:
res = o.jsonify()
except (TypeError, AttributeError):
if type(o) == datetime.timedelta:
res = o.total_seconds()
else:
res = super().default(o)
return res
def datapointObjectHook(j):
if type(j) == dict and 'type' in j and 'args' in j:
klass = eval(j['type'])
o = klass(**j['args'])
return o
else:
return j
def saveRegisterList(registerList, registerListFile):
js = json.dumps(registerList, cls=JsonifyEncoder, sort_keys=True, indent=4)
with open(registerListFile, 'w') as f: