Commit be6193cf authored by Ivan Tyagov's avatar Ivan Tyagov

Read previous state from ERP5 backend.

parent a72e0f59
......@@ -40,9 +40,12 @@ class ERP5Handler(asyncua.common.subscription.SubHandler):
if self.url is not None:
return f"%s/%s" %(self.url, ERP5_REQUEST_API)
def call(self, **data):
def call(self, http_method = "POST", **data):
params = urllib.parse.quote_plus(json.dumps({k: str(v) for k, v in data.items()}))
if http_method == "POST":
self.session.post(f"{self.uri}?data={params}")
elif http_method == "GET":
return self.session.get(f"{self.uri}")
def datachange_notification(self, node, val, data):
self.call(node=node, val=val, data=data)
......@@ -72,6 +75,17 @@ async def main():
if xml is not None:
await server.import_xml(xml)
# read previous state as saved in ERP5 backend
erp5_json = erp5_handler.call(http_method="GET").json()
_logger.error(erp5_json)
for k,v in erp5_json.items():
# set
node = server.get_node(k)
_logger.error("Set %s = %s at %s" %(k, v, node))
# XXX: this leads to a change notification which calls ERP5 and endless loop!
#await node.write_value(v)
if erp5_handler:
subscription = await server.create_subscription(1000, erp5_handler)
await subscription.subscribe_events()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment