2020-03-15 14:50:25 +00:00
|
|
|
/**
|
|
|
|
A smart plug is a plug that has a boolean internal state, i.e., that can be turned on or off, either with the
|
|
|
|
SmartHut interface or by a switch.
|
2020-03-17 22:24:40 +00:00
|
|
|
The smart plug also stores the total energy consumed while the plug is active, in terms of kilowatt-hours 2(kWh) .
|
|
|
|
The user can reset this value.
|
2020-03-15 14:50:25 +00:00
|
|
|
**/
|
|
|
|
import React, {Component} from 'react';
|
2020-03-17 16:38:03 +00:00
|
|
|
import {StyledDiv} from "./styleComponents";
|
2020-03-15 14:50:25 +00:00
|
|
|
import Settings from "./DeviceSettings";
|
|
|
|
import {Image} from "semantic-ui-react";
|
2020-03-17 16:38:03 +00:00
|
|
|
import {energyConsumedStyle, imageStyle, nameStyle} from "./SmartPlugStyle";
|
2020-03-15 14:50:25 +00:00
|
|
|
|
|
|
|
export default class SmartPlug extends Component {
|
|
|
|
constructor(props){
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
turnedOn: false,
|
|
|
|
energyConsumed : 0 // kWh
|
|
|
|
};
|
|
|
|
this.iconOn = "/img/smart-plug.svg";
|
|
|
|
this.iconOff = "/img/smart-plug-off.svg"
|
|
|
|
}
|
|
|
|
|
|
|
|
onClickDevice = () => {
|
|
|
|
this.setState((prevState) => ({turnedOn: !prevState.turnedOn}));
|
|
|
|
};
|
|
|
|
|
|
|
|
getIcon = () => {
|
|
|
|
if(this.state.turnedOn){
|
|
|
|
return this.iconOn;
|
|
|
|
}
|
|
|
|
return this.iconOff;
|
|
|
|
};
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
}
|
|
|
|
|
|
|
|
render(){
|
|
|
|
return (
|
2020-03-17 22:24:40 +00:00
|
|
|
<StyledDiv onClick={this.props.edit.mode ? () => {} : this.onClickDevice}>
|
2020-03-15 14:50:25 +00:00
|
|
|
<Settings
|
|
|
|
deviceId={this.props.device.id}
|
|
|
|
edit={this.props.edit}
|
|
|
|
onChangeData={(id, newSettings) => this.props.onChangeData(id, newSettings)}/>
|
|
|
|
<Image src={this.getIcon()} style={imageStyle}/>
|
|
|
|
<h4 style={energyConsumedStyle}>{this.state.energyConsumed} KWh</h4>
|
|
|
|
<h5 style={nameStyle}>{this.props.device.name}</h5>
|
|
|
|
</StyledDiv>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|