27 lines
617 B
Python
27 lines
617 B
Python
from __future__ import annotations
|
|
|
|
from fastapi_mqtt import FastMQTT, MQTTConfig
|
|
|
|
from app.core.config import settings
|
|
from app.communication.mqtt.topics import SUBSCRIBE_TOPICS
|
|
|
|
mqtt_config = MQTTConfig(
|
|
host=settings.MQTT_HOST,
|
|
port=settings.MQTT_PORT,
|
|
username=settings.MQTT_USERNAME or None,
|
|
password=settings.MQTT_PASSWORD or None,
|
|
keepalive=60,
|
|
)
|
|
|
|
mqtt = FastMQTT(config=mqtt_config)
|
|
|
|
|
|
async def mqtt_startup() -> None:
|
|
await mqtt.mqtt_startup()
|
|
for topic in SUBSCRIBE_TOPICS:
|
|
mqtt.client.subscribe(topic)
|
|
|
|
|
|
async def mqtt_shutdown() -> None:
|
|
await mqtt.mqtt_shutdown()
|