/** 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. 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. **/ import React, {Component} from 'react'; import {StyledDiv} from "./styleComponents"; import Settings from "./DeviceSettings"; import {Image} from "semantic-ui-react"; import {energyConsumedStyle, imageStyle, nameStyle} from "./SmartPlugStyle"; 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; }; resetEnergyConsumedValue = () => { // In the settings form there must be an option to restore this value // along with the rename feature. } componentDidMount() { } render(){ return ( {} : this.onClickDevice} style={{textAlign: "center"}}> this.props.onChangeData(id, newSettings)}/>

{this.state.energyConsumed} KWh

{this.props.device.name}
) } }