import React from 'react'; import { Header, Button, Icon, Card, } from 'semantic-ui-react'; import { connect } from 'react-redux'; import Light from './Light'; import SmartPlug from './SmartPlug'; import Sensor from './Sensor'; import { ButtonDimmer, KnobDimmer } from './Dimmer'; import Switcher from './Switch'; import Videocam from './Videocam'; import Curtains from './Curtain'; import Thermostat from './Thermostats'; import { RemoteService } from '../../../remote'; import DeviceSettingsModal from './DeviceSettingsModal'; import mapStateToProps from '../../../deviceProps'; const centerComponent = { marginLeft: '50%', transform: 'translateX(-50%)', marginTop: '10%', marginBottom: '10%', }; 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); this.deleteState = this.deleteState.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)); } deleteState() { this.props.deleteState(this.props.id, this.props.stateOrDevice.kind); } renderDeviceComponent() { const mapKindToComponent = { curtains: Curtains, thermostat: Thermostat, regularLight: Light, sensor: Sensor, motionSensor: Sensor, buttonDimmer: ButtonDimmer, knobDimmer: KnobDimmer, smartPlug: SmartPlug, switch: Switcher, dimmableLight: Light, securityCamera: Videocam, }; if (!(this.props.type in mapKindToComponent)) { throw new Error(`device kind ${this.props.type} not known`); } return React.createElement( mapKindToComponent[this.props.type], { tab: this.props.tab, id: this.props.id, hostId: this.props.hostId, }, '', ); } deviceDescription() { return (
{this.props.stateOrDevice.kind === 'smartPlug' ? ( ) : null}
); } stateDescription() { return (
); } get deviceName() { return this.props.device.name; } render() { return (
{this.deviceName}
{this.props.roomName}
{this.renderDeviceComponent()}
{this.props.tab === 'Devices' ? this.deviceDescription() : this.props.tab === 'Scenes' && this.stateDescription()} {this.props.tab === 'Devices' ? ( ) : null}
); } } const DeviceContainer = connect(mapStateToProps, RemoteService)(Device); export default DeviceContainer;