From 65756d0dc9122ccd9872fb80c26e6ffe68e894ce Mon Sep 17 00:00:00 2001 From: britea Date: Sun, 3 May 2020 14:39:44 +0200 Subject: [PATCH] firx videocamera turn on/off --- .../components/dashboard/devices/Device.js | 6 +++- .../dashboard/devices/Thermostats.js | 3 +- .../components/dashboard/devices/Videocam.js | 32 +++++++++++++++++-- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/smart-hut/src/components/dashboard/devices/Device.js b/smart-hut/src/components/dashboard/devices/Device.js index 6a251b3..dc2af8b 100644 --- a/smart-hut/src/components/dashboard/devices/Device.js +++ b/smart-hut/src/components/dashboard/devices/Device.js @@ -172,7 +172,11 @@ class Device extends React.Component { )} - + {this.renderDeviceComponent()} diff --git a/smart-hut/src/components/dashboard/devices/Thermostats.js b/smart-hut/src/components/dashboard/devices/Thermostats.js index ab08fa1..73423b5 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) { @@ -144,7 +143,7 @@ class Thermostats extends Component { ? this.props.device.mode !== "OFF" : this.props.stateOrDevice.on } - slider + toggle style={toggle} onChange={(e, val) => this.setMode(val.checked)} /> diff --git a/smart-hut/src/components/dashboard/devices/Videocam.js b/smart-hut/src/components/dashboard/devices/Videocam.js index c434be0..4313088 100644 --- a/smart-hut/src/components/dashboard/devices/Videocam.js +++ b/smart-hut/src/components/dashboard/devices/Videocam.js @@ -2,7 +2,7 @@ import React, { Component } from "react"; import { StyledDivCamera } from "./styleComponents"; -import { Grid } from "semantic-ui-react"; +import { Grid, Checkbox } from "semantic-ui-react"; import { RemoteService } from "../../../remote"; import { endpointURL } from "../../../endpoint"; import { connect } from "react-redux"; @@ -12,6 +12,8 @@ class Videocam extends Component { constructor(props) { super(props); this.state = { selectedVideo: undefined }; + + this.setOnOff = this.setOnOff.bind(this); } openModal = () => { @@ -26,6 +28,23 @@ class Videocam extends Component { }); }; + setOnOff(onOff) { + const turn = onOff; + if (this.props.tab === "Devices") { + this.props + .saveDevice({ ...this.props.device, on: turn }) + .then((res) => + turn ? this.refs.vidRef.play() : this.refs.vidRef.pause() + ) + .catch((err) => console.error("videocamera update error", err)); + } else { + this.props.updateState( + { id: this.props.state.id, on: turn }, + this.props.state.kind + ); + } + } + get url() { return endpointURL() + this.props.device.path; } @@ -35,7 +54,7 @@ class Videocam extends Component {
-
@@ -51,6 +70,15 @@ class Videocam extends Component { + this.setOnOff(val.checked)} + />
);