Initial commit: CODESYS tree, integration docs, Node-RED scripts.
PLC application sources (NVL, rooms, boiler), HA/Node-RED integration guide, and NVL patch utilities. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
40
scripts/nodered_global_nvl_state_patch.py
Normal file
40
scripts/nodered_global_nvl_state_patch.py
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Use global context for nvlInState/nvlClearSeq (shared across Node-RED tabs)."""
|
||||
import json
|
||||
import shutil
|
||||
from datetime import datetime
|
||||
|
||||
path = "/srv/docker-volumes/config/nodered/data/flows.json"
|
||||
backup = path + ".bak-global-nvl-" + datetime.now().strftime("%Y%m%d-%H%M%S")
|
||||
shutil.copy2(path, backup)
|
||||
print("backup:", backup)
|
||||
|
||||
with open(path) as f:
|
||||
flows = json.load(f)
|
||||
|
||||
replacements = [
|
||||
("flow.get('nvlInState')", "global.get('nvlInState')"),
|
||||
('flow.get("nvlInState")', 'global.get("nvlInState")'),
|
||||
("flow.set('nvlInState'", "global.set('nvlInState'"),
|
||||
('flow.set("nvlInState"', 'global.set("nvlInState"'),
|
||||
("flow.get('nvlClearSeq')", "global.get('nvlClearSeq')"),
|
||||
("flow.set('nvlClearSeq'", "global.set('nvlClearSeq'"),
|
||||
]
|
||||
|
||||
count = 0
|
||||
for n in flows:
|
||||
fn = n.get("func")
|
||||
if not fn:
|
||||
continue
|
||||
original = fn
|
||||
for old, new in replacements:
|
||||
fn = fn.replace(old, new)
|
||||
if fn != original:
|
||||
n["func"] = fn
|
||||
count += 1
|
||||
print("patched", n.get("id"), n.get("name"))
|
||||
|
||||
with open(path, "w") as f:
|
||||
json.dump(flows, f)
|
||||
|
||||
print("patched nodes:", count, "done")
|
||||
Reference in New Issue
Block a user