Files
EVCS/decoupesurplus/V2/gridhystact.js

87 lines
1.5 KiB
JavaScript

const root = $input.first().json;
const actions = [];
// Toujours mettre à jour état + raison
actions.push({
json: {
action: 'helper_state',
...root.ha_service_calls.helper_state
}
});
actions.push({
json: {
action: 'helper_reason',
...root.ha_service_calls.helper_reason
}
});
// Action réseau si nécessaire
if (root.decision.grid_action !== 'none') {
actions.push({
json: {
action: 'grid',
...root.ha_service_calls.grid
}
});
}
// Action latch si nécessaire
if (root.decision.latch_action !== 'none') {
actions.push({
json: {
action: 'helper_latch',
...root.ha_service_calls.helper_latch
}
});
}
// Timestamps si nécessaire
if (root.decision.set_last_on_at) {
actions.push({
json: {
action: 'helper_last_on_at',
...root.ha_service_calls.helper_last_on_at
}
});
}
if (root.decision.set_last_off_at) {
actions.push({
json: {
action: 'helper_last_off_at',
...root.ha_service_calls.helper_last_off_at
}
});
}
// Signature + logbook si changement
if (root.decision.signature_changed) {
actions.push({
json: {
action: 'helper_signature',
...root.ha_service_calls.helper_signature
}
});
actions.push({
json: {
action: 'logbook',
...root.ha_service_calls.logbook
}
});
}
// Notification si utile
if (root.decision.should_notify) {
actions.push({
json: {
action: 'mobile_notification',
...root.ha_service_calls.mobile_notification
}
});
}
return actions;