Skip to content
This repository was archived by the owner on Nov 21, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
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
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM node:10

# Create directory
WORKDIR /usr/src/app

# Copy Package.json
COPY package*.json ./

RUN npm install

# Copy app source
COPY . .

# !! MAKE SURE THIS IS THE RIGHT PORT YOU WANT TO USE !!
EXPOSE 3000

CMD ["node", "index.js"]
48 changes: 48 additions & 0 deletions controllers/plug_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,53 @@ module.exports = {
"is_active": localStorage.getItem(req.params.plugID)
});
}
},

getSmartPlug(req, res, next) {
// Return Smartplug details

AuthenticationManager.getSessionKey().then(sessionkey => {

// Check if session key is valid
if (sessionkey != "ERROR") {

axios({
method: 'get',
url: 'https://plug.homewizard.com/plugs',
headers: {
"x-session-token": sessionkey
}
})
.then(response => {
response.data.map((smartplug) => {

// Check if no smartplugs exist
if (smartplug.length == 0) {
res.status(200).send(new ApiResponse("No smartplugs found", 200));
} else {

// Create custom response based on response data
res.status(200).send({
"id": smartplug.id,
"name": smartplug.name,
"online": smartplug.online,
"latitude": smartplug.latitude,
"longtitude": smartplug.longtitude,
"timeZone": smartplug.timeZone,
"firmwareUpdateAvailable": smartplug.firmwareUpdateAvailable
});
}
})
})
.catch(e => {
// Cannot communicate with HWL, returning error
logger.error("Failed to communicate with HWL! ERROR: ", e.message);
res.status(503).send(new ApiResponse(e.message, 503));
});
} else {
// Session key is invalid
res.status(503).send(new ApiResponse("Invalid session key! Check the logs for more details about this problem ", 503));
}
});
}
}
41 changes: 30 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions routes/plug_routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const PlugController = require('../controllers/plug_controller');

// Plug routes
routes.get('/plug', PlugController.getAllPlugs);
routes.get('/smartplug', PlugController.getSmartPlug);
routes.post('/act/smartplug/:smartPlugID/plug/:plugID', PlugController.switchPlug);
routes.get('/act/smartplug/:smartPlugID/plug/:plugID', PlugController.plugState);

Expand Down