diff --git a/AGENTS.md b/AGENTS.md index 7247609..25b037b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -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: +## 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 - 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 `EvDashWebServerResource` represents the webserver HTTP backend and handles REST API requests and file requests starting with the path /evdash -- The `dashboard` folder contains the webinterface, a html + javacript based website representing the frontend. + - 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 + 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 uses a websocket to communicate with the API interface in `EvDashEngine`. ## General workflow - Keep pull request descriptions concise but informative, mentioning both user-visible changes and internal refactors. diff --git a/plugin/evdashengine.cpp b/plugin/evdashengine.cpp index 407ed90..abdea8e 100644 --- a/plugin/evdashengine.cpp +++ b/plugin/evdashengine.cpp @@ -120,9 +120,8 @@ void EvDashEngine::handleNewConnection() void EvDashEngine::handleSocketDisconnected() { QWebSocket *socket = qobject_cast(sender()); - if (!socket) { + if (!socket) return; - } m_clients.removeAll(socket); 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) { - if (!socket) { + if (!socket) return; - } QJsonParseError parseError; const QJsonDocument doc = QJsonDocument::fromJson(message.toUtf8(), &parseError); + if (parseError.error != QJsonParseError::NoError || !doc.isObject()) { qCWarning(dcEvDashExperience()) << "Invalid WebSocket payload" << parseError.errorString(); - QJsonObject errorReply{ {QStringLiteral("version"), QStringLiteral("1.0")}, {QStringLiteral("event"), QStringLiteral("error")}, @@ -148,6 +146,7 @@ void EvDashEngine::processTextMessage(QWebSocket *socket, const QString &message {QStringLiteral("details"), parseError.errorString()} }} }; + sendReply(socket, errorReply); return; } @@ -158,13 +157,14 @@ void EvDashEngine::processTextMessage(QWebSocket *socket, const QString &message QJsonObject EvDashEngine::handleApiRequest(const QJsonObject &request) const { + qCDebug(dcEvDashExperience()) << "Handle API request" << request; + QJsonObject response; response.insert(QStringLiteral("version"), request.value(QStringLiteral("version")).toString(QStringLiteral("1.0"))); const QString requestId = request.value(QStringLiteral("requestId")).toString(); - if (!requestId.isEmpty()) { + if (!requestId.isEmpty()) response.insert(QStringLiteral("requestId"), requestId); - } 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 { - if (!socket) { + if (!socket) return; - } - if (!response.contains(QStringLiteral("version"))) { + if (!response.contains(QStringLiteral("version"))) response.insert(QStringLiteral("version"), QStringLiteral("1.0")); - } const QJsonDocument replyDoc(response); socket->sendTextMessage(QString::fromUtf8(replyDoc.toJson(QJsonDocument::Compact)));