Fixed warning and merge in thermostats

This commit is contained in:
Claudio Maggioni (maggicl) 2020-05-03 16:37:04 +02:00
parent 74a5e49776
commit f6f46918c6
6 changed files with 35 additions and 86 deletions

View file

@ -255,8 +255,6 @@ class AutomationSaveModal extends Component {
} }
_checkNewTrigger(trigger) { _checkNewTrigger(trigger) {
const auxDevice = this.props.devices[trigger.device];
// Check for missing fields for creation // Check for missing fields for creation
const error = { const error = {
result: false, result: false,
@ -271,6 +269,8 @@ class AutomationSaveModal extends Component {
case "rangeTrigger": case "rangeTrigger":
if (!trigger.device || !trigger.operand || !trigger.value) return error; if (!trigger.device || !trigger.operand || !trigger.value) return error;
break; break;
default:
throw new Error("theoretically unreachable statement");
} }
const isNotDuplicate = !this.state.triggerList.some( const isNotDuplicate = !this.state.triggerList.some(
@ -345,6 +345,8 @@ class AutomationSaveModal extends Component {
return "" + trigger.device + trigger.on; return "" + trigger.device + trigger.on;
case "rangeTrigger": case "rangeTrigger":
return "" + trigger.device + trigger.operand + trigger.value; return "" + trigger.device + trigger.operand + trigger.value;
default:
throw new Error("theoretically unreachable statement");
} }
}; };

View file

@ -1,4 +1,4 @@
import React, { Component, useState, useEffect } from "react"; import React, { Component } from "react";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { RemoteService } from "../../remote"; import { RemoteService } from "../../remote";
import "./Automations.css"; import "./Automations.css";

View file

@ -4,10 +4,6 @@ import { RemoteService } from "../../remote";
import { Card, Segment, Header, Icon } from "semantic-ui-react"; import { Card, Segment, Header, Icon } from "semantic-ui-react";
class HostsPanel extends Component { class HostsPanel extends Component {
constructor(props) {
super(props);
}
render() { render() {
return ( return (
<Card.Group centered style={{ paddingTop: "3rem" }}> <Card.Group centered style={{ paddingTop: "3rem" }}>

View file

@ -7,7 +7,7 @@ import Switcher from "./Switch";
import Videocam from "./Videocam"; import Videocam from "./Videocam";
import Curtains from "./Curtain"; import Curtains from "./Curtain";
import Thermostat from "./Thermostats"; import Thermostat from "./Thermostats";
import { Segment, Grid, Header, Button, Icon, Card } from "semantic-ui-react"; import { Header, Button, Icon, Card } from "semantic-ui-react";
import { RemoteService } from "../../../remote"; import { RemoteService } from "../../../remote";
import { connect } from "react-redux"; import { connect } from "react-redux";
import DeviceSettingsModal from "./DeviceSettingsModal"; import DeviceSettingsModal from "./DeviceSettingsModal";
@ -157,11 +157,8 @@ class Device extends React.Component {
} }
render() { render() {
{
return ( return (
<Card <Card style={{ height: this.props.tab === "Devices" ? "23em" : "27em" }}>
style={{ height: this.props.tab === "Devices" ? "23em" : "27em" }}
>
<Card.Content> <Card.Content>
<Card.Header textAlign="center"> <Card.Header textAlign="center">
<Header as="h3">{this.deviceName}</Header> <Header as="h3">{this.deviceName}</Header>
@ -191,7 +188,6 @@ class Device extends React.Component {
); );
} }
} }
}
const mapStateToProps = (state, ownProps) => ({ const mapStateToProps = (state, ownProps) => ({
get stateOrDevice() { get stateOrDevice() {

View file

@ -27,7 +27,6 @@ class Thermostats extends Component {
console.log(this.state); console.log(this.state);
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.setTargetTemperature = this.setTargetTemperature.bind(this);
} }
setMode(mode) { setMode(mode) {
@ -88,43 +87,6 @@ class Thermostats extends Component {
} }
} }
setTargetTemperature(newTemp) {
if (this.state.timeout) {
clearTimeout(this.state.timeout);
}
this.setState({
newTemp,
timeout: setTimeout(() => {
this.saveTargetTemperature(newTemp);
this.setState({
targetTemperature: this.state.targetTemperature,
timeout: null,
});
}, 100),
});
}
saveTargetTemperature(targetTemperature) {
if (this.props.tab === "Devices") {
this.props
.saveDevice({
...this.props.device,
turnOn: this.props.device.mode !== "OFF",
targetTemperature,
})
.catch((err) => console.error("thermostat update error", err));
} else {
this.props.updateState(
{
id: this.props.stateOrDevice.id,
targetTemperature: targetTemperature,
},
this.props.stateOrDevice.kind
);
}
}
setTargetTemperature() { setTargetTemperature() {
this.saveTargetTemperature(this.state.targetTemperature); this.saveTargetTemperature(this.state.targetTemperature);
} }

View file

@ -1,12 +1,5 @@
import React, { Component } from "react"; import React, { Component } from "react";
import { import { Menu, Grid, Responsive, Dropdown } from "semantic-ui-react";
Menu,
Button,
Grid,
Icon,
Responsive,
Dropdown,
} from "semantic-ui-react";
import HostModal from "../components/HostModal"; import HostModal from "../components/HostModal";
import { RemoteService } from "../remote"; import { RemoteService } from "../remote";
import { connect } from "react-redux"; import { connect } from "react-redux";