Skip to content

Commit

Permalink
feat(webserver): Provide mqtt config properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypfer committed Sep 13, 2021
1 parent ac19d5d commit 7e6962b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
17 changes: 17 additions & 0 deletions backend/lib/webserver/ValetudoRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ class ValetudoRouter {
*
* @param {object} options
* @param {import("../Configuration")} options.config
* @param {import("../core/ValetudoRobot")} options.robot
* @param {*} options.validator
*/
constructor(options) {
this.router = express.Router({mergeParams: true});

this.config = options.config;
this.robot = options.robot;
this.validator = options.validator;

//TODO: somewhat ugly here. Refactor?
Expand Down Expand Up @@ -73,6 +75,21 @@ class ValetudoRouter {
res.json(mqttConfig);
});

this.router.get("/config/interfaces/mqtt/properties", (req, res) => {
//It might make sense to pull this from the mqttController but that would introduce a dependency between the webserver and the mqttController :/
res.json({
defaults: {
identity: {
friendlyName: this.robot.getModelName() + " " + Tools.GET_HUMAN_READABLE_SYSTEM_ID(),
identifier: Tools.GET_HUMAN_READABLE_SYSTEM_ID()
},
customizations: {
topicPrefix: "valetudo"
}
}
});
});

this.router.put("/config/interfaces/mqtt", this.validator, (req, res) => {
let mqttConfig = req.body;
let oldConfig = this.config.get("mqtt");
Expand Down
2 changes: 1 addition & 1 deletion backend/lib/webserver/WebServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class WebServer {

this.app.use("/api/v2/robot/", this.robotRouter.getRouter());

this.app.use("/api/v2/valetudo/", new ValetudoRouter({config: this.config, validator: this.validator}).getRouter());
this.app.use("/api/v2/valetudo/", new ValetudoRouter({config: this.config, robot: this.robot, validator: this.validator}).getRouter());

this.app.use("/api/v2/ntpclient/", new NTPClientRouter({config: this.config, ntpClient: options.ntpClient, validator: this.validator}).getRouter());

Expand Down
50 changes: 50 additions & 0 deletions backend/lib/webserver/doc/ValetudoRouter.openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,56 @@
}
}
},
"/api/v2/valetudo/config/interfaces/mqtt/properties": {
"get": {
"tags": [
"Valetudo"
],
"summary": "Get MQTT config properties such as the default values",
"responses": {
"200": {
"description": "Ok",
"content": {
"application/json": {
"schema": {
"type": "object",
"additionalProperties": false,
"properties": {
"defaults": {
"type": "object",
"additionalProperties": false,
"properties": {
"identity": {
"type": "object",
"additionalProperties": false,
"properties": {
"friendlyName": {
"type": "string"
},
"identifier": {
"type": "string"
}
}
},
"customizations": {
"type": "object",
"additionalProperties": false,
"properties": {
"topicPrefix": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
}
}
},
"/api/v2/valetudo/config/interfaces/http/auth/basic": {
"get": {
"tags": [
Expand Down

0 comments on commit 7e6962b

Please sign in to comment.