Update agents
This commit is contained in:
parent
4efed08aac
commit
9c2cc223a6
@ -2,12 +2,16 @@
|
|||||||
|
|
||||||
Welcome to the nymea EV-Dash experience plugin repository. Please keep the following guidelines in mind when working on this codebase:
|
Welcome to the nymea EV-Dash experience plugin repository. Please keep the following guidelines in mind when working on this codebase:
|
||||||
|
|
||||||
|
## Purpose
|
||||||
|
The dashboard should should give an overview of conofugred ev chargers in the system, show the status of each ev charger, information and provide
|
||||||
|
|
||||||
## Structure
|
## Structure
|
||||||
- The `plugin` directory contains the Qt c++ implementation of the experience plugin
|
- The `plugin` directory contains the Qt c++ implementation of the experience plugin
|
||||||
- The `EvDashJsonHandler` class provides the JSON RPC API definition and declaration of the experience
|
- The `EvDashJsonHandler` class provides the JSON RPC API definition and declaration of the experience
|
||||||
- The `EvDashWebServerResource` represents the webserver HTTP backend and handles REST API requests and file requests starting with the path /evdash
|
- The `EvDashWebServerResource` represents the webserver HTTP backend and handles REST API requests and file requests starting with the path /evdash. This class provides file access to the static resources and provides secure generated data access
|
||||||
- The `dashboard` folder contains the webinterface, a html + javacript based website representing the frontend.
|
- The `dashboard` folder contains the webinterface, a html + js file based website representing the frontend. The interface will be compiled into the plugin using the dashboard.qrc file.
|
||||||
- The dashboard should be brandable, providing 3 colors and icons should allow to change the style of the webinterface
|
- The dashboard should be brandable, providing 3 colors and icons should allow to change the style of the webinterface
|
||||||
|
- The dashboard uses a websocket to communicate with the API interface in `EvDashEngine`.
|
||||||
|
|
||||||
## General workflow
|
## General workflow
|
||||||
- Keep pull request descriptions concise but informative, mentioning both user-visible changes and internal refactors.
|
- Keep pull request descriptions concise but informative, mentioning both user-visible changes and internal refactors.
|
||||||
|
|||||||
@ -120,9 +120,8 @@ void EvDashEngine::handleNewConnection()
|
|||||||
void EvDashEngine::handleSocketDisconnected()
|
void EvDashEngine::handleSocketDisconnected()
|
||||||
{
|
{
|
||||||
QWebSocket *socket = qobject_cast<QWebSocket *>(sender());
|
QWebSocket *socket = qobject_cast<QWebSocket *>(sender());
|
||||||
if (!socket) {
|
if (!socket)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
m_clients.removeAll(socket);
|
m_clients.removeAll(socket);
|
||||||
qCDebug(dcEvDashExperience()) << "WebSocket client disconnected" << socket->peerAddress() << "Remaining clients:" << m_clients.count();
|
qCDebug(dcEvDashExperience()) << "WebSocket client disconnected" << socket->peerAddress() << "Remaining clients:" << m_clients.count();
|
||||||
@ -131,15 +130,14 @@ void EvDashEngine::handleSocketDisconnected()
|
|||||||
|
|
||||||
void EvDashEngine::processTextMessage(QWebSocket *socket, const QString &message)
|
void EvDashEngine::processTextMessage(QWebSocket *socket, const QString &message)
|
||||||
{
|
{
|
||||||
if (!socket) {
|
if (!socket)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
QJsonParseError parseError;
|
QJsonParseError parseError;
|
||||||
const QJsonDocument doc = QJsonDocument::fromJson(message.toUtf8(), &parseError);
|
const QJsonDocument doc = QJsonDocument::fromJson(message.toUtf8(), &parseError);
|
||||||
|
|
||||||
if (parseError.error != QJsonParseError::NoError || !doc.isObject()) {
|
if (parseError.error != QJsonParseError::NoError || !doc.isObject()) {
|
||||||
qCWarning(dcEvDashExperience()) << "Invalid WebSocket payload" << parseError.errorString();
|
qCWarning(dcEvDashExperience()) << "Invalid WebSocket payload" << parseError.errorString();
|
||||||
|
|
||||||
QJsonObject errorReply{
|
QJsonObject errorReply{
|
||||||
{QStringLiteral("version"), QStringLiteral("1.0")},
|
{QStringLiteral("version"), QStringLiteral("1.0")},
|
||||||
{QStringLiteral("event"), QStringLiteral("error")},
|
{QStringLiteral("event"), QStringLiteral("error")},
|
||||||
@ -148,6 +146,7 @@ void EvDashEngine::processTextMessage(QWebSocket *socket, const QString &message
|
|||||||
{QStringLiteral("details"), parseError.errorString()}
|
{QStringLiteral("details"), parseError.errorString()}
|
||||||
}}
|
}}
|
||||||
};
|
};
|
||||||
|
|
||||||
sendReply(socket, errorReply);
|
sendReply(socket, errorReply);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -158,13 +157,14 @@ void EvDashEngine::processTextMessage(QWebSocket *socket, const QString &message
|
|||||||
|
|
||||||
QJsonObject EvDashEngine::handleApiRequest(const QJsonObject &request) const
|
QJsonObject EvDashEngine::handleApiRequest(const QJsonObject &request) const
|
||||||
{
|
{
|
||||||
|
qCDebug(dcEvDashExperience()) << "Handle API request" << request;
|
||||||
|
|
||||||
QJsonObject response;
|
QJsonObject response;
|
||||||
response.insert(QStringLiteral("version"), request.value(QStringLiteral("version")).toString(QStringLiteral("1.0")));
|
response.insert(QStringLiteral("version"), request.value(QStringLiteral("version")).toString(QStringLiteral("1.0")));
|
||||||
|
|
||||||
const QString requestId = request.value(QStringLiteral("requestId")).toString();
|
const QString requestId = request.value(QStringLiteral("requestId")).toString();
|
||||||
if (!requestId.isEmpty()) {
|
if (!requestId.isEmpty())
|
||||||
response.insert(QStringLiteral("requestId"), requestId);
|
response.insert(QStringLiteral("requestId"), requestId);
|
||||||
}
|
|
||||||
|
|
||||||
const QString action = request.value(QStringLiteral("action")).toString();
|
const QString action = request.value(QStringLiteral("action")).toString();
|
||||||
|
|
||||||
@ -193,13 +193,11 @@ QJsonObject EvDashEngine::handleApiRequest(const QJsonObject &request) const
|
|||||||
|
|
||||||
void EvDashEngine::sendReply(QWebSocket *socket, QJsonObject response) const
|
void EvDashEngine::sendReply(QWebSocket *socket, QJsonObject response) const
|
||||||
{
|
{
|
||||||
if (!socket) {
|
if (!socket)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (!response.contains(QStringLiteral("version"))) {
|
if (!response.contains(QStringLiteral("version")))
|
||||||
response.insert(QStringLiteral("version"), QStringLiteral("1.0"));
|
response.insert(QStringLiteral("version"), QStringLiteral("1.0"));
|
||||||
}
|
|
||||||
|
|
||||||
const QJsonDocument replyDoc(response);
|
const QJsonDocument replyDoc(response);
|
||||||
socket->sendTextMessage(QString::fromUtf8(replyDoc.toJson(QJsonDocument::Compact)));
|
socket->sendTextMessage(QString::fromUtf8(replyDoc.toJson(QJsonDocument::Compact)));
|
||||||
|
|||||||
Reference in New Issue
Block a user