From b301c97212e3bd8361c3820adc2ab49b58e305f9 Mon Sep 17 00:00:00 2001 From: Jacob Salvi Date: Sat, 25 Apr 2020 17:45:22 +0200 Subject: [PATCH] fix to stateOrDevice --- .../src/components/dashboard/devices/Curtain.js | 3 +-- .../src/components/dashboard/devices/Dimmer.js | 3 +-- .../src/components/dashboard/devices/Light.js | 3 +-- .../src/components/dashboard/devices/Sensor.js | 3 +-- .../components/dashboard/devices/SmartPlug.js | 3 +-- smart-hut/src/remote.js | 17 +++++++++++++++++ 6 files changed, 22 insertions(+), 10 deletions(-) diff --git a/smart-hut/src/components/dashboard/devices/Curtain.js b/smart-hut/src/components/dashboard/devices/Curtain.js index de18fda..322e43c 100644 --- a/smart-hut/src/components/dashboard/devices/Curtain.js +++ b/smart-hut/src/components/dashboard/devices/Curtain.js @@ -110,8 +110,7 @@ const mapStateToProps = (state, ownProps) => ({ if(state.active.activeTab==="Devices"){ return state.devices[ownProps.id]; }else{ - const sceneState = state.sceneStates[ownProps.id]; - return state.devices[sceneState]; + return state.sceneStates[ownProps.id]; } }, //device: state.devices[ownProps.id], diff --git a/smart-hut/src/components/dashboard/devices/Dimmer.js b/smart-hut/src/components/dashboard/devices/Dimmer.js index ee41e3d..e9d7a72 100644 --- a/smart-hut/src/components/dashboard/devices/Dimmer.js +++ b/smart-hut/src/components/dashboard/devices/Dimmer.js @@ -133,8 +133,7 @@ const mapStateToProps = (state, ownProps) => ({ if(state.active.activeTab==="Devices"){ return state.devices[ownProps.id]; }else{ - const sceneState = state.sceneStates[ownProps.id]; - return state.devices[sceneState]; + return state.sceneStates[ownProps.id]; } }, }); diff --git a/smart-hut/src/components/dashboard/devices/Light.js b/smart-hut/src/components/dashboard/devices/Light.js index 161a791..4d81ddd 100644 --- a/smart-hut/src/components/dashboard/devices/Light.js +++ b/smart-hut/src/components/dashboard/devices/Light.js @@ -160,8 +160,7 @@ const mapStateToProps = (state, ownProps) => ({ if(state.active.activeTab==="Devices"){ return state.devices[ownProps.id]; }else{ - const sceneState = state.sceneStates[ownProps.id]; - return state.devices[sceneState]; + return state.sceneStates[ownProps.id]; } }, //device: state.devices[ownProps.id], diff --git a/smart-hut/src/components/dashboard/devices/Sensor.js b/smart-hut/src/components/dashboard/devices/Sensor.js index a38a644..8592420 100644 --- a/smart-hut/src/components/dashboard/devices/Sensor.js +++ b/smart-hut/src/components/dashboard/devices/Sensor.js @@ -196,8 +196,7 @@ const mapStateToProps = (state, ownProps) => ({ if(state.active.activeTab==="Devices"){ return state.devices[ownProps.id]; }else{ - const sceneState = state.sceneStates[ownProps.id]; - return state.devices[sceneState]; + return state.sceneStates[ownProps.id]; } }, }); diff --git a/smart-hut/src/components/dashboard/devices/SmartPlug.js b/smart-hut/src/components/dashboard/devices/SmartPlug.js index c88e762..e1099fa 100644 --- a/smart-hut/src/components/dashboard/devices/SmartPlug.js +++ b/smart-hut/src/components/dashboard/devices/SmartPlug.js @@ -72,8 +72,7 @@ const mapStateToProps = (state, ownProps) => ({ if(state.active.activeTab==="Devices"){ return state.devices[ownProps.id]; }else{ - const sceneState = state.sceneStates[ownProps.id]; - return state.devices[sceneState]; + return state.sceneStates[ownProps.id]; } }, }); diff --git a/smart-hut/src/remote.js b/smart-hut/src/remote.js index 2b6f730..3834827 100644 --- a/smart-hut/src/remote.js +++ b/smart-hut/src/remote.js @@ -396,6 +396,23 @@ export const RemoteService = { }; }, + deleteState: (id,type)=>{ + return (dispatch) => { + let url; + if(type=="dimmableState"){ + url="/dimmableState" + }else{ + url="/switchableState" + } + return Endpoint.delete(url+`/${id}`) + .then((res) => dispatch(actions.statesUpdate([res.data]))) + .catch((err) => { + console.warn(`reset error`, err); + throw new RemoteError(["Network error"]); + }); + }; + }, + /** * Creates/Updates a device with the given data. If * data.id is truthy, then a update call is performed,