import React from "react"; import Light from "./Light"; import SmartPlug from "./SmartPlug"; import Sensor from "./Sensor"; import { ButtonDimmer, KnobDimmer } from "./Dimmer"; import Switcher from "./Switch"; import { Segment, Grid, Header, Button, Icon } from "semantic-ui-react"; import { RemoteService } from "../../../remote"; import { connect } from "react-redux"; import DeviceSettingsModal from "./DeviceSettingsModal"; class Device extends React.Component { constructor(props) { super(props); this.modalRef = React.createRef(); this.edit = this.edit.bind(this); this.resetSmartPlug = this.resetSmartPlug.bind(this); } edit() { console.log("editing device with id=" + this.props.id); this.modalRef.current.openModal(); } resetSmartPlug() { this.props .smartPlugReset(this.props.id) .catch((err) => console.error(`Smart plug reset error`, err)); } renderDeviceComponent() { switch (this.props.device.kind) { case "regularLight": return ; case "sensor": return ; case "motionSensor": return ; case "buttonDimmer": return ; case "knobDimmer": return ; case "smartPlug": return ; case "switch": return ; case "dimmableLight": return ; default: throw new Error("Device type unknown"); } } render() { return ( {this.renderDeviceComponent()}
{this.props.device.name}
{this.props.device.kind === "smartPlug" ? ( ) : null}
); } } const mapStateToProps = (state, ownProps) => ({ device: state.devices[ownProps.id], }); const DeviceContainer = connect(mapStateToProps, RemoteService)(Device); export default DeviceContainer;