Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update plug_controller.js #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update plug_controller.js
Added support for curtains, type brel_ud_curtain
  • Loading branch information
RoMaTiX99 authored May 20, 2024
commit 0dc477a0a233c2e55e5c4a0d57c106b4d0a7c40c
24 changes: 22 additions & 2 deletions controllers/plug_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,28 @@ module.exports = {
res.status(400).send(new ApiResponse("Invalid value. For dimmers you should provide an integer between 0 and 100", 400));
}

} elseif(req.body.type && req.body.type.toLowerCase() === "brel_ud_curtain") {
// Device is a curtain, identified as "brel_ud_curtain"
// Variable to store wanted Action
let actionValue;

if (req.body.value.toLowerCase() === "up") {
actionValue = "Up";
} elseif(req.body.value.toLowerCase() === "stop"){
actionValue = "Stop";
} elseif(req.body.value.toLowerCase() === "down"){
actionValue = "Down";
} else {
res.status(400).send(new ApiResponse("Invalid value. For curtain typ brel_ud_curtain you should provide 'Up', 'Down' or 'Stop'", 400));
}

// create data object with selected Action
data = {
action: actionValue,
};

} else {
// Plug is not a dimmer, so should be a switch
// Plug is not a dimmer or curtain, so should be a switch
if (req.body.value && typeof(req.body.value) === "string") {
data = {
action: req.body.value.toLowerCase() === "on" ? "On" : "Off",
Expand Down Expand Up @@ -216,4 +236,4 @@ module.exports = {
res.status(503).send(new ApiResponse(e, 503));
});
}
}
}