M5-T10: add paho MQTT client with lifespan connect/reconnect and mqtt/test endpoint

This commit is contained in:
2026-06-22 15:06:30 +02:00
parent 360cddc05b
commit 9d05f5ea62
10 changed files with 1072 additions and 3 deletions
+95 -1
View File
@@ -53,7 +53,7 @@
"api-config"
],
"summary": "Put Config",
"description": "Save configuration updates.\n\n- Blank secret value keeps the existing stored value (no change).\n- Invalid values return 422 and nothing is written to the database.",
"description": "Save configuration updates.\n\n- Blank secret value keeps the existing stored value (no change).\n- Invalid values return 422 and nothing is written to the database.\n- If MQTT-related settings changed, the MQTT client reconnects automatically.",
"operationId": "put_config_api_config_put",
"parameters": [
{
@@ -177,6 +177,76 @@
}
}
},
"/api/config/mqtt/test": {
"post": {
"tags": [
"api-config"
],
"summary": "Post Mqtt Test",
"description": "Test MQTT broker connectivity by attempting to connect and publishing a\ntest message to ``<ha_discovery_prefix>/home-automation/test``.\n\nThe message is visible in MQTT Explorer (or any subscriber) so users can\nconfirm the full broker publish path is working.\n\nThree possible outcomes:\n- 200 { \"result\": \"success\", \"message\": ... }\n- 400 { \"result\": \"config-error\", \"message\": ... } (not configured)\n- 502 { \"result\": \"failed\", \"message\": ... } (connection/publish error)\n\nMQTT credentials are never echoed in the response.",
"operationId": "post_mqtt_test_api_config_mqtt_test_post",
"parameters": [
{
"name": "X-CSRF-Token",
"in": "header",
"required": false,
"schema": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"title": "X-Csrf-Token"
}
}
],
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MqttTestResponse"
}
}
}
},
"400": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MqttTestResponse"
}
}
},
"description": "Bad Request"
},
"502": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/MqttTestResponse"
}
}
},
"description": "Bad Gateway"
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/api/locations": {
"get": {
"tags": [
@@ -2329,6 +2399,30 @@
"title": "ModbusTestReadResponse",
"description": "Response for POST /api/modbus/devices/{uuid}/test.\n\nOn success ``ok=True`` and ``payload`` contains the decoded values.\nOn failure ``ok=False`` and ``error`` describes the problem."
},
"MqttTestResponse": {
"properties": {
"result": {
"type": "string",
"enum": [
"success",
"config-error",
"failed"
],
"title": "Result"
},
"message": {
"type": "string",
"title": "Message"
}
},
"type": "object",
"required": [
"result",
"message"
],
"title": "MqttTestResponse",
"description": "Response from POST /api/config/mqtt/test."
},
"PasswordChangeRequest": {
"properties": {
"current_password": {
+83 -1
View File
@@ -42,7 +42,9 @@ paths:
- Blank secret value keeps the existing stored value (no change).
- Invalid values return 422 and nothing is written to the database.'
- Invalid values return 422 and nothing is written to the database.
- If MQTT-related settings changed, the MQTT client reconnects automatically.'
operationId: put_config_api_config_put
parameters:
- name: X-CSRF-Token
@@ -127,6 +129,68 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
/api/config/mqtt/test:
post:
tags:
- api-config
summary: Post Mqtt Test
description: 'Test MQTT broker connectivity by attempting to connect and publishing
a
test message to ``<ha_discovery_prefix>/home-automation/test``.
The message is visible in MQTT Explorer (or any subscriber) so users can
confirm the full broker publish path is working.
Three possible outcomes:
- 200 { "result": "success", "message": ... }
- 400 { "result": "config-error", "message": ... } (not configured)
- 502 { "result": "failed", "message": ... } (connection/publish
error)
MQTT credentials are never echoed in the response.'
operationId: post_mqtt_test_api_config_mqtt_test_post
parameters:
- name: X-CSRF-Token
in: header
required: false
schema:
anyOf:
- type: string
- type: 'null'
title: X-Csrf-Token
responses:
'200':
description: Successful Response
content:
application/json:
schema:
$ref: '#/components/schemas/MqttTestResponse'
'400':
content:
application/json:
schema:
$ref: '#/components/schemas/MqttTestResponse'
description: Bad Request
'502':
content:
application/json:
schema:
$ref: '#/components/schemas/MqttTestResponse'
description: Bad Gateway
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
/api/locations:
get:
tags:
@@ -1699,6 +1763,24 @@ components:
On success ``ok=True`` and ``payload`` contains the decoded values.
On failure ``ok=False`` and ``error`` describes the problem.'
MqttTestResponse:
properties:
result:
type: string
enum:
- success
- config-error
- failed
title: Result
message:
type: string
title: Message
type: object
required:
- result
- message
title: MqttTestResponse
description: Response from POST /api/config/mqtt/test.
PasswordChangeRequest:
properties:
current_password: