From e3e096248437a5afebd0e41c2dbe292a3bb1436b Mon Sep 17 00:00:00 2001 From: Sonja Happ Date: Tue, 2 Jun 2020 14:51:38 +0200 Subject: [PATCH] lamp widget able to use output signals, switching of color works #218 --- src/widget/widgets/lamp.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/widget/widgets/lamp.js b/src/widget/widgets/lamp.js index 7a89c04..939caed 100644 --- a/src/widget/widgets/lamp.js +++ b/src/widget/widgets/lamp.js @@ -25,7 +25,6 @@ class WidgetLamp extends Component { this.state = { value: '', - threshold: 0 }; } @@ -34,28 +33,31 @@ class WidgetLamp extends Component { return{ value: ''}; } - const ic = props.icIDs[0]; + // get the signal with the selected signal ID let signalID = props.widget.signalIDs[0]; - let widgetSignal = props.signals.find(sig => sig.id === signalID); + let signal = props.signals.filter(s => s.id === signalID) + // determine ID of infrastructure component related to signal[0] (there is only one signal for a lamp widget) + let icID = props.icIDs[signal[0].id]; - // update value + // check if data available if (props.data == null - || props.data[ic] == null - || props.data[ic].output == null - || props.data[ic].output.values == null) { + || props.data[icID] == null + || props.data[icID].output == null + || props.data[icID].output.values == null) { return{value:''}; } // check if value has changed - const signalData = props.data[ic].output.values[widgetSignal.index]; - if (signalData != null && state.value !== signalData[signalData.length - 1].y) { - return { value: signalData[signalData.length - 1].y }; + const data = props.data[icID].output.values[signal[0].index-1]; + if (data != null && Number(state.value) !== data[data.length - 1].y) { + return { value: data[data.length - 1].y }; } return null; } render() { + let colors = EditWidgetColorControl.ColorPalette; let color;