added some more API calls
parent
653caa938e
commit
73055830b8
|
|
@ -33,15 +33,7 @@
|
||||||
{
|
{
|
||||||
"id": "b6c3377b-91de-411a-9d48-8b509c39d67c",
|
"id": "b6c3377b-91de-411a-9d48-8b509c39d67c",
|
||||||
"name": "openDoor",
|
"name": "openDoor",
|
||||||
"displayName": "Open door",
|
"displayName": "Open door"
|
||||||
"paramTypes": [
|
|
||||||
{
|
|
||||||
"id": "6dcce056-e4d4-49c4-8b68-d3f478c00a52",
|
|
||||||
"name": "number",
|
|
||||||
"displayName": "Number",
|
|
||||||
"type": "int"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "3a6cfc5d-804c-4d21-91b5-999913d4f1a5",
|
"id": "3a6cfc5d-804c-4d21-91b5-999913d4f1a5",
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,8 @@
|
||||||
#include <QAuthenticator>
|
#include <QAuthenticator>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
|
#include <QUrl>
|
||||||
|
#include <QUrlQuery>
|
||||||
|
|
||||||
Doorbird::Doorbird(const QHostAddress &address, const QString &username, const QString &password, QObject *parent) :
|
Doorbird::Doorbird(const QHostAddress &address, const QString &username, const QString &password, QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
|
|
@ -38,9 +40,10 @@ Doorbird::Doorbird(const QHostAddress &address, const QString &username, const Q
|
||||||
{
|
{
|
||||||
m_networkAccessManager = new QNetworkAccessManager(this);
|
m_networkAccessManager = new QNetworkAccessManager(this);
|
||||||
connect(m_networkAccessManager, &QNetworkAccessManager::authenticationRequired, this, [this](QNetworkReply *reply, QAuthenticator *authenticator) {
|
connect(m_networkAccessManager, &QNetworkAccessManager::authenticationRequired, this, [this](QNetworkReply *reply, QAuthenticator *authenticator) {
|
||||||
|
Q_UNUSED(reply);
|
||||||
qCDebug(dcDoorBird) << "Credentials requested:";
|
qCDebug(dcDoorBird) << "Credentials requested:";
|
||||||
authenticator->setUser(username);
|
authenticator->setUser(m_username);
|
||||||
authenticator->setPassword(password);
|
authenticator->setPassword(m_password);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -114,7 +117,22 @@ QUuid Doorbird::lightOn()
|
||||||
|
|
||||||
QUuid Doorbird::liveVideoRequest()
|
QUuid Doorbird::liveVideoRequest()
|
||||||
{
|
{
|
||||||
|
QNetworkRequest request(QString("http://%1/bha-api/info.cgi").arg(m_address.toString()));
|
||||||
|
qCDebug(dcDoorBird) << "Sending request:" << request.url();
|
||||||
|
QNetworkReply *reply = m_networkAccessManager->get(request);
|
||||||
|
QUuid requestId = QUuid::createUuid();
|
||||||
|
connect(reply, &QNetworkReply::finished, this, [this, reply, requestId](){
|
||||||
|
reply->deleteLater();
|
||||||
|
|
||||||
|
if (reply->error() != QNetworkReply::NoError) {
|
||||||
|
qCWarning(dcDoorBird) << "Error unlatching DoorBird device";
|
||||||
|
emit requestSent(requestId, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
qCDebug(dcDoorBird) << "DoorBird unlatched:" << reply->error() << reply->errorString();
|
||||||
|
emit requestSent(requestId, true);
|
||||||
|
});
|
||||||
|
return requestId;
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid Doorbird::liveImageRequest()
|
QUuid Doorbird::liveImageRequest()
|
||||||
|
|
@ -142,7 +160,52 @@ QUuid Doorbird::liveImageRequest()
|
||||||
|
|
||||||
QUuid Doorbird::historyImageRequest(int index)
|
QUuid Doorbird::historyImageRequest(int index)
|
||||||
{
|
{
|
||||||
|
QUrl url(QString("http://%1/bha-api/history.cgi").arg(m_address.toString()));
|
||||||
|
QUrlQuery query;
|
||||||
|
query.addQueryItem("index", QString::number(index));
|
||||||
|
url.setQuery(query);
|
||||||
|
|
||||||
|
qCDebug(dcDoorBird) << "Sending request:" << url;
|
||||||
|
QNetworkReply *reply = m_networkAccessManager->get(QNetworkRequest(url));
|
||||||
|
QUuid requestId = QUuid::createUuid();
|
||||||
|
connect(reply, &QNetworkReply::finished, this, [this, reply, requestId](){
|
||||||
|
reply->deleteLater();
|
||||||
|
|
||||||
|
if (reply->error() != QNetworkReply::NoError) {
|
||||||
|
qCWarning(dcDoorBird) << "Error unlatching DoorBird device";
|
||||||
|
emit requestSent(requestId, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
qCDebug(dcDoorBird) << "DoorBird unlatched:" << reply->error() << reply->errorString();
|
||||||
|
emit requestSent(requestId, true);
|
||||||
|
});
|
||||||
|
return requestId;
|
||||||
|
}
|
||||||
|
|
||||||
|
QUuid Doorbird::liveAudioReceive()
|
||||||
|
{
|
||||||
|
QNetworkRequest request(QString("http://%1/bha-api/audio-receive.cgi").arg(m_address.toString()));
|
||||||
|
qCDebug(dcDoorBird) << "Sending request:" << request.url();
|
||||||
|
QNetworkReply *reply = m_networkAccessManager->get(request);
|
||||||
|
QUuid requestId = QUuid::createUuid();
|
||||||
|
connect(reply, &QNetworkReply::finished, this, [this, reply, requestId](){
|
||||||
|
reply->deleteLater();
|
||||||
|
|
||||||
|
if (reply->error() != QNetworkReply::NoError) {
|
||||||
|
qCWarning(dcDoorBird) << "Error DoorBird device";
|
||||||
|
emit requestSent(requestId, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
qCDebug(dcDoorBird) << "DoorBird unlatched:" << reply->error() << reply->errorString();
|
||||||
|
emit requestSent(requestId, true);
|
||||||
|
});
|
||||||
|
return requestId;
|
||||||
|
}
|
||||||
|
|
||||||
|
QUuid Doorbird::liveAudioTransmit()
|
||||||
|
{
|
||||||
|
|
||||||
|
return QUuid::createUuid();
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid Doorbird::infoRequest()
|
QUuid Doorbird::infoRequest()
|
||||||
|
|
@ -150,26 +213,57 @@ QUuid Doorbird::infoRequest()
|
||||||
QNetworkRequest request(QString("http://%1/bha-api/info.cgi").arg(m_address.toString()));
|
QNetworkRequest request(QString("http://%1/bha-api/info.cgi").arg(m_address.toString()));
|
||||||
qCDebug(dcDoorBird) << "Sending request:" << request.url();
|
qCDebug(dcDoorBird) << "Sending request:" << request.url();
|
||||||
QNetworkReply *reply = m_networkAccessManager->get(request);
|
QNetworkReply *reply = m_networkAccessManager->get(request);
|
||||||
|
QUuid requestId = QUuid::createUuid();
|
||||||
connect(reply, &QNetworkReply::finished, this, [this, reply, action](){
|
connect(reply, &QNetworkReply::finished, this, [this, reply, requestId](){
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
|
||||||
if (reply->error() != QNetworkReply::NoError) {
|
if (reply->error() != QNetworkReply::NoError) {
|
||||||
qCWarning(dcDoorBird) << "Error unlatching DoorBird device";
|
qCWarning(dcDoorBird) << "Error unlatching DoorBird device";
|
||||||
|
emit requestSent(requestId, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
qCDebug(dcDoorBird) << "DoorBird unlatched:" << reply->error() << reply->errorString();
|
qCDebug(dcDoorBird) << "DoorBird unlatched:" << reply->error() << reply->errorString();
|
||||||
|
emit requestSent(requestId, true);
|
||||||
});
|
});
|
||||||
|
return requestId;
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid Doorbird::listFavorites()
|
QUuid Doorbird::listFavorites()
|
||||||
{
|
{
|
||||||
|
QNetworkRequest request(QString("http://%1/bha-api/favorites.cgi").arg(m_address.toString()));
|
||||||
|
qCDebug(dcDoorBird) << "Sending request:" << request.url();
|
||||||
|
QNetworkReply *reply = m_networkAccessManager->get(request);
|
||||||
|
QUuid requestId = QUuid::createUuid();
|
||||||
|
connect(reply, &QNetworkReply::finished, this, [this, reply, requestId](){
|
||||||
|
reply->deleteLater();
|
||||||
|
|
||||||
|
if (reply->error() != QNetworkReply::NoError) {
|
||||||
|
qCWarning(dcDoorBird) << "Error DoorBird device" << reply->error() << reply->errorString();
|
||||||
|
emit requestSent(requestId, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
emit requestSent(requestId, true);
|
||||||
|
});
|
||||||
|
return requestId;
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid Doorbird::listSchedules()
|
QUuid Doorbird::listSchedules()
|
||||||
{
|
{
|
||||||
|
QNetworkRequest request(QString("http://%1/bha-api/schedule.cgi").arg(m_address.toString()));
|
||||||
|
qCDebug(dcDoorBird) << "Sending request:" << request.url();
|
||||||
|
QNetworkReply *reply = m_networkAccessManager->get(request);
|
||||||
|
QUuid requestId = QUuid::createUuid();
|
||||||
|
connect(reply, &QNetworkReply::finished, this, [this, reply, requestId](){
|
||||||
|
reply->deleteLater();
|
||||||
|
|
||||||
|
if (reply->error() != QNetworkReply::NoError) {
|
||||||
|
qCWarning(dcDoorBird) << "Error DoorBird device" << reply->error() << reply->errorString();
|
||||||
|
emit requestSent(requestId, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
emit requestSent(requestId, true);
|
||||||
|
});
|
||||||
|
return requestId;
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid Doorbird::restart()
|
QUuid Doorbird::restart()
|
||||||
|
|
@ -177,24 +271,27 @@ QUuid Doorbird::restart()
|
||||||
QNetworkRequest request(QString("http://%1/bha-api/restart.cgi").arg(m_address.toString()));
|
QNetworkRequest request(QString("http://%1/bha-api/restart.cgi").arg(m_address.toString()));
|
||||||
qCDebug(dcDoorBird) << "Sending request:" << request.url();
|
qCDebug(dcDoorBird) << "Sending request:" << request.url();
|
||||||
QNetworkReply *reply = m_networkAccessManager->get(request);
|
QNetworkReply *reply = m_networkAccessManager->get(request);
|
||||||
|
QUuid requestId = QUuid::createUuid();
|
||||||
connect(reply, &QNetworkReply::finished, this, [this, reply, action](){
|
connect(reply, &QNetworkReply::finished, this, [this, reply, requestId](){
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
|
||||||
if (reply->error() != QNetworkReply::NoError) {
|
if (reply->error() != QNetworkReply::NoError) {
|
||||||
qCWarning(dcDoorBird) << "Error restarting DoorBird device" << reply;
|
qCWarning(dcDoorBird) << "Error restarting DoorBird device" << reply;
|
||||||
|
emit requestSent(requestId, false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
qCDebug(dcDoorBird) << "DoorBird restarting";
|
qCDebug(dcDoorBird) << "DoorBird restarting";
|
||||||
|
emit requestSent(requestId, true);
|
||||||
});
|
});
|
||||||
|
return requestId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Doorbird::connectToEventMonitor()
|
void Doorbird::connectToEventMonitor()
|
||||||
{
|
{
|
||||||
qCDebug(dcDoorBird) << "Starting monitoring";
|
qCDebug(dcDoorBird) << "Starting monitoring";
|
||||||
|
|
||||||
QNetworkRequest request(QString("http://%1/bha-api/monitor.cgi?ring=doorbell,motionsensor").arg(m_address.toString());
|
QNetworkRequest request(QString("http://%1/bha-api/monitor.cgi?ring=doorbell,motionsensor").arg(m_address.toString()));
|
||||||
QNetworkReply *reply = m_networkAccessManager->get(request);
|
QNetworkReply *reply = m_networkAccessManager->get(request);
|
||||||
|
|
||||||
connect(reply, &QNetworkReply::downloadProgress, this, [this, reply](qint64 bytesReceived, qint64 bytesTotal){
|
connect(reply, &QNetworkReply::downloadProgress, this, [this, reply](qint64 bytesReceived, qint64 bytesTotal){
|
||||||
Q_UNUSED(bytesReceived)
|
Q_UNUSED(bytesReceived)
|
||||||
|
|
@ -210,7 +307,7 @@ void Doorbird::connectToEventMonitor()
|
||||||
|
|
||||||
while (!m_readBuffers.isEmpty()) {
|
while (!m_readBuffers.isEmpty()) {
|
||||||
// find next --ioboundary
|
// find next --ioboundary
|
||||||
QString boundary = QStringLiteral("--ioboundary");
|
/*QString boundary = QStringLiteral("--ioboundary");
|
||||||
int startIndex = m_readBuffers.indexOf(boundary);
|
int startIndex = m_readBuffers.indexOf(boundary);
|
||||||
if (startIndex == -1) {
|
if (startIndex == -1) {
|
||||||
qCWarning(dcDoorBird) << "No meaningful data in buffer:" << m_readBuffers;
|
qCWarning(dcDoorBird) << "No meaningful data in buffer:" << m_readBuffers;
|
||||||
|
|
@ -265,17 +362,18 @@ void Doorbird::connectToEventMonitor()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qCWarning(dcDoorBird) << "Unhandled DoorBird data:" << message;
|
qCWarning(dcDoorBird) << "Unhandled DoorBird data:" << message;
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
connect(reply, &QNetworkReply::finished, this, [this, reply](){
|
|
||||||
|
connect(reply, &QNetworkReply::finished, this, [this, reply]() {
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
|
||||||
//device->setStateValue(doorBirdConnectedStateTypeId, false);
|
//device->setStateValue(doorBirdConnectedStateTypeId, false);
|
||||||
qCDebug(dcDoorBird) << "Monitor request finished:" << reply->error();
|
qCDebug(dcDoorBird) << "Monitor request finished:" << reply->error();
|
||||||
|
|
||||||
QTimer::singleShot(2000, this, [this] {
|
QTimer::singleShot(2000, this, [this] {
|
||||||
connectToEventMonitor(device);
|
connectToEventMonitor();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue