refactor: digitale Ausgänge über eigenen Service und Redux Thunk laden

- neue Datei fetchDigitalOutputs.ts liest win_da_state und win_da_bezeichnung aus window
- fetchDigitalOutputsThunk.ts verwendet den Service und befüllt Redux Slice
- entfernt alte Logik aus loadWindowVariables.ts
- verbessert Performance und Struktur, lädt Ausgänge nur bei Bedarf
This commit is contained in:
ISA
2025-03-26 12:11:59 +01:00
parent 8a4764a372
commit db67ba0709
5 changed files with 50 additions and 70 deletions

View File

@@ -0,0 +1,26 @@
// ✅ Service: /services/fetchDigitalOutputs.ts
export const fetchDigitalOutputs = async () => {
const win = window as any;
const state = win.win_da_state;
const labels = win.win_da_bezeichnung;
if (
Array.isArray(state) &&
Array.isArray(labels) &&
state.length === labels.length
) {
return state.map((status: number, index: number) => ({
id: index + 1,
label: labels[index] || `Ausgang ${index + 1}`,
status: status === 1,
}));
} else {
console.warn("⚠️ Digitale Ausgänge unvollständig oder inkonsistent:", {
state,
labels,
});
return [];
}
};