2020-03-15 14:50:25 +00:00
|
|
|
/**
|
|
|
|
* Users can add sensors in their rooms.
|
|
|
|
* Sensors typically measure physical quantities in a room.
|
|
|
|
* You must support temperature sensors, humidity sensors, light sensors (which measure luminosity1).
|
|
|
|
* Sensors have an internal state that cannot be changed by the user.
|
|
|
|
* For this story, make the sensors return a constant value with some small random error.
|
|
|
|
*/
|
|
|
|
|
2020-03-23 20:24:17 +00:00
|
|
|
/*
|
2020-03-23 18:08:31 +00:00
|
|
|
|
|
|
|
OPTIONAL STATE
|
|
|
|
error: 2.4
|
|
|
|
|
|
|
|
<text style={errorStyle} x={100} y={100} textAnchor="middle" dy="0.6em" fontWeight="bold">
|
|
|
|
±{this.state.error}
|
|
|
|
</text>
|
|
|
|
|
|
|
|
|
|
|
|
errorStyle,
|
|
|
|
*/
|
|
|
|
|
2020-03-23 20:24:17 +00:00
|
|
|
import React, { Component } from "react";
|
|
|
|
import {
|
|
|
|
CircularInput,
|
|
|
|
CircularProgress,
|
|
|
|
CircularTrack,
|
|
|
|
} from "react-circular-input";
|
|
|
|
import { sensorText, style, valueStyle } from "./SensorStyle";
|
2020-03-17 22:24:40 +00:00
|
|
|
import Settings from "./DeviceSettings";
|
2020-03-23 20:24:17 +00:00
|
|
|
import { StyledDiv } from "./styleComponents";
|
2020-03-15 14:50:25 +00:00
|
|
|
|
2020-03-17 16:38:03 +00:00
|
|
|
export default class Sensor extends Component {
|
2020-03-17 22:24:40 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
turnedOn: false,
|
2020-03-23 18:08:31 +00:00
|
|
|
value: 0,
|
2020-03-15 14:50:25 +00:00
|
|
|
};
|
2020-03-23 20:24:17 +00:00
|
|
|
this.units = "";
|
2020-03-17 22:24:40 +00:00
|
|
|
}
|
2020-03-15 14:50:25 +00:00
|
|
|
|
2020-03-17 22:24:40 +00:00
|
|
|
setName = () => {
|
|
|
|
if (this.props.device.name.length > 15) {
|
2020-03-23 20:24:17 +00:00
|
|
|
return this.props.device.name.slice(0, 12) + "...";
|
2020-03-15 14:50:25 +00:00
|
|
|
}
|
2020-03-17 22:24:40 +00:00
|
|
|
return this.props.device.name;
|
|
|
|
};
|
2020-03-15 14:50:25 +00:00
|
|
|
|
2020-03-17 22:24:40 +00:00
|
|
|
componentDidMount() {
|
2020-03-23 20:24:17 +00:00
|
|
|
switch (this.props.device.sensor) {
|
2020-03-23 18:08:31 +00:00
|
|
|
case "TEMPERATURE":
|
|
|
|
this.units = "ºC";
|
|
|
|
break;
|
2020-03-23 20:24:17 +00:00
|
|
|
case "HUMIDITY":
|
2020-03-23 18:08:31 +00:00
|
|
|
this.units = "%";
|
|
|
|
break;
|
|
|
|
case "LIGHT":
|
|
|
|
this.units = "lm";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
this.units = "";
|
|
|
|
}
|
|
|
|
this.setState({
|
2020-03-23 20:24:17 +00:00
|
|
|
value: this.props.device.value,
|
2020-03-23 18:08:31 +00:00
|
|
|
});
|
2020-03-17 22:24:40 +00:00
|
|
|
}
|
2020-03-15 14:50:25 +00:00
|
|
|
|
2020-03-17 22:24:40 +00:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<StyledDiv>
|
|
|
|
<Settings
|
|
|
|
deviceId={this.props.device.id}
|
|
|
|
edit={this.props.edit}
|
2020-03-23 20:24:17 +00:00
|
|
|
onChangeData={(id, newSettings) =>
|
|
|
|
this.props.onChangeData(id, newSettings)
|
|
|
|
}
|
|
|
|
/>
|
2020-03-17 22:24:40 +00:00
|
|
|
|
2020-03-23 20:24:17 +00:00
|
|
|
<CircularInput value={this.state.value / 100} style={style}>
|
|
|
|
<CircularTrack />
|
|
|
|
<CircularProgress />
|
|
|
|
<text
|
|
|
|
style={valueStyle}
|
|
|
|
x={100}
|
|
|
|
y={80}
|
|
|
|
textAnchor="middle"
|
|
|
|
dy="0.3em"
|
|
|
|
fontWeight="bold"
|
|
|
|
>
|
|
|
|
{Math.round(this.state.value)}
|
|
|
|
{this.units}
|
2020-03-17 22:24:40 +00:00
|
|
|
</text>
|
2020-03-23 20:24:17 +00:00
|
|
|
<text
|
|
|
|
style={sensorText}
|
|
|
|
x={100}
|
|
|
|
y={150}
|
|
|
|
textAnchor="middle"
|
|
|
|
dy="0.3em"
|
|
|
|
fontWeight="bold"
|
|
|
|
>
|
2020-03-17 22:24:40 +00:00
|
|
|
{this.setName()}
|
|
|
|
</text>
|
|
|
|
</CircularInput>
|
|
|
|
</StyledDiv>
|
2020-03-23 20:24:17 +00:00
|
|
|
);
|
2020-03-17 22:24:40 +00:00
|
|
|
}
|
2020-03-09 12:52:27 +00:00
|
|
|
}
|