diff --git a/smart-hut/src/components/dashboard/ScenesPanel.js b/smart-hut/src/components/dashboard/ScenesPanel.js
index 4060e9a..d8bcfd5 100644
--- a/smart-hut/src/components/dashboard/ScenesPanel.js
+++ b/smart-hut/src/components/dashboard/ScenesPanel.js
@@ -8,13 +8,14 @@ import { Grid, Button } from "semantic-ui-react";
class ScenesPanel extends Component {
constructor(props) {
super(props);
-
this.applyScene = this.applyScene.bind(this);
}
applyScene() {
console.log(this.props.activeScene);
- this.props.sceneApply(this.props.activeScene);
+ this.props.sceneApply(this.props.activeScene).then(() => {
+ alert("Scene applied.");
+ });
}
render() {
diff --git a/smart-hut/src/components/dashboard/devices/Curtain.js b/smart-hut/src/components/dashboard/devices/Curtain.js
index 322e43c..37920ce 100644
--- a/smart-hut/src/components/dashboard/devices/Curtain.js
+++ b/smart-hut/src/components/dashboard/devices/Curtain.js
@@ -4,116 +4,123 @@ import { RemoteService } from "../../../remote";
import { connect } from "react-redux";
class Curtain extends Component {
- constructor(props) {
- super(props);
- this.state = { intensity: this.props.stateOrDevice.intensity, timeout: null };
-
- this.setIntensity = this.setIntensity.bind(this);
- }
-
- //getters
- get turnedOn() {
- return this.props.stateOrDevice.on;
- }
-
- get intensity() {
- return this.props.stateOrDevice.intensity || 0;
- }
-
- onClickDevice = () => {
- const on = !this.turnedOn;
- if(this.props.tab==="Devices"){
- this.props
- .saveDevice({ ...this.props.stateOrDevice, on })
- .catch((err) => console.error("curtains update error", err));
- }else{
- this.props.updateState({ id: this.props.sceneState.id, on: on },this.props.sceneState.kind);
- }
+ constructor(props) {
+ super(props);
+ this.state = {
+ intensity: this.props.stateOrDevice.intensity,
+ timeout: null,
};
- setIntensity(intensity) {
- intensity *= 100;
+ this.setIntensity = this.setIntensity.bind(this);
+ }
- if (this.state.timeout) {
- clearTimeout(this.state.timeout);
- }
+ //getters
+ get turnedOn() {
+ return this.props.stateOrDevice.on;
+ }
- this.setState({
- intensity,
- timeout: setTimeout(() => {
- this.saveIntensity();
- this.setState({
- intensity: this.state.intensity,
- timeout: null,
- });
- }, 100),
- });
+ get intensity() {
+ return this.props.stateOrDevice.intensity || 0;
+ }
+
+ onClickDevice = () => {
+ const on = !this.turnedOn;
+ if (this.props.tab === "Devices") {
+ this.props
+ .saveDevice({ ...this.props.stateOrDevice, on })
+ .catch((err) => console.error("curtains update error", err));
+ } else {
+ this.props.updateState(
+ { id: this.props.stateOrDevice.id, on: on },
+ this.props.stateOrDevice.kind
+ );
+ }
+ };
+
+ setIntensity(intensity) {
+ intensity *= 100;
+
+ if (this.state.timeout) {
+ clearTimeout(this.state.timeout);
}
- saveIntensity = () => {
- const intensity = Math.round(this.state.intensity);
- if(this.props.tab==="Devices"){
- this.props
- .saveDevice({ ...this.props.stateOrDevice, intensity })
- .catch((err) => console.error("curtain update error", err));
- }else{
- this.props.updateState({ id: this.props.sceneState.id, intensity: intensity },this.props.sceneState.kind);
- }
- };
-
- helper = () => {
- if (this.props.device.intensity >= 90) {
- this.setIntensity(1);
- this.saveIntensity();
- } else {
- this.setIntensity(this.props.stateOrDevice.intensity / 100 + 0.1);
- this.saveIntensity();
- }
- };
-
-
- ///*this took me way too much more time than it should have*/
-
- handleChange = (a) => {
- this.setIntensity(a.target.value / 100);
+ this.setState({
+ intensity,
+ timeout: setTimeout(() => {
this.saveIntensity();
- };
+ this.setState({
+ intensity: this.state.intensity,
+ timeout: null,
+ });
+ }, 100),
+ });
+ }
- render() {
- return (
-
-
{" "}
-
- {Math.round(this.props.stateOrDevice.intensity)}%
-
-
-
-
- );
+ saveIntensity = () => {
+ const intensity = Math.round(this.state.intensity);
+ if (this.props.tab === "Devices") {
+ this.props
+ .saveDevice({ ...this.props.stateOrDevice, intensity })
+ .catch((err) => console.error("curtain update error", err));
+ } else {
+ this.props.updateState(
+ { id: this.props.stateOrDevice.id, intensity: intensity },
+ this.props.stateOrDevice.kind
+ );
}
+ };
+
+ helper = () => {
+ if (this.props.device.intensity >= 90) {
+ this.setIntensity(1);
+ this.saveIntensity();
+ } else {
+ this.setIntensity(this.props.stateOrDevice.intensity / 100 + 0.1);
+ this.saveIntensity();
+ }
+ };
+
+ ///*this took me way too much more time than it should have*/
+
+ handleChange = (a) => {
+ this.setIntensity(a.target.value / 100);
+ this.saveIntensity();
+ };
+
+ render() {
+ return (
+
+
{" "}
+
+ {Math.round(this.props.stateOrDevice.intensity)}%
+
+
+
+ );
+ }
}
const mapStateToProps = (state, ownProps) => ({
- get stateOrDevice(){
- if(state.active.activeTab==="Devices"){
- return state.devices[ownProps.id];
- }else{
- return state.sceneStates[ownProps.id];
- }
- },
- //device: state.devices[ownProps.id],
+ get stateOrDevice() {
+ if (state.active.activeTab === "Devices") {
+ return state.devices[ownProps.id];
+ } else {
+ return state.sceneStates[ownProps.id];
+ }
+ },
+ //device: state.devices[ownProps.id],
});
const CurtainContainer = connect(mapStateToProps, RemoteService)(Curtain);
export default CurtainContainer;
diff --git a/smart-hut/src/components/dashboard/devices/Device.js b/smart-hut/src/components/dashboard/devices/Device.js
index 8ad0fd2..41b0b16 100644
--- a/smart-hut/src/components/dashboard/devices/Device.js
+++ b/smart-hut/src/components/dashboard/devices/Device.js
@@ -77,60 +77,28 @@ class Device extends React.Component {
/>
);
case "motionSensor":
- return (
-
- );
+ return ;
case "buttonDimmer":
return (
-
+
);
case "knobDimmer":
return (
-
+
);
case "smartPlug":
return (
-
+
);
case "switch":
return (
-
+
);
case "dimmableLight":
- return (
-
- );
+ return ;
case "securityCamera":
return (
-
+
);
default:
//throw new Error("Device type unknown");
@@ -171,11 +139,12 @@ class Device extends React.Component {
) : (
-
- {this.props.stateOrDevice
- ? this.props.stateOrDevice.name
- : ""}
-
+
+ {this.props.tab === "Scenes" ? (
+
+ ) : (
+ ""
+ )}