diff --git a/smart-hut/src/components/dashboard/NewSceneDevice.js b/smart-hut/src/components/dashboard/NewSceneDevice.js index cef04f9..9b76044 100644 --- a/smart-hut/src/components/dashboard/NewSceneDevice.js +++ b/smart-hut/src/components/dashboard/NewSceneDevice.js @@ -62,17 +62,20 @@ class NewSceneDevice extends Component { } createState() { - const device = this.props.devices.filter( - (e) => this.state.devicesAttached[0] === e.id - ); - let data = { - sceneId: this.props.activeScene, - id: device[0].id, - kind: device[0].kind, - }; - this.props - .saveState(data) - .catch((err) => console.error("error in creating state", err)); + for (let i = 0; i < this.state.devicesAttached.length; i++) { + console.log("DIOPORCO", i, this.state.devicesAttached[i]); + let device = this.props.devices.filter( + (e) => this.state.devicesAttached[i] === e.id + ); + let data = { + sceneId: this.props.activeScene, + id: device[0].id, + kind: device[0].kind, + }; + this.props + .saveState(data) + .catch((err) => console.error("error in creating state", err)); + } this.resetState(); } diff --git a/smart-hut/src/components/dashboard/devices/Device.js b/smart-hut/src/components/dashboard/devices/Device.js index 954c67e..263e845 100644 --- a/smart-hut/src/components/dashboard/devices/Device.js +++ b/smart-hut/src/components/dashboard/devices/Device.js @@ -179,10 +179,12 @@ class Device extends React.Component { ? this.deviceDescription() : this.stateDescription()} - + {this.props.tab === "Devices" ? ( + + ) : null} ); } diff --git a/smart-hut/src/components/dashboard/devices/Thermostats.js b/smart-hut/src/components/dashboard/devices/Thermostats.js index 4a628b7..ef89dfd 100644 --- a/smart-hut/src/components/dashboard/devices/Thermostats.js +++ b/smart-hut/src/components/dashboard/devices/Thermostats.js @@ -71,7 +71,7 @@ class Thermostats extends Component { .catch((err) => console.error("thermostat update error", err)); } else { this.props.updateState( - { id: this.props.stateOrDevice.id, turnOn: turnOn }, + { id: this.props.stateOrDevice.id, on: turnOn }, this.props.stateOrDevice.kind ); } @@ -186,19 +186,20 @@ class Thermostats extends Component { // TODO Manage the state hereconsole.log("CHANGE", val.checked) onChange={(e, val) => this.setMode(val.checked)} /> - - {this.props.stateOrDevice.targetTemperature}ºC + {this.props.device.targetTemperature}ºC - this.handleChange(event.target.value)} - id="targetTemperature" - /> + {this.props.activeTab === "Devices" ? ( + this.handleChange(event.target.value)} + id="targetTemperature" + /> + ) : null}
{this.props.stateOrDevice.mode}
@@ -215,6 +216,14 @@ const mapStateToProps = (state, ownProps) => ({ return state.sceneStates[ownProps.id]; } }, + get device() { + if (state.active.activeTab === "Devices") { + return state.devices[ownProps.id]; + } else { + return state.devices[state.sceneStates[ownProps.id].deviceId]; + } + }, + activeTab: state.activeTab, }); const ThermostatContainer = connect( diff --git a/smart-hut/src/remote.js b/smart-hut/src/remote.js index c238c56..b8cc42e 100644 --- a/smart-hut/src/remote.js +++ b/smart-hut/src/remote.js @@ -423,7 +423,7 @@ export const RemoteService = { updateState: (data, type) => { return (dispatch) => { let url; - if (data.on) { + if (data.on !== undefined) { url = "/switchableState"; } else { url = "/dimmableState";