diff --git a/interface/src/project/api.ts b/interface/src/project/api.ts index f3a29a6bc..e605332fb 100644 --- a/interface/src/project/api.ts +++ b/interface/src/project/api.ts @@ -12,7 +12,7 @@ import { DeviceData, DeviceEntity, UniqueID, - ExcludeEntities, + MaskedEntities, WriteValue, WriteSensor, WriteAnalog, @@ -63,8 +63,8 @@ export function readDeviceEntities(unique_id: UniqueID): AxiosPromise { - return AXIOS.post('/excludeEntities', excludeEntities); +export function writeMaskedEntities(maskedEntities: MaskedEntities): AxiosPromise { + return AXIOS.post('/maskedEntities', maskedEntities); } export function writeValue(writevalue: WriteValue): AxiosPromise { diff --git a/interface/src/project/types.ts b/interface/src/project/types.ts index 226873bdd..5bcf45dad 100644 --- a/interface/src/project/types.ts +++ b/interface/src/project/types.ts @@ -146,11 +146,11 @@ export interface DeviceEntity { v?: any; // value, in any format n: string; // name s: string; // shortname - x: boolean; // excluded flag + m: number; // mask i: number; // unique id } -export interface ExcludeEntities { +export interface MaskedEntities { id: number; entity_ids: string[]; } diff --git a/src/system.cpp b/src/system.cpp index ab29b4a68..bf8f9ec26 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -1018,7 +1018,6 @@ bool System::command_customizations(const char * value, const int8_t id, JsonObj JsonObject node = output.createNestedObject("Customizations"); - // hide ssid from this list EMSESP::webCustomizationService.read([&](WebCustomization & settings) { // 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"); for (const auto & entityCustomization : settings.entityCustomizations) { JsonObject entityJson = mask_entitiesJson.createNestedObject(); diff --git a/src/test/test.cpp b/src/test/test.cpp index ee4635ee5..960332c58 100644 --- a/src/test/test.cpp +++ b/src/test/test.cpp @@ -595,8 +595,8 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const EMSESP::system_.healthcheck(n); } - if (command == "exclude") { - shell.printfln(F("Testing exclude entities")); + if (command == "masked") { + shell.printfln(F("Testing masked entities")); Mqtt::ha_enabled(true); Mqtt::send_response(false); diff --git a/src/test/test.h b/src/test/test.h index 9ca31dd36..65021652e 100644 --- a/src/test/test.h +++ b/src/test/test.h @@ -31,12 +31,12 @@ namespace emsesp { // #define EMSESP_DEBUG_DEFAULT "mixer" // #define EMSESP_DEBUG_DEFAULT "web" // #define EMSESP_DEBUG_DEFAULT "mqtt" -// #define EMSESP_DEBUG_DEFAULT "general" +#define EMSESP_DEBUG_DEFAULT "general" // #define EMSESP_DEBUG_DEFAULT "boiler" // #define EMSESP_DEBUG_DEFAULT "mqtt2" // #define EMSESP_DEBUG_DEFAULT "mqtt_nested" -#define EMSESP_DEBUG_DEFAULT "ha" -// #define EMSESP_DEBUG_DEFAULT "exclude" +// #define EMSESP_DEBUG_DEFAULT "ha" +// #define EMSESP_DEBUG_DEFAULT "masked" // #define EMSESP_DEBUG_DEFAULT "board_profile" // #define EMSESP_DEBUG_DEFAULT "shower_alert" // #define EMSESP_DEBUG_DEFAULT "310" diff --git a/src/web/WebCustomizationService.cpp b/src/web/WebCustomizationService.cpp index 44301e2a6..21bc198ba 100644 --- a/src/web/WebCustomizationService.cpp +++ b/src/web/WebCustomizationService.cpp @@ -31,9 +31,9 @@ WebCustomizationService::WebCustomizationService(AsyncWebServer * server, FS * f securityManager, AuthenticationPredicates::IS_AUTHENTICATED) , _fsPersistence(WebCustomization::read, WebCustomization::update, this, fs, EMSESP_CUSTOMIZATION_FILE) - , _exclude_entities_handler(EXCLUDE_ENTITIES_PATH, - securityManager->wrapCallback(std::bind(&WebCustomizationService::exclude_entities, this, _1, _2), - AuthenticationPredicates::IS_AUTHENTICATED)) + , _masked_entities_handler(MASKED_ENTITIES_PATH, + securityManager->wrapCallback(std::bind(&WebCustomizationService::masked_entities, this, _1, _2), + AuthenticationPredicates::IS_AUTHENTICATED)) , _device_entities_handler(DEVICE_ENTITIES_PATH, securityManager->wrapCallback(std::bind(&WebCustomizationService::device_entities, this, _1, _2), AuthenticationPredicates::IS_AUTHENTICATED)) { @@ -45,17 +45,17 @@ WebCustomizationService::WebCustomizationService(AsyncWebServer * server, FS * f HTTP_POST, securityManager->wrapRequest(std::bind(&WebCustomizationService::reset_customization, this, _1), AuthenticationPredicates::IS_ADMIN)); - _exclude_entities_handler.setMethod(HTTP_POST); - _exclude_entities_handler.setMaxContentLength(2048); - _exclude_entities_handler.setMaxJsonBufferSize(2048); - server->addHandler(&_exclude_entities_handler); + _masked_entities_handler.setMethod(HTTP_POST); + _masked_entities_handler.setMaxContentLength(2048); + _masked_entities_handler.setMaxJsonBufferSize(2048); + server->addHandler(&_masked_entities_handler); _device_entities_handler.setMethod(HTTP_POST); _device_entities_handler.setMaxContentLength(256); 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) { // Dallas Sensor customization JsonArray sensorsJson = root.createNestedArray("sensors"); @@ -78,21 +78,21 @@ void WebCustomization::read(WebCustomization & settings, JsonObject & root) { sensorJson["type"] = sensor.type; // t } - // Exclude entities customization - JsonArray exclude_entitiesJson = root.createNestedArray("exclude_entities"); + // Masked entities customization + JsonArray masked_entitiesJson = root.createNestedArray("masked_entities"); for (const EntityCustomization & entityCustomization : settings.entityCustomizations) { - JsonObject entityJson = exclude_entitiesJson.createNestedObject(); + JsonObject entityJson = masked_entitiesJson.createNestedObject(); entityJson["product_id"] = entityCustomization.product_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) { - 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 StateUpdateResult WebCustomization::update(JsonObject & root, WebCustomization & settings) { // 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(); - if (root["exclude_entities"].is()) { - for (const JsonObject exclude_entities : root["exclude_entities"].as()) { + if (root["masked_entities"].is()) { + for (const JsonObject masked_entities : root["masked_entities"].as()) { auto new_entry = EntityCustomization(); - new_entry.product_id = exclude_entities["product_id"]; - new_entry.device_id = exclude_entities["device_id"]; + new_entry.product_id = masked_entities["product_id"]; + new_entry.device_id = masked_entities["device_id"]; - for (const JsonVariant exclude_entity_id : exclude_entities["entity_ids"].as()) { - new_entry.entity_ids.push_back(exclude_entity_id.as()); // add entity list + for (const JsonVariant masked_entity_id : masked_entities["entity_ids"].as()) { + if (masked_entity_id.is()) { + new_entry.entity_ids.push_back(masked_entity_id.as()); // add entity list + } } + settings.entityCustomizations.push_back(new_entry); // save the new object } } @@ -157,7 +160,7 @@ void WebCustomizationService::reset_customization(AsyncWebServerRequest * reques #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) { auto * response = new AsyncJsonResponse(false, EMSESP_JSON_SIZE_LARGE_DYN); JsonObject root = response->getRoot(); @@ -183,10 +186,10 @@ void WebCustomizationService::devices(AsyncWebServerRequest * request) { request->send(response); } -// send back list device entities +// send back list of device entities void WebCustomizationService::device_entities(AsyncWebServerRequest * request, JsonVariant & json) { if (json.is()) { - 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) { if (emsdevice->unique_id() == json["id"]) { #ifndef EMSESP_STANDALONE @@ -205,10 +208,10 @@ void WebCustomizationService::device_entities(AsyncWebServerRequest * request, J 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 // 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()) { // find the device using the unique_id for (const auto & emsdevice : EMSESP::emsdevices) { @@ -218,7 +221,7 @@ void WebCustomizationService::exclude_entities(AsyncWebServerRequest * request, // first reset all the entity ids 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"]; std::vector entity_ids; for (JsonVariant id : entity_ids_json) { diff --git a/src/web/WebCustomizationService.h b/src/web/WebCustomizationService.h index 1c34ac80d..526259dbe 100644 --- a/src/web/WebCustomizationService.h +++ b/src/web/WebCustomizationService.h @@ -27,7 +27,7 @@ // POST #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" namespace emsesp { @@ -63,17 +63,16 @@ class EntityCustomization { public: uint8_t product_id; // device's product id uint8_t device_id; // device's device id - std::vector entity_ids; // array of entity ids to exclude + std::vector entity_ids; // array of entity ids with masks }; class WebCustomization { public: std::list sensorCustomizations; // for sensor names and offsets std::list analogCustomizations; // for analog sensors - std::list entityCustomizations; // for a list of entities that should be excluded from the device list - - static void read(WebCustomization & settings, JsonObject & root); - static StateUpdateResult update(JsonObject & root, WebCustomization & settings); + std::list entityCustomizations; // for a list of entities that have a special mask set + static void read(WebCustomization & settings, JsonObject & root); + static StateUpdateResult update(JsonObject & root, WebCustomization & settings); }; class WebCustomizationService : public StatefulService { @@ -94,11 +93,11 @@ class WebCustomizationService : public StatefulService { void devices(AsyncWebServerRequest * request); // POST - void exclude_entities(AsyncWebServerRequest * request, JsonVariant & json); + void masked_entities(AsyncWebServerRequest * request, JsonVariant & json); void device_entities(AsyncWebServerRequest * request, JsonVariant & json); void reset_customization(AsyncWebServerRequest * request); - AsyncCallbackJsonWebHandler _exclude_entities_handler, _device_entities_handler; + AsyncCallbackJsonWebHandler _masked_entities_handler, _device_entities_handler; }; } // namespace emsesp