2021-01-04 07:48:38 +01:00
|
|
|
import React, {useState, useEffect} from "react";
|
|
|
|
import PropTypes from "prop-types";
|
|
|
|
import { Box, Button } from "grommet";
|
2021-01-05 17:58:57 +01:00
|
|
|
import axios from "axios";
|
2021-01-04 07:48:38 +01:00
|
|
|
|
2021-01-05 17:58:57 +01:00
|
|
|
import { CAMERA_URL, LIGHTS_URL } from "../config";
|
2021-01-04 07:48:38 +01:00
|
|
|
|
|
|
|
function SmartHome(props) {
|
|
|
|
const [ idx, setIdx ] = useState(0);
|
|
|
|
useEffect(() => {
|
|
|
|
const id = setInterval(() => setIdx(i => i + 1), 20);
|
|
|
|
return () => clearInterval(id);
|
|
|
|
}, []);
|
2021-01-05 17:58:57 +01:00
|
|
|
function turnOn() {
|
|
|
|
axios.get(`${LIGHTS_URL}/on`);
|
|
|
|
}
|
|
|
|
function turnOff() {
|
|
|
|
axios.get(`${LIGHTS_URL}/off`);
|
|
|
|
}
|
2021-01-04 07:48:38 +01:00
|
|
|
return (
|
|
|
|
<Box
|
|
|
|
align="center"
|
|
|
|
background="light-1"
|
|
|
|
width="100vw"
|
|
|
|
justify="center"
|
|
|
|
direction="column"
|
|
|
|
alignContent="center"
|
|
|
|
height="95vh"
|
|
|
|
>
|
|
|
|
<img src={`${CAMERA_URL}?id=${idx}`} />
|
2021-01-05 17:58:57 +01:00
|
|
|
<Box direction="row" margin="1em 0">
|
|
|
|
<Button primary size="large" onClick={turnOn}
|
|
|
|
label="Turn On Lights" margin="0 0 0 0" />
|
|
|
|
<Button primary size="large" onClick={turnOff}
|
|
|
|
label="Turn Off Lights" margin="0 0 0 1em" />
|
|
|
|
</Box>
|
2021-01-04 07:48:38 +01:00
|
|
|
<Button primary size="large" onClick={props.close}
|
2021-01-05 17:58:57 +01:00
|
|
|
label="Dismiss" margin="0" />
|
2021-01-04 07:48:38 +01:00
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
SmartHome.propTypes = {
|
|
|
|
data: PropTypes.object,
|
|
|
|
close: PropTypes.func
|
|
|
|
};
|
|
|
|
|
|
|
|
SmartHome.pluginName = "Smart Home";
|
|
|
|
|
|
|
|
export default SmartHome;
|