2020-03-17 16:38:03 +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
|
|
|
import React, { Component } from "react";
|
|
|
|
import {
|
|
|
|
CircularInput,
|
|
|
|
CircularProgress,
|
|
|
|
CircularTrack,
|
|
|
|
} from "react-circular-input";
|
|
|
|
import { errorStyle, sensorText, style, valueStyle } from "./SensorStyle";
|
|
|
|
import { StyledDiv } from "./styleComponents";
|
2020-03-17 16:38:03 +00:00
|
|
|
import Settings from "./DeviceSettings";
|
2020-03-23 20:24:17 +00:00
|
|
|
import { Image } from "semantic-ui-react";
|
|
|
|
import { imageStyle, nameStyle } from "./DigitalSensorStyle";
|
2020-03-17 16:38:03 +00:00
|
|
|
|
|
|
|
export default class DigitalSensor extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
value: false, // This value is a boolean, was this type of sensor returns presence/absence
|
|
|
|
};
|
|
|
|
|
|
|
|
this.iconOn = "/img/sensorOn.svg";
|
2020-03-23 20:24:17 +00:00
|
|
|
this.iconOff = "/img/sensorOff.svg";
|
2020-03-17 16:38:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setName = () => {
|
2020-03-23 20:24:17 +00:00
|
|
|
if (this.props.device.name.length > 15) {
|
|
|
|
return this.props.device.name.slice(0, 12) + "...";
|
2020-03-17 16:38:03 +00:00
|
|
|
}
|
|
|
|
return this.props.device.name;
|
|
|
|
};
|
|
|
|
|
|
|
|
getIcon = () => {
|
2020-03-23 20:24:17 +00:00
|
|
|
if (this.state.value) {
|
2020-03-17 16:38:03 +00:00
|
|
|
return this.iconOn;
|
|
|
|
}
|
|
|
|
return this.iconOff;
|
|
|
|
};
|
|
|
|
|
2020-03-23 20:24:17 +00:00
|
|
|
componentDidMount() {}
|
2020-03-17 16:38:03 +00:00
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2020-03-17 22:24:40 +00:00
|
|
|
<StyledDiv>
|
2020-03-17 16:38:03 +00:00
|
|
|
<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)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<Image src={this.getIcon()} style={imageStyle} />
|
2020-03-17 16:38:03 +00:00
|
|
|
<h5 style={nameStyle}>{this.props.device.name}</h5>
|
|
|
|
</StyledDiv>
|
2020-03-23 20:24:17 +00:00
|
|
|
);
|
2020-03-17 16:38:03 +00:00
|
|
|
}
|
|
|
|
}
|