2020-03-15 14:50:25 +00:00
|
|
|
/**
|
|
|
|
Users can add dimmers, a particular kind of switch that can also modify the intensity level of a given light.
|
|
|
|
There are two types of dimmers:
|
|
|
|
• A dimmer with state stores a given intensity level and sets the light to that level. <-- StatefulDimmer
|
|
|
|
• A dimmer without state can just increase or decrease the intensity of a light. <-- DefualtDimmer
|
|
|
|
|
|
|
|
The user can change the state of a dimmer through an intuitive UI in SmartHut .
|
|
|
|
**/
|
|
|
|
|
2020-03-25 16:20:53 +00:00
|
|
|
import React, { Component } from "react";
|
2020-03-25 11:13:15 +00:00
|
|
|
import {
|
2020-03-25 16:20:53 +00:00
|
|
|
CircularInput,
|
|
|
|
CircularProgress,
|
|
|
|
CircularThumb,
|
2020-03-25 11:13:15 +00:00
|
|
|
} from "react-circular-input";
|
2020-03-25 16:20:53 +00:00
|
|
|
import {
|
|
|
|
ButtonDimmerContainer,
|
|
|
|
MinusPanel,
|
|
|
|
PlusPanel,
|
|
|
|
ThumbText,
|
|
|
|
} from "./styleComponents";
|
2020-03-25 11:13:15 +00:00
|
|
|
import {
|
2020-03-25 16:20:53 +00:00
|
|
|
CircularThumbStyle,
|
|
|
|
KnobDimmerStyle,
|
|
|
|
KnobProgress,
|
|
|
|
textStyle,
|
|
|
|
knobIcon,
|
|
|
|
knobContainer,
|
2020-03-25 11:13:15 +00:00
|
|
|
} from "./DimmerStyle";
|
2020-04-10 15:25:52 +00:00
|
|
|
import { RemoteService } from "../../../remote";
|
|
|
|
import { connect } from "react-redux";
|
2020-03-25 18:58:19 +00:00
|
|
|
|
2020-04-10 15:25:52 +00:00
|
|
|
export class ButtonDimmerComponent extends Component {
|
2020-03-25 16:20:53 +00:00
|
|
|
increaseIntensity = () => {
|
2020-04-11 16:29:32 +00:00
|
|
|
this.props
|
|
|
|
.buttonDimmerDim(this.props.id, "UP")
|
|
|
|
.catch((err) => console.error("button dimmer increase error", err));
|
2020-03-25 16:20:53 +00:00
|
|
|
};
|
2020-04-10 22:42:23 +00:00
|
|
|
|
2020-03-25 16:20:53 +00:00
|
|
|
decreaseIntensity = () => {
|
2020-04-11 16:29:32 +00:00
|
|
|
this.props
|
|
|
|
.buttonDimmerDim(this.props.id, "DOWN")
|
|
|
|
.catch((err) => console.error("button dimmer decrease error", err));
|
2020-03-25 16:20:53 +00:00
|
|
|
};
|
2020-03-23 20:24:17 +00:00
|
|
|
|
2020-03-25 16:20:53 +00:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<ButtonDimmerContainer>
|
|
|
|
<img alt="icon" src="/img/buttonDimmer.svg" />
|
2020-04-11 16:29:32 +00:00
|
|
|
<span className="knob">Button Dimmer</span>
|
2020-03-25 18:58:19 +00:00
|
|
|
<PlusPanel name="UP" onClick={this.increaseIntensity}>
|
2020-03-25 16:20:53 +00:00
|
|
|
<span>+</span>
|
|
|
|
</PlusPanel>
|
2020-03-25 18:58:19 +00:00
|
|
|
<MinusPanel name="DOWN" onClick={this.decreaseIntensity}>
|
2020-03-25 16:20:53 +00:00
|
|
|
<span>−</span>
|
|
|
|
</MinusPanel>
|
|
|
|
</ButtonDimmerContainer>
|
|
|
|
);
|
|
|
|
}
|
2020-03-15 14:50:25 +00:00
|
|
|
}
|
|
|
|
|
2020-04-10 15:25:52 +00:00
|
|
|
export class KnobDimmerComponent extends Component {
|
2020-03-25 18:58:19 +00:00
|
|
|
setIntensity = (newValue) => {
|
2020-04-10 22:42:23 +00:00
|
|
|
const val = Math.round(newValue * 100);
|
2020-04-11 16:29:32 +00:00
|
|
|
this.props
|
|
|
|
.knobDimmerDimTo(this.props.id, val)
|
|
|
|
.catch((err) => console.error("knob dimmer set intensity error", err));
|
2020-03-25 18:58:19 +00:00
|
|
|
};
|
|
|
|
|
2020-04-11 16:29:32 +00:00
|
|
|
get intensity() {
|
|
|
|
return this.props.device.intensity || 0;
|
|
|
|
}
|
|
|
|
|
2020-03-25 16:20:53 +00:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div style={knobContainer}>
|
|
|
|
<CircularInput
|
|
|
|
style={KnobDimmerStyle}
|
2020-04-11 16:29:32 +00:00
|
|
|
value={+(Math.round(this.intensity / 100 + "e+2") + "e-2")}
|
2020-03-25 18:58:19 +00:00
|
|
|
onChange={this.setIntensity}
|
2020-03-25 16:20:53 +00:00
|
|
|
>
|
|
|
|
<text
|
|
|
|
style={textStyle}
|
|
|
|
x={100}
|
|
|
|
y={120}
|
|
|
|
textAnchor="middle"
|
|
|
|
dy="0.3em"
|
|
|
|
fontWeight="bold"
|
|
|
|
>
|
2020-04-10 22:42:23 +00:00
|
|
|
Knob Dimmer
|
2020-03-25 16:20:53 +00:00
|
|
|
</text>
|
|
|
|
<CircularProgress
|
2020-04-11 16:29:32 +00:00
|
|
|
style={{ ...KnobProgress, opacity: this.intensity + 0.1 }}
|
2020-03-25 16:20:53 +00:00
|
|
|
/>
|
|
|
|
<CircularThumb style={CircularThumbStyle} />
|
|
|
|
<ThumbText color={"#1a2849"} />
|
|
|
|
</CircularInput>
|
|
|
|
<img alt="Knob Icon" style={knobIcon} src="/img/knobDimmer.svg" />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2020-03-15 14:50:25 +00:00
|
|
|
}
|
2020-04-10 15:25:52 +00:00
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => ({
|
|
|
|
device: state.devices[ownProps.id],
|
|
|
|
});
|
|
|
|
const conn = connect(mapStateToProps, RemoteService);
|
|
|
|
|
|
|
|
export const KnobDimmer = conn(KnobDimmerComponent);
|
|
|
|
export const ButtonDimmer = conn(ButtonDimmerComponent);
|