- 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
27 lines
631 B
TypeScript
27 lines
631 B
TypeScript
// ✅ 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 [];
|
|
}
|
|
};
|