1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-23 20:23:50 +01:00

[web_server] add entity sorting for v3 (#6445)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
RFDarter
2024-05-30 03:54:20 +02:00
committed by GitHub
parent 854d3f2e4a
commit a7fc1a6298
20 changed files with 802 additions and 503 deletions

View File

@@ -5,8 +5,10 @@
#include "esphome/components/web_server_base/web_server_base.h"
#include "esphome/core/component.h"
#include "esphome/core/controller.h"
#include "esphome/core/entity_base.h"
#include <vector>
#include <map>
#ifdef USE_ESP32
#include <freertos/FreeRTOS.h>
#include <freertos/semphr.h>
@@ -39,6 +41,10 @@ struct UrlMatch {
bool valid; ///< Whether this match is valid
};
struct SortingComponents {
float weight;
};
enum JsonDetail { DETAIL_ALL, DETAIL_STATE };
/** This class allows users to create a web server with their ESP nodes.
@@ -320,12 +326,15 @@ class WebServer : public Controller, public Component, public AsyncWebHandler {
/// This web handle is not trivial.
bool isRequestHandlerTrivial() override;
void add_entity_to_sorting_list(EntityBase *entity, float weight);
protected:
void schedule_(std::function<void()> &&f);
friend ListEntitiesIterator;
web_server_base::WebServerBase *base_;
AsyncEventSource events_{"/events"};
ListEntitiesIterator entities_iterator_;
std::map<EntityBase *, SortingComponents> sorting_entitys_;
#if USE_WEBSERVER_VERSION == 1
const char *css_url_{nullptr};
const char *js_url_{nullptr};