btn-dimmer and knob-dimmer update

This commit is contained in:
britea 2020-03-25 19:58:19 +01:00
parent 9fa9a2f90f
commit 67496b11a0
4 changed files with 67 additions and 15 deletions

View file

@ -211,15 +211,19 @@ export var call = {
headers: { Authorization: "Bearer " + tkn },
})
.then((res) => {
if (res.status === 200 && data.device === "switch") {
if (
res.status === 200 &&
(data.device === "switch" ||
data.device === "buttonDimmer" ||
data.device === "knobDimmer")
) {
let type = "lightId=";
if (data.device === "switch") {
type = "switchableId=";
}
data.params.lights.forEach((e) => {
let urlUp =
config +
data.device +
"/" +
res.data.id +
"/lights?switchableId=" +
e;
config + data.device + "/" + res.data.id + "/lights?" + type + e;
axios.post(
urlUp,
{},
@ -239,7 +243,11 @@ export var call = {
headers: { Authorization: "Bearer " + tkn },
});
// also for btn/knob dimmer
if (typeDevice === "switch/operate") {
if (
typeDevice === "switch/operate" ||
typeDevice === "buttonDimmer/dim" ||
typeDevice === "knobDimmer/dimTo"
) {
promiseRes = promiseRes.then((e) => {
if (e.status === 200) {
e.data.forEach((device) => socket.invokeCallbacks(device));

View file

@ -29,6 +29,8 @@ import {
knobContainer,
} from "./DimmerStyle";
import { call } from "../../../client_server";
export class ButtonDimmer extends Component {
constructor(props) {
super(props);
@ -36,10 +38,24 @@ export class ButtonDimmer extends Component {
}
increaseIntensity = () => {
console.log("Increase!");
let data = {
dimType: "UP",
id: this.props.device.id,
};
call.deviceUpdate(data, "buttonDimmer/dim").then((res) => {
if (res.status === 200) {
}
});
};
decreaseIntensity = () => {
console.log("Decrease!");
let data = {
dimType: "DOWN",
id: this.props.device.id,
};
call.deviceUpdate(data, "buttonDimmer/dim").then((res) => {
if (res.status === 200) {
}
});
};
componentDidMount() {}
@ -56,10 +72,10 @@ export class ButtonDimmer extends Component {
/>
<img alt="icon" src="/img/buttonDimmer.svg" />
<span className="knob">{this.props.device.name}</span>
<PlusPanel onClick={this.increaseIntensity}>
<PlusPanel name="UP" onClick={this.increaseIntensity}>
<span>&#43;</span>
</PlusPanel>
<MinusPanel onClick={this.decreaseIntensity}>
<MinusPanel name="DOWN" onClick={this.decreaseIntensity}>
<span>&minus;</span>
</MinusPanel>
</ButtonDimmerContainer>
@ -76,7 +92,26 @@ export class KnobDimmer extends Component {
};
}
componentDidMount() {}
setIntensity = (newValue) => {
let val = Math.round(newValue * 100) <= 1 ? 1 : Math.round(newValue * 100);
let data = {
id: this.props.device.id,
intensity: val,
};
call.deviceUpdate(data, "knobDimmer/dimTo").then((res) => {
if (res.status === 200) {
this.setState({
value: val,
});
}
});
};
componentDidMount() {
this.setState({
value: 1,
});
}
render() {
return (
@ -90,8 +125,8 @@ export class KnobDimmer extends Component {
/>
<CircularInput
style={KnobDimmerStyle}
value={this.state.value}
onChange={(value) => this.setState({ value: value })}
value={+(Math.round(this.state.value / 100 + "e+2") + "e-2")}
onChange={this.setIntensity}
>
<text
style={textStyle}

View file

@ -107,6 +107,12 @@ export default class NewDevice extends Component {
case "switch":
data.params["lights"] = this.state.lightsAttached;
break;
case "buttonDimmer":
data.params["lights"] = this.state.lightsAttached;
break;
case "knobDimmer":
data.params["lights"] = this.state.lightsAttached;
break;
default:
break;
}

View file

@ -40,6 +40,9 @@ export default class ModalWindow extends Component {
image: this.state.img,
};
this.props.addRoom(data);
this.setState({
name: "Device",
});
this.closeModal();
};