diff --git a/smart-hut/src/client_server.js b/smart-hut/src/client_server.js index fa20cd7..08e5a67 100644 --- a/smart-hut/src/client_server.js +++ b/smart-hut/src/client_server.js @@ -233,7 +233,7 @@ export var call = { let promiseRes = axios.put(config + url, data, { headers: { Authorization: "Bearer " + tkn }, }); - + // also for btn/knob dimmer if (typeDevice === "switch/operate") { promiseRes = promiseRes.then((e) => { if (e.status === 200) { diff --git a/smart-hut/src/components/HeaderController.js b/smart-hut/src/components/HeaderController.js index acc4259..e85fd0d 100644 --- a/smart-hut/src/components/HeaderController.js +++ b/smart-hut/src/components/HeaderController.js @@ -1,12 +1,7 @@ import React from "react"; import { Dropdown, Icon, Grid, Divider } from "semantic-ui-react"; import { Segment, Image } from "semantic-ui-react"; -import { - BrowserView, - MobileView, - isBrowser, - isMobile, -} from "react-device-detect"; +import { BrowserView, MobileView } from "react-device-detect"; const AvatarImage = () => ( @@ -22,16 +17,6 @@ const IconHomeImage = () => ( /> ); -const IconHomeImageMobile = () => ( - -); - const TitleImage = () => ; const BrowserStructure = (props) => ( diff --git a/smart-hut/src/components/SelectIcons.js b/smart-hut/src/components/SelectIcons.js index bbefcc1..3722168 100644 --- a/smart-hut/src/components/SelectIcons.js +++ b/smart-hut/src/components/SelectIcons.js @@ -1,5 +1,5 @@ import React, { Component } from "react"; -import { Button, Grid, Responsive } from "semantic-ui-react"; +import { Button, Grid } from "semantic-ui-react"; export default class SelectIcons extends Component { constructor(props) { diff --git a/smart-hut/src/components/dashboard/DevicePanel.js b/smart-hut/src/components/dashboard/DevicePanel.js index 4473904..ccbe36f 100644 --- a/smart-hut/src/components/dashboard/DevicePanel.js +++ b/smart-hut/src/components/dashboard/DevicePanel.js @@ -56,7 +56,7 @@ export default class DevicePanel extends Component { this.forceUpdate(); }; - getDevices() { + getDevices = () => { if (this.props.activeItem === -1) { call .getAllDevices() @@ -82,7 +82,7 @@ export default class DevicePanel extends Component { }) .catch((err) => {}); } - } + }; async addDevice(data) { const ds = await this.props.addDevice(data); @@ -96,10 +96,8 @@ export default class DevicePanel extends Component { const roomId = this.props.devices.filter( (d) => d.id === this.state.settingsDeviceId )[0].roomId; - console.log(roomId); data["id"] = this.state.settingsDeviceId; data["roomId"] = roomId; - console.log(data); call .deviceUpdate(data) .then((res) => { @@ -159,6 +157,7 @@ export default class DevicePanel extends Component { return ( { case "regularLight": return ( { case "sensor": return ( { case "buttonDimmer": return ( { case "smartPlug": return ( { case "switch": return ( { case "dimmableLight": return ( this.setState(Object.assign(this.state, e)); + this.stateCallback = (e) => { + this.setState(Object.assign(this.state, e)); + }; call.socketSubscribe(this.props.device.id, this.stateCallback); } @@ -95,7 +97,7 @@ export default class Sensor extends Component { dy="0.3em" fontWeight="bold" > - {Math.round(this.state.value)} + {+(Math.round(this.state.value + "e+2") + "e-2")} {this.units} { + this.setState( + Object.assign(this.state, { + energyConsumed: (e.totalConsumption / 1000).toFixed(3), + turnedOn: e.on, + }) + ); + }; + + call.socketSubscribe(this.props.device.id, this.stateCallback); + } + + componentWillUnmount() { + call.socketUnsubscribe(this.props.device.id, this.stateCallback); } onClickDevice = () => { diff --git a/smart-hut/src/components/modalform.js b/smart-hut/src/components/modalform.js index 1486e4e..41951fd 100644 --- a/smart-hut/src/components/modalform.js +++ b/smart-hut/src/components/modalform.js @@ -108,16 +108,6 @@ export default class ModalWindow extends Component { )} - - {this.props.type === "new" ? ( - - ) : ( - - )} - {this.props.type === "new" ? (