diff --git a/smart-hut/src/client_server.js b/smart-hut/src/client_server.js
index 7736894..fdf1710 100644
--- a/smart-hut/src/client_server.js
+++ b/smart-hut/src/client_server.js
@@ -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));
diff --git a/smart-hut/src/components/dashboard/devices/Dimmer.js b/smart-hut/src/components/dashboard/devices/Dimmer.js
index c1b6b0d..8a79128 100644
--- a/smart-hut/src/components/dashboard/devices/Dimmer.js
+++ b/smart-hut/src/components/dashboard/devices/Dimmer.js
@@ -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 {
/>
{this.props.device.name}
-
+
+
-
+
−
@@ -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 {
/>
this.setState({ value: value })}
+ value={+(Math.round(this.state.value / 100 + "e+2") + "e-2")}
+ onChange={this.setIntensity}
>