From f6f46918c6cdd1d56d26c009cf2c9fef1e0ee68a Mon Sep 17 00:00:00 2001 From: "Claudio Maggioni (maggicl)" Date: Sun, 3 May 2020 16:37:04 +0200 Subject: [PATCH] Fixed warning and merge in thermostats --- .../dashboard/AutomationCreationModal.js | 6 +- .../components/dashboard/AutomationsPanel.js | 2 +- .../src/components/dashboard/HostsPanel.js | 4 -- .../components/dashboard/devices/Device.js | 62 +++++++++---------- .../dashboard/devices/Thermostats.js | 38 ------------ smart-hut/src/views/HostsNavbar.js | 9 +-- 6 files changed, 35 insertions(+), 86 deletions(-) diff --git a/smart-hut/src/components/dashboard/AutomationCreationModal.js b/smart-hut/src/components/dashboard/AutomationCreationModal.js index f32abde..867f677 100644 --- a/smart-hut/src/components/dashboard/AutomationCreationModal.js +++ b/smart-hut/src/components/dashboard/AutomationCreationModal.js @@ -255,8 +255,6 @@ class AutomationSaveModal extends Component { } _checkNewTrigger(trigger) { - const auxDevice = this.props.devices[trigger.device]; - // Check for missing fields for creation const error = { result: false, @@ -271,6 +269,8 @@ class AutomationSaveModal extends Component { case "rangeTrigger": if (!trigger.device || !trigger.operand || !trigger.value) return error; break; + default: + throw new Error("theoretically unreachable statement"); } const isNotDuplicate = !this.state.triggerList.some( @@ -345,6 +345,8 @@ class AutomationSaveModal extends Component { return "" + trigger.device + trigger.on; case "rangeTrigger": return "" + trigger.device + trigger.operand + trigger.value; + default: + throw new Error("theoretically unreachable statement"); } }; diff --git a/smart-hut/src/components/dashboard/AutomationsPanel.js b/smart-hut/src/components/dashboard/AutomationsPanel.js index d4d828e..9d6c972 100644 --- a/smart-hut/src/components/dashboard/AutomationsPanel.js +++ b/smart-hut/src/components/dashboard/AutomationsPanel.js @@ -1,4 +1,4 @@ -import React, { Component, useState, useEffect } from "react"; +import React, { Component } from "react"; import { connect } from "react-redux"; import { RemoteService } from "../../remote"; import "./Automations.css"; diff --git a/smart-hut/src/components/dashboard/HostsPanel.js b/smart-hut/src/components/dashboard/HostsPanel.js index 21dd9c8..7b6ffac 100644 --- a/smart-hut/src/components/dashboard/HostsPanel.js +++ b/smart-hut/src/components/dashboard/HostsPanel.js @@ -4,10 +4,6 @@ import { RemoteService } from "../../remote"; import { Card, Segment, Header, Icon } from "semantic-ui-react"; class HostsPanel extends Component { - constructor(props) { - super(props); - } - render() { return ( diff --git a/smart-hut/src/components/dashboard/devices/Device.js b/smart-hut/src/components/dashboard/devices/Device.js index 6a251b3..ac13888 100644 --- a/smart-hut/src/components/dashboard/devices/Device.js +++ b/smart-hut/src/components/dashboard/devices/Device.js @@ -7,7 +7,7 @@ import Switcher from "./Switch"; import Videocam from "./Videocam"; import Curtains from "./Curtain"; 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 { connect } from "react-redux"; import DeviceSettingsModal from "./DeviceSettingsModal"; @@ -157,39 +157,35 @@ class Device extends React.Component { } render() { - { - return ( - - - -
{this.deviceName}
- {this.props.tab === "Scenes" ? ( -
{this.props.roomName}
- ) : ( - "" - )} -
+ return ( + + + +
{this.deviceName}
+ {this.props.tab === "Scenes" ? ( +
{this.props.roomName}
+ ) : ( + "" + )} +
- - {this.renderDeviceComponent()} - -
- - {this.props.tab === "Devices" - ? this.deviceDescription() - : this.stateDescription()} - - {this.props.tab === "Devices" ? ( - - ) : null} -
- ); - } + + {this.renderDeviceComponent()} + +
+ + {this.props.tab === "Devices" + ? 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 ab08fa1..c2012bd 100644 --- a/smart-hut/src/components/dashboard/devices/Thermostats.js +++ b/smart-hut/src/components/dashboard/devices/Thermostats.js @@ -27,7 +27,6 @@ class Thermostats extends Component { console.log(this.state); this.setMode = this.setMode.bind(this); this.setTargetTemperature = this.setTargetTemperature.bind(this); - this.setTargetTemperature = this.setTargetTemperature.bind(this); } 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() { this.saveTargetTemperature(this.state.targetTemperature); } diff --git a/smart-hut/src/views/HostsNavbar.js b/smart-hut/src/views/HostsNavbar.js index f0f37ab..0158346 100644 --- a/smart-hut/src/views/HostsNavbar.js +++ b/smart-hut/src/views/HostsNavbar.js @@ -1,12 +1,5 @@ import React, { Component } from "react"; -import { - Menu, - Button, - Grid, - Icon, - Responsive, - Dropdown, -} from "semantic-ui-react"; +import { Menu, Grid, Responsive, Dropdown } from "semantic-ui-react"; import HostModal from "../components/HostModal"; import { RemoteService } from "../remote"; import { connect } from "react-redux";