From 7e6962bd8094120168c960d550027efbf3a53d73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Beye?= Date: Mon, 13 Sep 2021 18:16:07 +0200 Subject: [PATCH] feat(webserver): Provide mqtt config properties --- backend/lib/webserver/ValetudoRouter.js | 17 +++++++ backend/lib/webserver/WebServer.js | 2 +- .../webserver/doc/ValetudoRouter.openapi.json | 50 +++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/backend/lib/webserver/ValetudoRouter.js b/backend/lib/webserver/ValetudoRouter.js index 70ac842c2d6..37c072c8139 100644 --- a/backend/lib/webserver/ValetudoRouter.js +++ b/backend/lib/webserver/ValetudoRouter.js @@ -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? @@ -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"); diff --git a/backend/lib/webserver/WebServer.js b/backend/lib/webserver/WebServer.js index 39e1591a934..54abee013d1 100644 --- a/backend/lib/webserver/WebServer.js +++ b/backend/lib/webserver/WebServer.js @@ -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()); diff --git a/backend/lib/webserver/doc/ValetudoRouter.openapi.json b/backend/lib/webserver/doc/ValetudoRouter.openapi.json index 9379a54fb61..2934d673de6 100644 --- a/backend/lib/webserver/doc/ValetudoRouter.openapi.json +++ b/backend/lib/webserver/doc/ValetudoRouter.openapi.json @@ -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": [