Thermostats fixed

This commit is contained in:
Claudio Maggioni (maggicl) 2020-05-02 11:11:21 +02:00
parent 3af3b85aa9
commit d49d6361ef
6 changed files with 83 additions and 101 deletions

View File

@ -20,6 +20,7 @@
"react-device-detect": "^1.11.14", "react-device-detect": "^1.11.14",
"react-dom": "^16.12.0", "react-dom": "^16.12.0",
"react-modal": "^2.2.2", "react-modal": "^2.2.2",
"react-rangeslider": "^2.2.0",
"react-redux": "^7.2.0", "react-redux": "^7.2.0",
"react-round-slider": "^1.0.1", "react-round-slider": "^1.0.1",
"react-router": "^5.1.2", "react-router": "^5.1.2",

View File

@ -107,6 +107,7 @@ class NewDevice extends Component {
buttonDimmer: "New button dimmer", buttonDimmer: "New button dimmer",
knobDimmer: "New knob dimmer", knobDimmer: "New knob dimmer",
securityCamera: "New security camera", securityCamera: "New security camera",
thermostat: "New thermostat",
}; };
if (this.state.deviceName === "") { if (this.state.deviceName === "") {

View File

@ -1,15 +1,10 @@
.slider-css { .rangeslider.slider-css {
-webkit-appearance: none; margin-left: 1rem;
width: 20rem; margin-right: 1rem;
font-family: "Lato";
position: absolute;
margin-top: 27%;
margin-left: 50%;
transform: translate(-50%, -50%);
} }
/*
.slider-css::-webkit-slider-thumb { .slider-css::-webkit-slider-thumb {
-webkit-appearance: none;
border: 5px solid #ffffff; border: 5px solid #ffffff;
width: 18px; width: 18px;
height: 18px; height: 18px;
@ -21,13 +16,10 @@
} }
.slider-css:focus { .slider-css:focus {
-webkit-appearance: none;
outline: none; outline: none;
} }
.slider-css::-webkit-slider-runnable-track { .slider-css::-webkit-slider-runnable-track {
-webkit-appearance: none;
outline: none; outline: none;
width: 100%; width: 100%;
height: 7px; height: 7px;
@ -36,3 +28,4 @@
background: white; background: white;
border-radius: 5px; border-radius: 5px;
} }
*/

View File

@ -1,37 +1,27 @@
export const container = { export const container = {
position: "relative", margin: "-1em 0",
width: "25rem", width: "15em",
height: "12rem", height: "14em",
boxShadow: "22px 18px 54px -7px rgba(102,102,102,1)", boxShadow: "5px 5px 5px 5px #DDD",
borderRadius: "30px", borderRadius: "1em",
backgroundColor: "white", backgroundColor: "white",
}; transform: "translate(-2.5em, 0)",
export const line = {
width: "250px",
height: "47px",
borderBottom: "1px solid #646464",
position: "absolute",
left: "5%",
}; };
export const deviceName = { export const deviceName = {
paddingTop: ".5rem",
paddingLeft: "1rem",
fontFamily: "Lato", fontFamily: "Lato",
position: "absolute",
marginTop: "5%",
marginLeft: "8%",
fontSize: "1rem", fontSize: "1rem",
fontWeight: "bold", fontWeight: "bold",
color: "#646464",
}; };
export const targetTemperature = { export const targetTemperature = {
fontFamily: "Lato", fontFamily: "Lato",
position: "absolute", marginTop: ".5rem",
marginTop: "20%", width: "100%",
marginLeft: "50%", textAlign: "center",
transform: "translate(-50%,-50%)", fontSize: "1.3rem",
fontSize: "2rem",
fontWeight: "bold", fontWeight: "bold",
color: "#646464", color: "#646464",
}; };
@ -48,26 +38,26 @@ export const slider = {
export const stateTagContainer = { export const stateTagContainer = {
textAlign: "center", textAlign: "center",
position: "absolute", position: "absolute",
//width: "3rem", width: "10rem",
height: "2rem", height: "2rem",
marginTop: "35%", bottom: 0,
marginLeft: "50%", left: "50%",
transform: "translate(-50%,-50%)", transform: "translate(-50%,-50%)",
padding: "0.5rem 4rem", backgroundColor: "#2b2",
backgroundColor: "rgba(94,246,152,1)",
borderRadius: "50px", borderRadius: "50px",
}; };
export const stateTag = { export const stateTag = {
fontFamily: "Lato", fontFamily: "Lato",
fontSize: "1.2rem", fontSize: "1.2rem",
lineHeight: "2rem",
color: "white", color: "white",
textTransform: "uppercase", textTransform: "uppercase",
}; };
export const toggle = { export const toggle = {
position: "absolute", position: "absolute",
top: "10%", top: ".7rem",
left: "35%", right: "2.5rem",
transform: "rotate(-360deg)", transform: "rotate(-360deg)",
}; };

View File

@ -1,15 +1,16 @@
import React, { Component } from "react"; import React, { Component } from "react";
import { Checkbox } from "semantic-ui-react"; import { Checkbox, Icon } from "semantic-ui-react";
import { RemoteService } from "../../../remote"; import { RemoteService } from "../../../remote";
import { connect } from "react-redux"; import { connect } from "react-redux";
import "./Thermostat.css"; import "./Thermostat.css";
import Slider from "react-rangeslider";
import "react-rangeslider/lib/index.css";
import { import {
stateTag, stateTag,
container, container,
deviceName, deviceName,
targetTemperature, targetTemperature,
slider,
line,
toggle, toggle,
stateTagContainer, stateTagContainer,
} from "./ThermostatStyle"; } from "./ThermostatStyle";
@ -20,8 +21,6 @@ class Thermostats extends Component {
super(props); super(props);
this.state = { this.state = {
targetTemperature: this.props.stateOrDevice.targetTemperature, targetTemperature: this.props.stateOrDevice.targetTemperature,
internalSensorTemperature: this.props.stateOrDevice
.internalSensorTemperature,
mode: this.props.stateOrDevice.mode, mode: this.props.stateOrDevice.mode,
measuredTemperature: this.props.stateOrDevice.measuredTemperature, measuredTemperature: this.props.stateOrDevice.measuredTemperature,
useExternalSensors: this.props.stateOrDevice.useExternalSensors, useExternalSensors: this.props.stateOrDevice.useExternalSensors,
@ -29,9 +28,7 @@ class Thermostats extends Component {
}; };
this.setMode = this.setMode.bind(this); this.setMode = this.setMode.bind(this);
this.setTargetTemperature = this.setTargetTemperature.bind(this); this.setTargetTemperature = this.setTargetTemperature.bind(this);
this.setInternalSensorTemperature = this.setInternalSensorTemperature.bind( this.setTargetTemperature = this.setTargetTemperature.bind(this);
this
);
} }
//getters //getters
@ -43,10 +40,6 @@ class Thermostats extends Component {
return this.props.stateOrDevice.targetTemperature; return this.props.stateOrDevice.targetTemperature;
} }
get getInternalSensorTemperature() {
return this.props.stateOrDevice.internalSensorTemperature;
}
get getMeasuredTemperature() { get getMeasuredTemperature() {
return this.props.stateOrDevice.measuredTemperature; return this.props.stateOrDevice.measuredTemperature;
} }
@ -62,6 +55,7 @@ class Thermostats extends Component {
console.log(mode); console.log(mode);
//i came to the conclusion that is not possible to set mode. //i came to the conclusion that is not possible to set mode.
// Good job Jacob (Claudio)
//this.mode = "HEATING"; //this.mode = "HEATING";
const turnOn = mode; const turnOn = mode;
console.log(turnOn); console.log(turnOn);
@ -85,7 +79,7 @@ class Thermostats extends Component {
.catch((err) => console.error("thermostat update error", err)); .catch((err) => console.error("thermostat update error", err));
} else { } else {
this.props.updateState( this.props.updateState(
{ id: this.props.stateOrDevice.id, on: on }, { id: this.props.stateOrDevice.id, on },
this.props.stateOrDevice.kind this.props.stateOrDevice.kind
); );
} }
@ -93,7 +87,7 @@ class Thermostats extends Component {
//It seems to work //It seems to work
saveTargetTemperature(targetTemperature) { saveTargetTemperature(targetTemperature) {
const turn = this.props.stateOrDevice.mode !== "OFF" ? true : false; const turn = this.props.stateOrDevice.mode !== "OFF";
if (this.props.tab === "Devices") { if (this.props.tab === "Devices") {
this.props this.props
.saveDevice({ .saveDevice({
@ -131,73 +125,63 @@ class Thermostats extends Component {
} }
//I have no idea why it doesn't want to update the temperature //I have no idea why it doesn't want to update the temperature
saveInternalSensorTemperature(internalSensorTemperature) { // Maybe ask yourself some questions
saveTargetTemperature(targetTemperature) {
if (this.props.tab === "Devices") { if (this.props.tab === "Devices") {
this.props this.props
.saveDevice({ ...this.props.device, internalSensorTemperature }) .saveDevice({
...this.props.device,
turnOn: this.props.device.mode !== "OFF",
targetTemperature,
})
.catch((err) => console.error("thermostat update error", err)); .catch((err) => console.error("thermostat update error", err));
} else { } else {
this.props.updateState( this.props.updateState(
{ {
id: this.props.stateOrDevice.id, id: this.props.stateOrDevice.id,
internalSensorTemperature: internalSensorTemperature, targetTemperature: targetTemperature,
}, },
this.props.stateOrDevice.kind this.props.stateOrDevice.kind
); );
} }
} }
setInternalSensorTemperature(newTemp) { setTargetTemperature() {
if (this.state.timeout) { this.saveTargetTemperature(this.state.targetTemperature);
clearTimeout(this.state.timeout);
}
this.setState({
newTemp,
timeout: setTimeout(() => {
this.saveInternalSensorTemperature(newTemp);
this.setState({
internalSensorTemperature: this.state.internalSensorTemperature,
timeout: null,
});
}, 100),
});
} }
helperMode = () => {
//this.setMode("HEATING");
this.setTargetTemperature(20);
//this.setInternalSensorTemperature(42);
};
handleChange = (value) => { handleChange = (value) => {
this.setTargetTemperature(value); this.setState({ ...this.state, targetTemperature: value });
}; };
render() { render() {
return ( return (
<div style={container}> <div style={container}>
<h3 style={deviceName}>{this.props.stateOrDevice.name}</h3> <h3 style={deviceName}>
<div style={line}></div> Thermostat
<Checkbox <Checkbox
checked={this.props.stateOrDevice.mode !== "OFF" ? true : false} checked={this.props.stateOrDevice.mode !== "OFF" ? true : false}
slider slider
style={toggle} style={toggle}
// TODO Manage the state hereconsole.log("CHANGE", val.checked) onChange={(e, val) => this.setMode(val.checked)}
onChange={(e, val) => this.setMode(val.checked)} />
/> </h3>
<span style={targetTemperature}> <hr />
{this.props.device.targetTemperature}ºC <div style={targetTemperature}>
</span> <Icon name="thermometer half" />{" "}
{this.props.activeTab === "Devices" ? ( {this.props.device.measuredTemperature} ºC <br />
<input <Icon name="target" /> {this.state.targetTemperature.toFixed(1)} ºC
type="range" </div>
min="0" {this.props.tab === "Devices" ? (
max="40" <Slider
min={10}
max={30}
step={0.1}
tooltip={false}
className="slider-css" className="slider-css"
value={this.props.device.targetTemperature} value={this.state.targetTemperature}
onChange={(event) => this.handleChange(event.target.value)} onChange={(event) => this.handleChange(event)}
id="targetTemperature" onChangeComplete={() => this.setTargetTemperature()}
/> />
) : null} ) : null}
<div style={stateTagContainer}> <div style={stateTagContainer}>

View File

@ -2814,7 +2814,7 @@ class-utils@^0.3.5:
isobject "^3.0.0" isobject "^3.0.0"
static-extend "^0.1.1" static-extend "^0.1.1"
classnames@^2.2.6: classnames@^2.2.3, classnames@^2.2.6:
version "2.2.6" version "2.2.6"
resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.2.6.tgz#43935bffdd291f326dad0a205309b38d00f650ce" resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.2.6.tgz#43935bffdd291f326dad0a205309b38d00f650ce"
integrity sha512-JR/iSQOSt+LQIWwrwEzJ9uk0xfN3mTVYMwt1Ir5mUcSN6pU+V4zQFFaJsclJbPuAUQH+yfWef6tm7l1quW3C8Q== integrity sha512-JR/iSQOSt+LQIWwrwEzJ9uk0xfN3mTVYMwt1Ir5mUcSN6pU+V4zQFFaJsclJbPuAUQH+yfWef6tm7l1quW3C8Q==
@ -8787,6 +8787,14 @@ react-popper@^1.3.4:
typed-styles "^0.0.7" typed-styles "^0.0.7"
warning "^4.0.2" warning "^4.0.2"
react-rangeslider@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/react-rangeslider/-/react-rangeslider-2.2.0.tgz#4362b01f4f5a455f0815d371d496f69ca4c6b5aa"
integrity sha512-5K7Woa+cyqZ5wiW5+KhqGV+3+FiFxGKQ9rUxTMh52sObXVYEeBbfxFrp1eBvS8mRIxnUbHz9ppnFP0LhwOyNeg==
dependencies:
classnames "^2.2.3"
resize-observer-polyfill "^1.4.2"
react-redux@^7.2.0: react-redux@^7.2.0:
version "7.2.0" version "7.2.0"
resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-7.2.0.tgz#f970f62192b3981642fec46fd0db18a074fe879d" resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-7.2.0.tgz#f970f62192b3981642fec46fd0db18a074fe879d"
@ -9208,6 +9216,11 @@ requires-port@^1.0.0:
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff" resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
integrity sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8= integrity sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=
resize-observer-polyfill@^1.4.2:
version "1.5.1"
resolved "https://registry.yarnpkg.com/resize-observer-polyfill/-/resize-observer-polyfill-1.5.1.tgz#0e9020dd3d21024458d4ebd27e23e40269810464"
integrity sha512-LwZrotdHOo12nQuZlHEmtuXdqGoOD0OhaxopaNFxWzInpEgaLWoVuAMbTzixuosCx2nEG58ngzW3vxdWoxIgdg==
resolve-cwd@^2.0.0: resolve-cwd@^2.0.0:
version "2.0.0" version "2.0.0"
resolved "https://registry.yarnpkg.com/resolve-cwd/-/resolve-cwd-2.0.0.tgz#00a9f7387556e27038eae232caa372a6a59b665a" resolved "https://registry.yarnpkg.com/resolve-cwd/-/resolve-cwd-2.0.0.tgz#00a9f7387556e27038eae232caa372a6a59b665a"