mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
replace exclude_entities with masked_entities
This commit is contained in:
@@ -12,7 +12,7 @@ import {
|
|||||||
DeviceData,
|
DeviceData,
|
||||||
DeviceEntity,
|
DeviceEntity,
|
||||||
UniqueID,
|
UniqueID,
|
||||||
ExcludeEntities,
|
MaskedEntities,
|
||||||
WriteValue,
|
WriteValue,
|
||||||
WriteSensor,
|
WriteSensor,
|
||||||
WriteAnalog,
|
WriteAnalog,
|
||||||
@@ -63,8 +63,8 @@ export function readDeviceEntities(unique_id: UniqueID): AxiosPromise<DeviceEnti
|
|||||||
return AXIOS_BIN.post('/deviceEntities', unique_id);
|
return AXIOS_BIN.post('/deviceEntities', unique_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function writeExcludeEntities(excludeEntities: ExcludeEntities): AxiosPromise<void> {
|
export function writeMaskedEntities(maskedEntities: MaskedEntities): AxiosPromise<void> {
|
||||||
return AXIOS.post('/excludeEntities', excludeEntities);
|
return AXIOS.post('/maskedEntities', maskedEntities);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function writeValue(writevalue: WriteValue): AxiosPromise<void> {
|
export function writeValue(writevalue: WriteValue): AxiosPromise<void> {
|
||||||
|
|||||||
@@ -146,11 +146,11 @@ export interface DeviceEntity {
|
|||||||
v?: any; // value, in any format
|
v?: any; // value, in any format
|
||||||
n: string; // name
|
n: string; // name
|
||||||
s: string; // shortname
|
s: string; // shortname
|
||||||
x: boolean; // excluded flag
|
m: number; // mask
|
||||||
i: number; // unique id
|
i: number; // unique id
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ExcludeEntities {
|
export interface MaskedEntities {
|
||||||
id: number;
|
id: number;
|
||||||
entity_ids: string[];
|
entity_ids: string[];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1018,7 +1018,6 @@ bool System::command_customizations(const char * value, const int8_t id, JsonObj
|
|||||||
|
|
||||||
JsonObject node = output.createNestedObject("Customizations");
|
JsonObject node = output.createNestedObject("Customizations");
|
||||||
|
|
||||||
// hide ssid from this list
|
|
||||||
EMSESP::webCustomizationService.read([&](WebCustomization & settings) {
|
EMSESP::webCustomizationService.read([&](WebCustomization & settings) {
|
||||||
// sensors
|
// sensors
|
||||||
JsonArray sensorsJson = node.createNestedArray("sensors");
|
JsonArray sensorsJson = node.createNestedArray("sensors");
|
||||||
@@ -1053,7 +1052,7 @@ bool System::command_customizations(const char * value, const int8_t id, JsonObj
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// exclude entities
|
// masked entities
|
||||||
JsonArray mask_entitiesJson = node.createNestedArray("masked_entities");
|
JsonArray mask_entitiesJson = node.createNestedArray("masked_entities");
|
||||||
for (const auto & entityCustomization : settings.entityCustomizations) {
|
for (const auto & entityCustomization : settings.entityCustomizations) {
|
||||||
JsonObject entityJson = mask_entitiesJson.createNestedObject();
|
JsonObject entityJson = mask_entitiesJson.createNestedObject();
|
||||||
|
|||||||
@@ -595,8 +595,8 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
|||||||
EMSESP::system_.healthcheck(n);
|
EMSESP::system_.healthcheck(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command == "exclude") {
|
if (command == "masked") {
|
||||||
shell.printfln(F("Testing exclude entities"));
|
shell.printfln(F("Testing masked entities"));
|
||||||
|
|
||||||
Mqtt::ha_enabled(true);
|
Mqtt::ha_enabled(true);
|
||||||
Mqtt::send_response(false);
|
Mqtt::send_response(false);
|
||||||
|
|||||||
@@ -31,12 +31,12 @@ namespace emsesp {
|
|||||||
// #define EMSESP_DEBUG_DEFAULT "mixer"
|
// #define EMSESP_DEBUG_DEFAULT "mixer"
|
||||||
// #define EMSESP_DEBUG_DEFAULT "web"
|
// #define EMSESP_DEBUG_DEFAULT "web"
|
||||||
// #define EMSESP_DEBUG_DEFAULT "mqtt"
|
// #define EMSESP_DEBUG_DEFAULT "mqtt"
|
||||||
// #define EMSESP_DEBUG_DEFAULT "general"
|
#define EMSESP_DEBUG_DEFAULT "general"
|
||||||
// #define EMSESP_DEBUG_DEFAULT "boiler"
|
// #define EMSESP_DEBUG_DEFAULT "boiler"
|
||||||
// #define EMSESP_DEBUG_DEFAULT "mqtt2"
|
// #define EMSESP_DEBUG_DEFAULT "mqtt2"
|
||||||
// #define EMSESP_DEBUG_DEFAULT "mqtt_nested"
|
// #define EMSESP_DEBUG_DEFAULT "mqtt_nested"
|
||||||
#define EMSESP_DEBUG_DEFAULT "ha"
|
// #define EMSESP_DEBUG_DEFAULT "ha"
|
||||||
// #define EMSESP_DEBUG_DEFAULT "exclude"
|
// #define EMSESP_DEBUG_DEFAULT "masked"
|
||||||
// #define EMSESP_DEBUG_DEFAULT "board_profile"
|
// #define EMSESP_DEBUG_DEFAULT "board_profile"
|
||||||
// #define EMSESP_DEBUG_DEFAULT "shower_alert"
|
// #define EMSESP_DEBUG_DEFAULT "shower_alert"
|
||||||
// #define EMSESP_DEBUG_DEFAULT "310"
|
// #define EMSESP_DEBUG_DEFAULT "310"
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ WebCustomizationService::WebCustomizationService(AsyncWebServer * server, FS * f
|
|||||||
securityManager,
|
securityManager,
|
||||||
AuthenticationPredicates::IS_AUTHENTICATED)
|
AuthenticationPredicates::IS_AUTHENTICATED)
|
||||||
, _fsPersistence(WebCustomization::read, WebCustomization::update, this, fs, EMSESP_CUSTOMIZATION_FILE)
|
, _fsPersistence(WebCustomization::read, WebCustomization::update, this, fs, EMSESP_CUSTOMIZATION_FILE)
|
||||||
, _exclude_entities_handler(EXCLUDE_ENTITIES_PATH,
|
, _masked_entities_handler(MASKED_ENTITIES_PATH,
|
||||||
securityManager->wrapCallback(std::bind(&WebCustomizationService::exclude_entities, this, _1, _2),
|
securityManager->wrapCallback(std::bind(&WebCustomizationService::masked_entities, this, _1, _2),
|
||||||
AuthenticationPredicates::IS_AUTHENTICATED))
|
AuthenticationPredicates::IS_AUTHENTICATED))
|
||||||
, _device_entities_handler(DEVICE_ENTITIES_PATH,
|
, _device_entities_handler(DEVICE_ENTITIES_PATH,
|
||||||
securityManager->wrapCallback(std::bind(&WebCustomizationService::device_entities, this, _1, _2),
|
securityManager->wrapCallback(std::bind(&WebCustomizationService::device_entities, this, _1, _2),
|
||||||
@@ -45,17 +45,17 @@ WebCustomizationService::WebCustomizationService(AsyncWebServer * server, FS * f
|
|||||||
HTTP_POST,
|
HTTP_POST,
|
||||||
securityManager->wrapRequest(std::bind(&WebCustomizationService::reset_customization, this, _1), AuthenticationPredicates::IS_ADMIN));
|
securityManager->wrapRequest(std::bind(&WebCustomizationService::reset_customization, this, _1), AuthenticationPredicates::IS_ADMIN));
|
||||||
|
|
||||||
_exclude_entities_handler.setMethod(HTTP_POST);
|
_masked_entities_handler.setMethod(HTTP_POST);
|
||||||
_exclude_entities_handler.setMaxContentLength(2048);
|
_masked_entities_handler.setMaxContentLength(2048);
|
||||||
_exclude_entities_handler.setMaxJsonBufferSize(2048);
|
_masked_entities_handler.setMaxJsonBufferSize(2048);
|
||||||
server->addHandler(&_exclude_entities_handler);
|
server->addHandler(&_masked_entities_handler);
|
||||||
|
|
||||||
_device_entities_handler.setMethod(HTTP_POST);
|
_device_entities_handler.setMethod(HTTP_POST);
|
||||||
_device_entities_handler.setMaxContentLength(256);
|
_device_entities_handler.setMaxContentLength(256);
|
||||||
server->addHandler(&_device_entities_handler);
|
server->addHandler(&_device_entities_handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
// this creates the customization file, saving to the FS
|
// this creates the customization file, saving it to the FS
|
||||||
void WebCustomization::read(WebCustomization & settings, JsonObject & root) {
|
void WebCustomization::read(WebCustomization & settings, JsonObject & root) {
|
||||||
// Dallas Sensor customization
|
// Dallas Sensor customization
|
||||||
JsonArray sensorsJson = root.createNestedArray("sensors");
|
JsonArray sensorsJson = root.createNestedArray("sensors");
|
||||||
@@ -78,21 +78,21 @@ void WebCustomization::read(WebCustomization & settings, JsonObject & root) {
|
|||||||
sensorJson["type"] = sensor.type; // t
|
sensorJson["type"] = sensor.type; // t
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exclude entities customization
|
// Masked entities customization
|
||||||
JsonArray exclude_entitiesJson = root.createNestedArray("exclude_entities");
|
JsonArray masked_entitiesJson = root.createNestedArray("masked_entities");
|
||||||
for (const EntityCustomization & entityCustomization : settings.entityCustomizations) {
|
for (const EntityCustomization & entityCustomization : settings.entityCustomizations) {
|
||||||
JsonObject entityJson = exclude_entitiesJson.createNestedObject();
|
JsonObject entityJson = masked_entitiesJson.createNestedObject();
|
||||||
entityJson["product_id"] = entityCustomization.product_id;
|
entityJson["product_id"] = entityCustomization.product_id;
|
||||||
entityJson["device_id"] = entityCustomization.device_id;
|
entityJson["device_id"] = entityCustomization.device_id;
|
||||||
|
|
||||||
JsonArray exclude_entityJson = entityJson.createNestedArray("entity_ids");
|
JsonArray masked_entityJson = entityJson.createNestedArray("entity_ids");
|
||||||
for (std::string entity_id : entityCustomization.entity_ids) {
|
for (std::string entity_id : entityCustomization.entity_ids) {
|
||||||
exclude_entityJson.add(entity_id);
|
masked_entityJson.add(entity_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// call on initialization and also when the page is saved via web
|
// call on initialization and also when the page is saved via web UI
|
||||||
// this loads the data into the internal class
|
// this loads the data into the internal class
|
||||||
StateUpdateResult WebCustomization::update(JsonObject & root, WebCustomization & settings) {
|
StateUpdateResult WebCustomization::update(JsonObject & root, WebCustomization & settings) {
|
||||||
// Dallas Sensor customization
|
// Dallas Sensor customization
|
||||||
@@ -124,17 +124,20 @@ StateUpdateResult WebCustomization::update(JsonObject & root, WebCustomization &
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// load array of entities id's to exclude, building up the object class
|
// load array of entities id's with masks, building up the object class
|
||||||
settings.entityCustomizations.clear();
|
settings.entityCustomizations.clear();
|
||||||
if (root["exclude_entities"].is<JsonArray>()) {
|
if (root["masked_entities"].is<JsonArray>()) {
|
||||||
for (const JsonObject exclude_entities : root["exclude_entities"].as<JsonArray>()) {
|
for (const JsonObject masked_entities : root["masked_entities"].as<JsonArray>()) {
|
||||||
auto new_entry = EntityCustomization();
|
auto new_entry = EntityCustomization();
|
||||||
new_entry.product_id = exclude_entities["product_id"];
|
new_entry.product_id = masked_entities["product_id"];
|
||||||
new_entry.device_id = exclude_entities["device_id"];
|
new_entry.device_id = masked_entities["device_id"];
|
||||||
|
|
||||||
for (const JsonVariant exclude_entity_id : exclude_entities["entity_ids"].as<JsonArray>()) {
|
for (const JsonVariant masked_entity_id : masked_entities["entity_ids"].as<JsonArray>()) {
|
||||||
new_entry.entity_ids.push_back(exclude_entity_id.as<std::string>()); // add entity list
|
if (masked_entity_id.is<std::string>()) {
|
||||||
|
new_entry.entity_ids.push_back(masked_entity_id.as<std::string>()); // add entity list
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
settings.entityCustomizations.push_back(new_entry); // save the new object
|
settings.entityCustomizations.push_back(new_entry); // save the new object
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -157,7 +160,7 @@ void WebCustomizationService::reset_customization(AsyncWebServerRequest * reques
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// send back a short list devices used in the customization page
|
// send back a list of devices used to the customization web page
|
||||||
void WebCustomizationService::devices(AsyncWebServerRequest * request) {
|
void WebCustomizationService::devices(AsyncWebServerRequest * request) {
|
||||||
auto * response = new AsyncJsonResponse(false, EMSESP_JSON_SIZE_LARGE_DYN);
|
auto * response = new AsyncJsonResponse(false, EMSESP_JSON_SIZE_LARGE_DYN);
|
||||||
JsonObject root = response->getRoot();
|
JsonObject root = response->getRoot();
|
||||||
@@ -183,10 +186,10 @@ void WebCustomizationService::devices(AsyncWebServerRequest * request) {
|
|||||||
request->send(response);
|
request->send(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
// send back list device entities
|
// send back list of device entities
|
||||||
void WebCustomizationService::device_entities(AsyncWebServerRequest * request, JsonVariant & json) {
|
void WebCustomizationService::device_entities(AsyncWebServerRequest * request, JsonVariant & json) {
|
||||||
if (json.is<JsonObject>()) {
|
if (json.is<JsonObject>()) {
|
||||||
auto * response = new MsgpackAsyncJsonResponse(true, EMSESP_JSON_SIZE_XXLARGE_DYN);
|
auto * response = new MsgpackAsyncJsonResponse(true, EMSESP_JSON_SIZE_XXXLARGE_DYN);
|
||||||
for (const auto & emsdevice : EMSESP::emsdevices) {
|
for (const auto & emsdevice : EMSESP::emsdevices) {
|
||||||
if (emsdevice->unique_id() == json["id"]) {
|
if (emsdevice->unique_id() == json["id"]) {
|
||||||
#ifndef EMSESP_STANDALONE
|
#ifndef EMSESP_STANDALONE
|
||||||
@@ -205,10 +208,10 @@ void WebCustomizationService::device_entities(AsyncWebServerRequest * request, J
|
|||||||
request->send(response);
|
request->send(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
// takes a list of excluded ids send from the webUI
|
// takes a list of masked ids send from the webUI
|
||||||
// saves it in the customization service
|
// saves it in the customization service
|
||||||
// and updates the entity list real-time
|
// and updates the entity list real-time
|
||||||
void WebCustomizationService::exclude_entities(AsyncWebServerRequest * request, JsonVariant & json) {
|
void WebCustomizationService::masked_entities(AsyncWebServerRequest * request, JsonVariant & json) {
|
||||||
if (json.is<JsonObject>()) {
|
if (json.is<JsonObject>()) {
|
||||||
// find the device using the unique_id
|
// find the device using the unique_id
|
||||||
for (const auto & emsdevice : EMSESP::emsdevices) {
|
for (const auto & emsdevice : EMSESP::emsdevices) {
|
||||||
@@ -218,7 +221,7 @@ void WebCustomizationService::exclude_entities(AsyncWebServerRequest * request,
|
|||||||
// first reset all the entity ids
|
// first reset all the entity ids
|
||||||
emsdevice->reset_entity_masks();
|
emsdevice->reset_entity_masks();
|
||||||
|
|
||||||
// build a list of entities to exclude and then set the flag to non-visible
|
// build a list of entities
|
||||||
JsonArray entity_ids_json = json["entity_ids"];
|
JsonArray entity_ids_json = json["entity_ids"];
|
||||||
std::vector<std::string> entity_ids;
|
std::vector<std::string> entity_ids;
|
||||||
for (JsonVariant id : entity_ids_json) {
|
for (JsonVariant id : entity_ids_json) {
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
// POST
|
// POST
|
||||||
#define DEVICE_ENTITIES_PATH "/rest/deviceEntities"
|
#define DEVICE_ENTITIES_PATH "/rest/deviceEntities"
|
||||||
#define EXCLUDE_ENTITIES_PATH "/rest/excludeEntities"
|
#define MASKED_ENTITIES_PATH "/rest/maskedEntities"
|
||||||
#define RESET_CUSTOMIZATION_SERVICE_PATH "/rest/resetCustomizations"
|
#define RESET_CUSTOMIZATION_SERVICE_PATH "/rest/resetCustomizations"
|
||||||
|
|
||||||
namespace emsesp {
|
namespace emsesp {
|
||||||
@@ -63,15 +63,14 @@ class EntityCustomization {
|
|||||||
public:
|
public:
|
||||||
uint8_t product_id; // device's product id
|
uint8_t product_id; // device's product id
|
||||||
uint8_t device_id; // device's device id
|
uint8_t device_id; // device's device id
|
||||||
std::vector<std::string> entity_ids; // array of entity ids to exclude
|
std::vector<std::string> entity_ids; // array of entity ids with masks
|
||||||
};
|
};
|
||||||
|
|
||||||
class WebCustomization {
|
class WebCustomization {
|
||||||
public:
|
public:
|
||||||
std::list<SensorCustomization> sensorCustomizations; // for sensor names and offsets
|
std::list<SensorCustomization> sensorCustomizations; // for sensor names and offsets
|
||||||
std::list<AnalogCustomization> analogCustomizations; // for analog sensors
|
std::list<AnalogCustomization> analogCustomizations; // for analog sensors
|
||||||
std::list<EntityCustomization> entityCustomizations; // for a list of entities that should be excluded from the device list
|
std::list<EntityCustomization> entityCustomizations; // for a list of entities that have a special mask set
|
||||||
|
|
||||||
static void read(WebCustomization & settings, JsonObject & root);
|
static void read(WebCustomization & settings, JsonObject & root);
|
||||||
static StateUpdateResult update(JsonObject & root, WebCustomization & settings);
|
static StateUpdateResult update(JsonObject & root, WebCustomization & settings);
|
||||||
};
|
};
|
||||||
@@ -94,11 +93,11 @@ class WebCustomizationService : public StatefulService<WebCustomization> {
|
|||||||
void devices(AsyncWebServerRequest * request);
|
void devices(AsyncWebServerRequest * request);
|
||||||
|
|
||||||
// POST
|
// POST
|
||||||
void exclude_entities(AsyncWebServerRequest * request, JsonVariant & json);
|
void masked_entities(AsyncWebServerRequest * request, JsonVariant & json);
|
||||||
void device_entities(AsyncWebServerRequest * request, JsonVariant & json);
|
void device_entities(AsyncWebServerRequest * request, JsonVariant & json);
|
||||||
void reset_customization(AsyncWebServerRequest * request);
|
void reset_customization(AsyncWebServerRequest * request);
|
||||||
|
|
||||||
AsyncCallbackJsonWebHandler _exclude_entities_handler, _device_entities_handler;
|
AsyncCallbackJsonWebHandler _masked_entities_handler, _device_entities_handler;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace emsesp
|
} // namespace emsesp
|
||||||
|
|||||||
Reference in New Issue
Block a user