Files
codesys-home-automation/scripts/nodered_global_nvl_state_patch.py
nearxos d98c44bfa3 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>
2026-05-26 21:21:56 +03:00

41 lines
1.1 KiB
Python

#!/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")