Files
EVCS/tools/patch-20261008-advisor-relecteur.mjs

17 lines
1.1 KiB
JavaScript

#!/usr/bin/env node
// 08/10/2026 (proprietaire) : le conseiller devient RELECTEUR de la journee. Son
// noeud d'ecriture doit pouvoir publier un capteur avec attributs
// (sensor.evcs_advisor_revue) : un item `state_entity` part vers /api/states,
// les autres vers /api/services comme avant. Rejouable (idempotent).
import fs from 'fs';
const F = 'workflows/evcs-advisor-shadow-v1.json';
const wf = JSON.parse(fs.readFileSync(F, 'utf8'));
const n = wf.nodes.find((x) => x.name === 'Execute HA Service Advisor');
const ancien = "={{ 'http://10.10.10.17:8123/api/services/' + $json.domain + '/' + $json.service }}";
const nouveau = "={{ $json.state_entity ? 'http://10.10.10.17:8123/api/states/' + $json.state_entity : 'http://10.10.10.17:8123/api/services/' + $json.domain + '/' + $json.service }}";
if (n.parameters.url === nouveau) { console.log('deja applique'); process.exit(0); }
if (n.parameters.url !== ancien) throw new Error('url inattendue : ' + n.parameters.url);
n.parameters.url = nouveau;
fs.writeFileSync(F, JSON.stringify(wf, null, 2) + '\n');
console.log('patch applique');