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:
26
services/fetchDigitalOutputs.ts
Normal file
26
services/fetchDigitalOutputs.ts
Normal 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 [];
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user