Skip to content
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
6 changes: 3 additions & 3 deletions sonoff.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ server.get('/devices/:deviceId/status', function (req, res) {
});

//switch the device
server.get('/devices/:deviceId/:state', function (req, res) {
server.get('/devices/:deviceId/:index/:state', function (req, res) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, but this would break the compatibility with the existing implementation. Could you create a secound "get" with this parameter? You might want to export the functionality to a new function and call it by both paths.

function devices(deviceId, index, state, res) {
....
}

server.get('/devices/:deviceId/:index/:state', function (req, res) {
devices(req.params.deviceId, req.params.index, req.params.state, res)
}

server.get('/devices/:deviceId/:state', function (req, res) {
devices(req.params.deviceId, req.params.index, req.params.state, res)
}

log.log('GET | %s | %s ', req.method, req.url);
var d = devices.getDeviceState(req.params.deviceId);

Expand All @@ -66,12 +66,12 @@ server.get('/devices/:deviceId/:state', function (req, res) {
case "1":
case "ON":
res.sendStatus(200);
devices.turnOnDevice(req.params.deviceId);
devices.turnOnDevice(req.params.deviceId, req.params.index);
break;
case "0":
case "OFF":
res.sendStatus(200);
devices.turnOffDevice(req.params.deviceId);
devices.turnOffDevice(req.params.deviceId, req.params.index);
break;
default:
res.status(404).send('Sonoff device ' + req.params.deviceId + ' can not be switched to "' + req.params.state + '", only "ON" and "OFF" are supported currently');
Expand Down