add more immich control options
This commit is contained in:
@@ -18,6 +18,8 @@ MqttController::MqttController(const MqttConfig &configIn, QObject *parent)
|
||||
mosquitto_lib_init();
|
||||
g_mqttInitialized = true;
|
||||
}
|
||||
controlTopic = QString::fromStdString(config.topic);
|
||||
immichTopic = QString::fromStdString(config.immichTopic);
|
||||
}
|
||||
|
||||
MqttController::~MqttController()
|
||||
@@ -103,6 +105,18 @@ void MqttController::subscribe()
|
||||
{
|
||||
Log("MQTT subscribed to ", config.topic);
|
||||
}
|
||||
if (!config.immichTopic.empty() && config.immichTopic != config.topic)
|
||||
{
|
||||
rc = mosquitto_subscribe(client, nullptr, config.immichTopic.c_str(), config.qos);
|
||||
if (rc != MOSQ_ERR_SUCCESS)
|
||||
{
|
||||
Log("MQTT subscribe (immich) failed: ", mosquitto_strerror(rc));
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("MQTT subscribed to ", config.immichTopic);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MqttController::HandleMessage(struct mosquitto *mosq, void *userdata, const struct mosquitto_message *message)
|
||||
@@ -113,15 +127,26 @@ void MqttController::HandleMessage(struct mosquitto *mosq, void *userdata, const
|
||||
return;
|
||||
|
||||
QString payload = QString::fromUtf8(static_cast<const char *>(message->payload), message->payloadlen);
|
||||
QMetaObject::invokeMethod(self, "handleCommand", Qt::QueuedConnection, Q_ARG(QString, payload));
|
||||
QString topic = QString::fromUtf8(message->topic);
|
||||
QMetaObject::invokeMethod(self, "handleMessage", Qt::QueuedConnection,
|
||||
Q_ARG(QString, topic),
|
||||
Q_ARG(QString, payload));
|
||||
}
|
||||
|
||||
void MqttController::handleCommand(const QString &payload)
|
||||
void MqttController::handleMessage(const QString &topic, const QString &payload)
|
||||
{
|
||||
QString cmd = payload.trimmed().toLower();
|
||||
if (cmd.isEmpty())
|
||||
return;
|
||||
|
||||
Log("MQTT message on ", topic.toStdString(), ": ", cmd.toStdString());
|
||||
|
||||
if (!immichTopic.isEmpty() && topic == immichTopic)
|
||||
{
|
||||
emit immichControl(payload);
|
||||
return;
|
||||
}
|
||||
|
||||
if (cmd == "play" || cmd == "resume")
|
||||
{
|
||||
emit play();
|
||||
|
||||
Reference in New Issue
Block a user