57 lines
1.6 KiB
JavaScript
57 lines
1.6 KiB
JavaScript
|
/**
|
||
|
* Users can add on-off switches. A on-off switch can turn on (or off) lights.
|
||
|
* If a light has an intensity level, when it gets switched back on, it gets the last available
|
||
|
* intensity level that was set by the user (or 100% if no such level exists).
|
||
|
* The user can change the state of a switch through the SmartHut interface.
|
||
|
*/
|
||
|
|
||
|
import React, {Component} from 'react';
|
||
|
import {StyledDiv} from "./styleComponents";
|
||
|
import Settings from "./DeviceSettings";
|
||
|
import {Image} from "semantic-ui-react";
|
||
|
import {imageStyle, nameStyle} from "./SwitchStyle";
|
||
|
|
||
|
export default class Switch extends Component {
|
||
|
constructor(props){
|
||
|
super(props);
|
||
|
this.state = {
|
||
|
turnedOn: false,
|
||
|
pointingLights : []
|
||
|
};
|
||
|
this.iconOn = "/img/switchOn.svg";
|
||
|
this.iconOff = "/img/switchOff.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 (
|
||
|
<StyledDiv onClick={this.props.edit ? () => {} : this.onClickDevice} style={{textAlign: "center"}}>
|
||
|
<Settings
|
||
|
deviceId={this.props.device.id}
|
||
|
edit={this.props.edit}
|
||
|
onChangeData={(id, newSettings) => this.props.onChangeData(id, newSettings)}/>
|
||
|
<Image src={this.getIcon()} style={imageStyle}/>
|
||
|
<h5 style={nameStyle}>{this.props.device.name}</h5>
|
||
|
</StyledDiv>
|
||
|
)
|
||
|
}
|
||
|
}
|