diff --git a/smart-hut/src/components/dashboard/devices/Curtain.js b/smart-hut/src/components/dashboard/devices/Curtain.js index 40b6b52..25873d2 100644 --- a/smart-hut/src/components/dashboard/devices/Curtain.js +++ b/smart-hut/src/components/dashboard/devices/Curtain.js @@ -1,11 +1,11 @@ -import React, {Component} from "react"; - +import React, { Component } from "react"; +import "./Curtains.css"; import { RemoteService } from "../../../remote"; import { connect } from "react-redux"; -import {Slider} from "@material-ui/core"; +import { Slider } from "@material-ui/core"; class Curtain extends Component { - constructor (props){ + constructor(props) { super(props); this.state = { intensity: this.props.device.intensity, timeout: null }; @@ -54,49 +54,81 @@ class Curtain extends Component { .catch((err) => console.error("curtains update error", err)); }; - helper=()=>{ - if(this.props.device.intensity>=90){ + helper = () => { + if (this.props.device.intensity >= 90) { this.setIntensity(1); this.saveIntensity(); - }else { - this.setIntensity(this.props.device.intensity / 100 + 0.10); + } else { + this.setIntensity(this.props.device.intensity / 100 + 0.1); this.saveIntensity(); } }; - helper2=()=>{ - if(this.props.device.intensity<=10){ + helper2 = () => { + if (this.props.device.intensity <= 10) { this.setIntensity(0); this.saveIntensity(); - }else { - this.setIntensity(this.props.device.intensity / 100 - 0.10); + } else { + this.setIntensity(this.props.device.intensity / 100 - 0.1); this.saveIntensity(); } }; - helper3=(a)=>{ + helper3 = (a) => { //console.log(a); - this.setIntensity(a/100); + this.setIntensity(a / 100); this.saveIntensity(); }; -///*this took me way too much more time than it should have*/ - render(){ - return

{this.props.device.intensity}

+ ///*this took me way too much more time than it should have*/ - { + this.setIntensity(a.target.value / 100); + this.saveIntensity(); + }; - min={0} value={this.props.device.intensity} max={100} onChange={ (e, val) => {this.helper3(val)}} - /> + render() { + return ( +
+
{" "} + + {Math.round(this.props.device.intensity)}% + + +
+ /* +
+

{this.props.device.intensity}

- - -
; + { + this.helper3(val); + }} + /> + + + +
*/ + ); } } - const mapStateToProps = (state, ownProps) => ({ device: state.devices[ownProps.id], }); const CurtainContainer = connect(mapStateToProps, RemoteService)(Curtain); -export default CurtainContainer; \ No newline at end of file +export default CurtainContainer; diff --git a/smart-hut/src/components/dashboard/devices/Curtains.css b/smart-hut/src/components/dashboard/devices/Curtains.css new file mode 100644 index 0000000..eb3ea90 --- /dev/null +++ b/smart-hut/src/components/dashboard/devices/Curtains.css @@ -0,0 +1,69 @@ +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + +.container { + position: relative; + margin-top: 10%; + width: 18rem; + height: 9rem; + background-color: #f7f7f7; + border-radius: 5px; + box-shadow: 10px 10px 30px 15px rgba(0, 0, 0, 0.247); +} + +.open-container { + position: absolute; + width: 18rem; + background-color: #f79071; + border-radius: 5px; +} + +.slider { + -webkit-appearance: none; + width: 9rem; + position: absolute; + left: 75%; + top: 50%; + transform: translateY(-50%) rotateZ(90deg); + background: transparent; + outline: none; +} + +.slider::-webkit-slider-runnable-track { + -webkit-appearance: none; + height: 5px; + background-color: #1b1c1d; + border-radius: 50px; + cursor: pointer; +} + +.slider::-webkit-slider-thumb { + -webkit-appearance: none; + appearance: none; + width: 18px; + height: 18px; + border-radius: 50%; + background: #1b1c1d; + position: relative; + transition: all; + top: -5.5px; +} + +.slider::-webkit-slider-thumb:hover { + transform: scale(1.2); +} + +.span-open { + -webkit-user-select: none; + font-family: "Lato"; + font-weight: bold; + font-size: 3rem; + text-emphasis: none; + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); +} diff --git a/smart-hut/src/components/dashboard/devices/Curtains.js b/smart-hut/src/components/dashboard/devices/Curtains.js new file mode 100644 index 0000000..8a259a9 --- /dev/null +++ b/smart-hut/src/components/dashboard/devices/Curtains.js @@ -0,0 +1,41 @@ +// TODO Remove this! + +import React, { Component } from "react"; +import "./Curtains.css"; + +class Curtain extends Component { + constructor(props) { + super(props); + this.state = { + open: 0.6, + }; + } + + handleChange = (e) => { + this.setState({ open: e.target.value / 100 }); + }; + + render() { + return ( +
+
{" "} + + {Math.round(this.state.open * 100)}% + + +
+ ); + } +} + +export default Curtain; diff --git a/smart-hut/src/components/dashboard/devices/Device.js b/smart-hut/src/components/dashboard/devices/Device.js index b02d9a2..8abef3f 100644 --- a/smart-hut/src/components/dashboard/devices/Device.js +++ b/smart-hut/src/components/dashboard/devices/Device.js @@ -13,105 +13,112 @@ import { connect } from "react-redux"; import DeviceSettingsModal from "./DeviceSettingsModal"; class Device extends React.Component { - constructor(props) { - super(props); + constructor(props) { + super(props); - this.modalRef = React.createRef(); - this.edit = this.edit.bind(this); - this.resetSmartPlug = this.resetSmartPlug.bind(this); - } - - edit() { - console.log("editing device with id=" + this.props.id); - this.modalRef.current.openModal(); - } - - resetSmartPlug() { - this.props - .smartPlugReset(this.props.id) - .catch((err) => console.error(`Smart plug reset error`, err)); - } - - renderDeviceComponent() { - switch (this.props.stateOrDevice.kind) { - case "curtains": - return - case "thermostat": - return - case "regularLight": - return ; - case "sensor": - return ; - case "motionSensor": - return ; - case "buttonDimmer": - return ; - case "knobDimmer": - return ; - case "smartPlug": - return ; - case "switch": - return ; - case "dimmableLight": - return ; - case "securityCamera": - return ; - default: - throw new Error("Device type unknown"); + this.modalRef = React.createRef(); + this.edit = this.edit.bind(this); + this.resetSmartPlug = this.resetSmartPlug.bind(this); } - } - render() { - return ( - - - {this.renderDeviceComponent()} - {this.props.tab === "Devices" ? ( - -
{this.props.stateOrDevice.name}
- - {this.props.stateOrDevice.kind === "smartPlug" ? ( - - ) : null} -
- ) : ( - -
{this.props.stateOrDevice.name}
-
- )} + edit() { + console.log("editing device with id=" + this.props.id); + this.modalRef.current.openModal(); + } - -
-
- ); - } + resetSmartPlug() { + this.props + .smartPlugReset(this.props.id) + .catch((err) => console.error(`Smart plug reset error`, err)); + } + + renderDeviceComponent() { + switch (this.props.stateOrDevice.kind) { + case "curtains": + return ; + case "thermostat": + return ; + case "regularLight": + return ; + case "sensor": + return ; + case "motionSensor": + return ; + case "buttonDimmer": + return ; + case "knobDimmer": + return ; + case "smartPlug": + return ; + case "switch": + return ; + case "dimmableLight": + return ; + case "securityCamera": + return ; + default: + throw new Error("Device type unknown"); + } + } + + render() { + return ( + + + {this.renderDeviceComponent()} + {this.props.tab === "Devices" ? ( + +
+ {this.props.stateOrDevice.name} +
+ + {this.props.stateOrDevice.kind === "smartPlug" ? ( + + ) : null} +
+ ) : ( + +
+ {this.props.stateOrDevice.name} +
+
+ )} + + +
+
+ ); + } } const mapStateToProps = (state, ownProps) => ({ - get stateOrDevice() { - if (state.active.activeTab === "Devices") { - return state.devices[ownProps.id]; - } else { - const sceneState = state.sceneStates[ownProps.id]; - return state.devices[sceneState]; - } - }, + get stateOrDevice() { + if (state.active.activeTab === "Devices") { + return state.devices[ownProps.id]; + } else { + const sceneState = state.sceneStates[ownProps.id]; + return state.devices[sceneState]; + } + }, }); const DeviceContainer = connect(mapStateToProps, RemoteService)(Device); export default DeviceContainer; diff --git a/smart-hut/src/components/dashboard/devices/Thermostat.css b/smart-hut/src/components/dashboard/devices/Thermostat.css new file mode 100644 index 0000000..d098c2f --- /dev/null +++ b/smart-hut/src/components/dashboard/devices/Thermostat.css @@ -0,0 +1,38 @@ +.slider-css { + -webkit-appearance: none; + width: 20rem; + font-family: "Lato"; + position: absolute; + margin-top: 32%; + margin-left: 50%; + transform: translate(-50%, -50%); +} + +.slider-css::-webkit-slider-thumb { + -webkit-appearance: none; + border: 5px solid #ffffff; + width: 18px; + height: 18px; + border-radius: 10px; + background-color: rgba(94, 246, 152, 1); + cursor: pointer; + box-shadow: 1px 1px 15px 2px rgba(0, 0, 0, 0.4); + margin-top: -7px; +} + +.slider-css:focus { + -webkit-appearance: none; + + outline: none; +} + +.slider-css::-webkit-slider-runnable-track { + -webkit-appearance: none; + outline: none; + width: 100%; + height: 7px; + cursor: pointer; + box-shadow: 4.5px 4.5px 20px 1px rgba(0, 0, 0, 0.3); + background: white; + border-radius: 5px; +} diff --git a/smart-hut/src/components/dashboard/devices/Thermostat.js b/smart-hut/src/components/dashboard/devices/Thermostat.js new file mode 100644 index 0000000..e14f9e0 --- /dev/null +++ b/smart-hut/src/components/dashboard/devices/Thermostat.js @@ -0,0 +1,62 @@ +// TODO Remove this! + +import React, { Component } from "react"; +import { + stateTag, + container, + deviceName, + targetTemperature, + slider, + line, + stateTagContainer, +} from "./ThermostatStyle"; + +class Thermostat extends Component { + constructor(props) { + super(props); + this.state = { + currentTemperature: 10, + targetTemperature: 20, + state: "idle", + }; + } + + handleChange = (value) => { + let state = this.state.state; + if (this.state.currentTemperature > value) { + state = "cooling"; + } else if (this.state.currentTemperature < value) { + state = "heating"; + } else { + state = "idle"; // or heating, i don't know the difference + } + + this.setState({ targetTemperature: value, state: state }); + }; + + render() { + return ( +
+

{this.props.device.name}

+
+ + {this.state.targetTemperature}ºC + + this.handleChange(event.target.value)} + id="targetTemperature" + /> +
+ {this.state.state} +
+
+ ); + } +} + +export default Thermostat; diff --git a/smart-hut/src/components/dashboard/devices/ThermostatStyle.js b/smart-hut/src/components/dashboard/devices/ThermostatStyle.js new file mode 100644 index 0000000..9f266c7 --- /dev/null +++ b/smart-hut/src/components/dashboard/devices/ThermostatStyle.js @@ -0,0 +1,73 @@ +export const container = { + position: "relative", + width: "25rem", + height: "12rem", + boxShadow: "22px 18px 54px -7px rgba(102,102,102,1)", + borderRadius: "30px", + backgroundColor: "white", +}; + +export const line = { + width: "250px", + height: "47px", + borderBottom: "1px solid #646464", + position: "absolute", + left: "5%", +}; + +export const deviceName = { + fontFamily: "Lato", + position: "absolute", + marginTop: "5%", + marginLeft: "8%", + fontSize: "1rem", + fontWeight: "bold", + color: "#646464", +}; + +export const targetTemperature = { + fontFamily: "Lato", + position: "absolute", + marginTop: "20%", + marginLeft: "50%", + transform: "translate(-50%,-50%)", + fontSize: "3.5rem", + fontWeight: "bold", + color: "#646464", +}; + +export const slider = { + width: "25rem", + fontFamily: "Lato", + position: "absolute", + marginTop: "35%", + marginLeft: "50%", + transform: "translate(-50%,-50%)", +}; + +export const stateTagContainer = { + textAlign: "center", + position: "absolute", + width: "4rem", + height: "1rem", + marginTop: "40%", + marginLeft: "50%", + transform: "translate(-50%,-50%)", + padding: "0.5rem 4rem", + backgroundColor: "rgba(94,246,152,1)", + borderRadius: "50px", +}; + +export const stateTag = { + fontFamily: "Lato", + fontSize: "1.2rem", + color: "white", + textTransform: "uppercase", +}; + +export const toggle = { + position: "absolute", + top: "10%", + left: "35%", + transform: "rotate(-360deg)", +}; diff --git a/smart-hut/src/components/dashboard/devices/Thermostats.js b/smart-hut/src/components/dashboard/devices/Thermostats.js index eeba407..cd3e461 100644 --- a/smart-hut/src/components/dashboard/devices/Thermostats.js +++ b/smart-hut/src/components/dashboard/devices/Thermostats.js @@ -1,53 +1,67 @@ -import React, {Component} from "react"; - +import React, { Component } from "react"; +import { Checkbox } from "semantic-ui-react"; import { RemoteService } from "../../../remote"; import { connect } from "react-redux"; - +import "./Thermostat.css"; +import { + stateTag, + container, + deviceName, + targetTemperature, + slider, + line, + toggle, + stateTagContainer, +} from "./ThermostatStyle"; //not quite working yet -class Thermostats extends Component{ - constructor (props){ +class Thermostats extends Component { + constructor(props) { super(props); - this.state = {targetTemperature: this.props.device.targetTemperature, - internalSensorTemperature: this.props.device.internalSensorTemperature, + this.state = { + targetTemperature: this.props.device.targetTemperature, + internalSensorTemperature: this.props.device + .internalSensorTemperature, mode: this.props.device.mode, measuredTemperature: this.props.device.measuredTemperature, useExternalSensors: this.props.device.useExternalSensors, - timeout: null }; - this.setMode=this.setMode.bind(this); - this.setTargetTemperature=this.setTargetTemperature.bind(this); - this.setInternalSensorTemperature=this.setInternalSensorTemperature.bind(this); + timeout: null, + }; + this.setMode = this.setMode.bind(this); + this.setTargetTemperature = this.setTargetTemperature.bind(this); + this.setInternalSensorTemperature = this.setInternalSensorTemperature.bind( + this + ); } //getters - get getMode(){ + get getMode() { return this.props.device.mode; } - get getTargetTemperature(){ + get getTargetTemperature() { return this.props.device.targetTemperature; } - get getInternalSensorTemperature(){ + get getInternalSensorTemperature() { return this.props.device.internalSensorTemperature; } - get getMeasuredTemperature(){ + get getMeasuredTemperature() { return this.props.device.measuredTemperature; } - get getUseExternalSensors(){ + get getUseExternalSensors() { return this.props.device.useExternalSensors; } - setMode(mode){ + setMode(mode) { if (this.state.timeout) { clearTimeout(this.state.timeout); } //i came to the conclusion that is not possible to set mode. - this.mode="HEATING"; - + this.mode = "HEATING"; } onClickDevice = () => { @@ -57,16 +71,14 @@ class Thermostats extends Component{ .catch((err) => console.error("regular light update error", err)); }; - //It seems to work - saveTargetTemperature(targetTemperature){ + saveTargetTemperature(targetTemperature) { this.props .saveDevice({ ...this.props.device, targetTemperature }) .catch((err) => console.error(" update error", err)); - } - setTargetTemperature(newTemp){ + setTargetTemperature(newTemp) { if (this.state.timeout) { clearTimeout(this.state.timeout); } @@ -84,13 +96,13 @@ class Thermostats extends Component{ } //I have no idea why it doesn't want to update the temperature - saveInternalSensorTemperature(internalSensorTemperature){ + saveInternalSensorTemperature(internalSensorTemperature) { this.props .saveDevice({ ...this.props.device, internalSensorTemperature }) .catch((err) => console.error(" update error", err)); } - setInternalSensorTemperature(newTemp){ + setInternalSensorTemperature(newTemp) { if (this.state.timeout) { clearTimeout(this.state.timeout); } @@ -100,34 +112,89 @@ class Thermostats extends Component{ timeout: setTimeout(() => { this.saveInternalSensorTemperature(newTemp); this.setState({ - internalSensorTemperature: this.state.internalSensorTemperature, + internalSensorTemperature: this.state + .internalSensorTemperature, timeout: null, }); }, 100), }); } - helperMode=()=>{ + helperMode = () => { //this.setMode("HEATING"); this.setTargetTemperature(20); //this.setInternalSensorTemperature(42); - } + }; - render(){ - return

"mode is: "{this.props.device.mode}

-

"internalsensortemperature is: "{this.props.device.internalSensorTemperature}

-

"targetTemperature is: "{this.props.device.targetTemperature}

-

"measuredtemperature is: "{this.props.device.measuredTemperature}

-

{this.props.device.on}

- -
; - } + handleChange = (value) => { + this.setTargetTemperature(value); + }; + render() { + return ( + /*
+

"mode is: "{this.props.device.mode}

+

+ "internalsensortemperature is: " + {this.props.device.internalSensorTemperature} +

+

+ "targetTemperature is: " + {this.props.device.targetTemperature} +

+

+ "measuredtemperature is: " + {this.props.device.measuredTemperature} +

+

{this.props.device.on}

+ + +
*/ + +
+

{this.props.device.name}

+
+ console.log("CHANGE", val.checked)} + /> + + + {this.props.device.targetTemperature}ºC + + this.handleChange(event.target.value)} + id="targetTemperature" + /> +
+ {this.props.device.mode} +
+
+ ); + } } const mapStateToProps = (state, ownProps) => ({ device: state.devices[ownProps.id], }); -const ThermostatContainer = connect(mapStateToProps, RemoteService)(Thermostats); -export default ThermostatContainer; \ No newline at end of file +const ThermostatContainer = connect( + mapStateToProps, + RemoteService +)(Thermostats); +export default ThermostatContainer;