Files
EVCS/build.js
2026-04-12 03:01:51 +02:00

100 lines
2.8 KiB
JavaScript

const root = $input.first().json || {};
const decision = root.decision || {};
const calls = root.ha_service_calls || {};
const actions = [];
function pushAction(action, call) {
if (!call) return;
actions.push({
json: {
action,
...call
}
});
}
// Helpers toujours mis à jour
pushAction('helper_state', calls.helper_state);
pushAction('helper_current_decision', calls.helper_current_decision);
pushAction('helper_reason', calls.helper_reason);
pushAction('helper_operating_mode', calls.helper_operating_mode);
pushAction('helper_target_current', calls.helper_target_current);
pushAction('helper_budget_remaining', calls.helper_budget_remaining);
pushAction('helper_projected_soc', calls.helper_projected_soc);
pushAction('helper_cloud_debt', calls.helper_cloud_debt);
pushAction('helper_dynamic_ok', calls.helper_dynamic_ok);
pushAction('helper_must_stop', calls.helper_must_stop);
// Helpers V1.4 additionnels
if (decision.set_cloud_debt_started_at) {
pushAction('helper_cloud_debt_started_at', calls.helper_cloud_debt_started_at);
}
if (decision.set_block_reason) {
pushAction('helper_block_reason', calls.helper_block_reason);
}
if (decision.set_blocked_until) {
pushAction('helper_blocked_until', calls.helper_blocked_until);
}
if (decision.set_probe_started_at) {
pushAction('helper_probe_started_at', calls.helper_probe_started_at);
}
// Forcer Auto Start OFF si besoin
if (decision.auto_start_action !== 'none') {
pushAction('evcs_auto_start_off', calls.evcs_auto_start_off);
}
// Si on arrête : charging OFF d'abord
if (decision.charging_action === 'turn_off') {
pushAction('evcs_charging', calls.evcs_charging);
}
// Permission / latch
if (decision.permission_action !== 'none') {
pushAction('helper_permission', calls.helper_permission);
}
if (decision.latch_action !== 'none') {
pushAction('helper_latch', calls.helper_latch);
}
// Courant si nécessaire
if (decision.current_action === 'set') {
pushAction('evcs_set_current', calls.evcs_set_current);
if (decision.set_last_current_change_at) {
pushAction('helper_last_current_change_at', calls.helper_last_current_change_at);
}
}
// Si on démarre : charging ON à la fin
if (decision.charging_action === 'turn_on') {
pushAction('evcs_charging', calls.evcs_charging);
}
// Timestamps start / stop
if (decision.set_last_start_at) {
pushAction('helper_last_start_at', calls.helper_last_start_at);
}
if (decision.set_last_stop_at) {
pushAction('helper_last_stop_at', calls.helper_last_stop_at);
}
// Signature + logbook si changement
if (decision.signature_changed) {
pushAction('helper_signature', calls.helper_signature);
pushAction('logbook', calls.logbook);
}
// Notifications
if (decision.should_notify) {
pushAction('mobile_notification', calls.mobile_notification);
}
return actions;