diff --git a/smart-hut/src/components/dashboard/DevicePanel.js b/smart-hut/src/components/dashboard/DevicePanel.js index 7537b1b..28a9906 100644 --- a/smart-hut/src/components/dashboard/DevicePanel.js +++ b/smart-hut/src/components/dashboard/DevicePanel.js @@ -48,9 +48,7 @@ const mapStateToProps = (state, _) => ({ if (state.active.activeRoom === -1) { return Object.values(state.devices); } else { - console.log(state.active.activeRoom); const deviceArray = [...state.rooms[state.active.activeRoom].devices].sort(); - console.log(deviceArray); return deviceArray.map((id) => state.devices[id]); } }, diff --git a/smart-hut/src/components/dashboard/devices/Dimmer.js b/smart-hut/src/components/dashboard/devices/Dimmer.js index 25ac89c..d86b18e 100644 --- a/smart-hut/src/components/dashboard/devices/Dimmer.js +++ b/smart-hut/src/components/dashboard/devices/Dimmer.js @@ -60,23 +60,50 @@ export class ButtonDimmerComponent extends Component { } export class KnobDimmerComponent extends Component { - setIntensity = (newValue) => { - const val = Math.round(newValue * 100); + constructor(props) { + super(props); + + this.state = { + intensity: this.props.device.intensity || 0, + timeout: null + }; + + this.saveIntensity = this.saveIntensity.bind(this); + this.setIntensity = this.setIntensity.bind(this); + } + + setIntensity(intensity) { + intensity *= 100; + + if (this.state.timeout) { + clearTimeout(this.state.timeout); + } + + this.setState({ + intensity, + timeout: setTimeout(() => { + this.saveIntensity(); + this.setState({ + intensity: this.state.intensity, + timeout: null + }); + }, 100) + }); + } + + saveIntensity() { + const val = Math.round(this.state.intensity); this.props .knobDimmerDimTo(this.props.id, val) .catch((err) => console.error("knob dimmer set intensity error", err)); }; - get intensity() { - return this.props.device.intensity || 0; - } - render() { return (