115 lines
4.0 KiB
Python
115 lines
4.0 KiB
Python
#!/usr/bin/env python3
|
|
import json
|
|
|
|
with open('/home/mdares/.node-red/flows.json', 'r') as f:
|
|
flows = json.load(f)
|
|
|
|
print("FIXING START BUTTON - HOLISTIC APPROACH")
|
|
print("="*60)
|
|
|
|
# ============================================================================
|
|
# FIX 1: Wire Cavities Settings output to Settings Template
|
|
# ============================================================================
|
|
|
|
# Find Cavities Settings function
|
|
cavities_node = None
|
|
settings_template_id = 'f5a6b7c8d9e0f1a2'
|
|
|
|
for node in flows:
|
|
if node.get('name') == 'Cavities Settings' and node.get('type') == 'function':
|
|
cavities_node = node
|
|
break
|
|
|
|
if cavities_node:
|
|
# Wire output to Settings Template
|
|
if not cavities_node.get('wires'):
|
|
cavities_node['wires'] = [[]]
|
|
|
|
if settings_template_id not in cavities_node['wires'][0]:
|
|
cavities_node['wires'][0].append(settings_template_id)
|
|
print("✅ FIX 1: Wired Cavities Settings → Settings Template")
|
|
else:
|
|
print("✅ FIX 1: Already wired (no change needed)")
|
|
else:
|
|
print("❌ ERROR: Cavities Settings node not found")
|
|
|
|
# ============================================================================
|
|
# FIX 2: Remove Mold Presets Handler from link in 1 (it doesn't need selectMoldPreset)
|
|
# ============================================================================
|
|
|
|
# Find link in 1
|
|
link_in_1 = None
|
|
mold_presets_handler_id = None
|
|
|
|
for node in flows:
|
|
if node.get('type') == 'link in' and 'link in 1' in node.get('name', ''):
|
|
link_in_1 = node
|
|
if node.get('name') == 'Mold Presets Handler':
|
|
mold_presets_handler_id = node.get('id')
|
|
|
|
if link_in_1 and mold_presets_handler_id:
|
|
wires = link_in_1.get('wires', [[]])[0]
|
|
if mold_presets_handler_id in wires:
|
|
wires.remove(mold_presets_handler_id)
|
|
link_in_1['wires'] = [wires]
|
|
print("✅ FIX 2: Removed Mold Presets Handler from link in 1")
|
|
print(" (Eliminates 'Unknown topic: selectMoldPreset' warnings)")
|
|
else:
|
|
print("✅ FIX 2: Already removed (no change needed)")
|
|
else:
|
|
print("⚠️ FIX 2: Could not apply (nodes not found)")
|
|
|
|
# ============================================================================
|
|
# FIX 3: Ensure Back to UI properly sends activeWorkOrder to Home
|
|
# ============================================================================
|
|
|
|
# Check if link out 4 connects to link in 4 which connects to Home
|
|
back_to_ui_node = None
|
|
for node in flows:
|
|
if node.get('name') == 'Back to UI':
|
|
back_to_ui_node = node
|
|
break
|
|
|
|
if back_to_ui_node:
|
|
# Back to UI has 2 outputs (or 3?)
|
|
# Output 2 should go to link out 4
|
|
wires = back_to_ui_node.get('wires', [])
|
|
print(f"\n✅ FIX 3: Back to UI has {len(wires)} outputs")
|
|
|
|
if len(wires) >= 2:
|
|
output_2 = wires[1]
|
|
print(f" Output 2 wires to: {len(output_2)} nodes")
|
|
|
|
# Find link out 4
|
|
for target_id in output_2:
|
|
for node in flows:
|
|
if node.get('id') == target_id:
|
|
print(f" - {node.get('name', 'unnamed')} (Type: {node.get('type')})")
|
|
break
|
|
else:
|
|
print(" ⚠️ WARNING: Back to UI doesn't have enough outputs!")
|
|
else:
|
|
print("❌ ERROR: Back to UI node not found")
|
|
|
|
# Write updated flows
|
|
with open('/home/mdares/.node-red/flows.json', 'w') as f:
|
|
json.dump(flows, f, indent=4)
|
|
|
|
print("\n" + "="*60)
|
|
print("✅ FIXES APPLIED")
|
|
print("="*60)
|
|
print("\nWhat was fixed:")
|
|
print(" 1. Cavities Settings now sends moldPresetSelected to Settings UI")
|
|
print(" 2. Removed duplicate routing to Mold Presets Handler")
|
|
print(" 3. Verified Back to UI → Home Template path")
|
|
print("\nIMPACT CHECK:")
|
|
print(" ✅ Mold selection will now update UI fields")
|
|
print(" ✅ No more 'Unknown topic' warnings")
|
|
print(" ✅ Backwards compatibility maintained")
|
|
print("\nNEXT STEPS:")
|
|
print(" 1. Restart Node-RED")
|
|
print(" 2. Select WO from WO list")
|
|
print(" 3. Select mold from Settings")
|
|
print(" 4. Check if START button enables")
|
|
print(" 5. If still gray, check debug log for activeWorkOrder messages")
|