mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 16:59:50 +03:00
remove OriginID from state service
This commit is contained in:
@@ -628,52 +628,50 @@ bool WebCustomEntityService::get_value(std::shared_ptr<const Telegram> telegram)
|
||||
// hard coded tests
|
||||
#ifdef EMSESP_TEST
|
||||
void WebCustomEntityService::test() {
|
||||
update(
|
||||
[&](WebCustomEntity & webCustomEntity) {
|
||||
webCustomEntity.customEntityItems.clear();
|
||||
// test 1
|
||||
auto entityItem = CustomEntityItem();
|
||||
entityItem.ram = 0;
|
||||
entityItem.device_id = 8;
|
||||
entityItem.type_id = 24;
|
||||
entityItem.offset = 0;
|
||||
entityItem.factor = 1;
|
||||
entityItem.name = "test_custom";
|
||||
entityItem.uom = 1;
|
||||
entityItem.value_type = 1;
|
||||
entityItem.writeable = true;
|
||||
entityItem.data = "70";
|
||||
webCustomEntity.customEntityItems.push_back(entityItem);
|
||||
update([&](WebCustomEntity & webCustomEntity) {
|
||||
webCustomEntity.customEntityItems.clear();
|
||||
// test 1
|
||||
auto entityItem = CustomEntityItem();
|
||||
entityItem.ram = 0;
|
||||
entityItem.device_id = 8;
|
||||
entityItem.type_id = 24;
|
||||
entityItem.offset = 0;
|
||||
entityItem.factor = 1;
|
||||
entityItem.name = "test_custom";
|
||||
entityItem.uom = 1;
|
||||
entityItem.value_type = 1;
|
||||
entityItem.writeable = true;
|
||||
entityItem.data = "70";
|
||||
webCustomEntity.customEntityItems.push_back(entityItem);
|
||||
|
||||
// test 2
|
||||
entityItem.ram = 0;
|
||||
entityItem.device_id = 24;
|
||||
entityItem.type_id = 677;
|
||||
entityItem.offset = 3;
|
||||
entityItem.factor = 1;
|
||||
entityItem.name = "test_read_only";
|
||||
entityItem.uom = 0;
|
||||
entityItem.value_type = 2;
|
||||
entityItem.writeable = false;
|
||||
entityItem.data = "48";
|
||||
webCustomEntity.customEntityItems.push_back(entityItem);
|
||||
// test 2
|
||||
entityItem.ram = 0;
|
||||
entityItem.device_id = 24;
|
||||
entityItem.type_id = 677;
|
||||
entityItem.offset = 3;
|
||||
entityItem.factor = 1;
|
||||
entityItem.name = "test_read_only";
|
||||
entityItem.uom = 0;
|
||||
entityItem.value_type = 2;
|
||||
entityItem.writeable = false;
|
||||
entityItem.data = "48";
|
||||
webCustomEntity.customEntityItems.push_back(entityItem);
|
||||
|
||||
// test 2
|
||||
entityItem.ram = 1;
|
||||
entityItem.device_id = 0;
|
||||
entityItem.type_id = 0;
|
||||
entityItem.offset = 0;
|
||||
entityItem.factor = 1;
|
||||
entityItem.name = "test_ram";
|
||||
entityItem.uom = 0;
|
||||
entityItem.value_type = 8;
|
||||
entityItem.writeable = true;
|
||||
entityItem.data = "14";
|
||||
webCustomEntity.customEntityItems.push_back(entityItem);
|
||||
// test 2
|
||||
entityItem.ram = 1;
|
||||
entityItem.device_id = 0;
|
||||
entityItem.type_id = 0;
|
||||
entityItem.offset = 0;
|
||||
entityItem.factor = 1;
|
||||
entityItem.name = "test_ram";
|
||||
entityItem.uom = 0;
|
||||
entityItem.value_type = 8;
|
||||
entityItem.writeable = true;
|
||||
entityItem.data = "14";
|
||||
webCustomEntity.customEntityItems.push_back(entityItem);
|
||||
|
||||
return StateUpdateResult::CHANGED; // persist the changes
|
||||
},
|
||||
"local");
|
||||
return StateUpdateResult::CHANGED; // persist the changes
|
||||
});
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -276,30 +276,28 @@ void WebCustomizationService::customization_entities(AsyncWebServerRequest * req
|
||||
emsdevice->getCustomizationEntities(entity_ids);
|
||||
|
||||
// Save the list to the customization file
|
||||
update(
|
||||
[&](WebCustomization & settings) {
|
||||
// see if we already have a mask list for this device, if so remove it
|
||||
for (auto it = settings.entityCustomizations.begin(); it != settings.entityCustomizations.end();) {
|
||||
if ((*it).product_id == product_id && (*it).device_id == device_id) {
|
||||
it = settings.entityCustomizations.erase(it);
|
||||
break;
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
update([&](WebCustomization & settings) {
|
||||
// see if we already have a mask list for this device, if so remove it
|
||||
for (auto it = settings.entityCustomizations.begin(); it != settings.entityCustomizations.end();) {
|
||||
if ((*it).product_id == product_id && (*it).device_id == device_id) {
|
||||
it = settings.entityCustomizations.erase(it);
|
||||
break;
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
// create a new entry for this device if there are values
|
||||
EntityCustomization new_entry;
|
||||
new_entry.product_id = product_id;
|
||||
new_entry.device_id = device_id;
|
||||
// create a new entry for this device if there are values
|
||||
EntityCustomization new_entry;
|
||||
new_entry.product_id = product_id;
|
||||
new_entry.device_id = device_id;
|
||||
|
||||
new_entry.entity_ids = entity_ids;
|
||||
new_entry.entity_ids = entity_ids;
|
||||
|
||||
// add the record and save
|
||||
settings.entityCustomizations.push_back(new_entry);
|
||||
return StateUpdateResult::CHANGED;
|
||||
},
|
||||
"local");
|
||||
// add the record and save
|
||||
settings.entityCustomizations.push_back(new_entry);
|
||||
return StateUpdateResult::CHANGED;
|
||||
});
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -320,54 +318,52 @@ void WebCustomizationService::begin() {
|
||||
// hard coded tests
|
||||
#ifdef EMSESP_TEST
|
||||
void WebCustomizationService::test() {
|
||||
update(
|
||||
[&](WebCustomization & webCustomization) {
|
||||
// Temperature sensors
|
||||
webCustomization.sensorCustomizations.clear();
|
||||
auto sensor = SensorCustomization();
|
||||
sensor.id = "01-0203-0405-0607";
|
||||
sensor.name = "test_sensor1";
|
||||
sensor.offset = 0;
|
||||
webCustomization.sensorCustomizations.push_back(sensor);
|
||||
update([&](WebCustomization & webCustomization) {
|
||||
// Temperature sensors
|
||||
webCustomization.sensorCustomizations.clear();
|
||||
auto sensor = SensorCustomization();
|
||||
sensor.id = "01-0203-0405-0607";
|
||||
sensor.name = "test_sensor1";
|
||||
sensor.offset = 0;
|
||||
webCustomization.sensorCustomizations.push_back(sensor);
|
||||
|
||||
sensor = SensorCustomization();
|
||||
sensor.id = "0B-0C0D-0E0F-1011";
|
||||
sensor.name = "test_sensor2";
|
||||
sensor.offset = 4;
|
||||
webCustomization.sensorCustomizations.push_back(sensor);
|
||||
sensor = SensorCustomization();
|
||||
sensor.id = "0B-0C0D-0E0F-1011";
|
||||
sensor.name = "test_sensor2";
|
||||
sensor.offset = 4;
|
||||
webCustomization.sensorCustomizations.push_back(sensor);
|
||||
|
||||
// Analog sensors
|
||||
// This actually adds the sensors as we use customizations to store them
|
||||
webCustomization.analogCustomizations.clear();
|
||||
auto analog = AnalogCustomization();
|
||||
analog.gpio = 36;
|
||||
analog.name = "test_analog1";
|
||||
analog.offset = 0;
|
||||
analog.factor = 0.1;
|
||||
analog.uom = 17;
|
||||
analog.type = 3;
|
||||
webCustomization.analogCustomizations.push_back(analog);
|
||||
// Analog sensors
|
||||
// This actually adds the sensors as we use customizations to store them
|
||||
webCustomization.analogCustomizations.clear();
|
||||
auto analog = AnalogCustomization();
|
||||
analog.gpio = 36;
|
||||
analog.name = "test_analog1";
|
||||
analog.offset = 0;
|
||||
analog.factor = 0.1;
|
||||
analog.uom = 17;
|
||||
analog.type = 3;
|
||||
webCustomization.analogCustomizations.push_back(analog);
|
||||
|
||||
analog = AnalogCustomization();
|
||||
analog.gpio = 37;
|
||||
analog.name = "test_analog2";
|
||||
analog.offset = 0;
|
||||
analog.factor = 1;
|
||||
analog.uom = 0;
|
||||
analog.type = 1;
|
||||
webCustomization.analogCustomizations.push_back(analog);
|
||||
analog = AnalogCustomization();
|
||||
analog.gpio = 37;
|
||||
analog.name = "test_analog2";
|
||||
analog.offset = 0;
|
||||
analog.factor = 1;
|
||||
analog.uom = 0;
|
||||
analog.type = 1;
|
||||
webCustomization.analogCustomizations.push_back(analog);
|
||||
|
||||
// EMS entities
|
||||
webCustomization.entityCustomizations.clear();
|
||||
auto emsEntity = EntityCustomization();
|
||||
emsEntity.product_id = 123;
|
||||
emsEntity.device_id = 8;
|
||||
emsEntity.entity_ids.push_back("08heatingactive|is my heating on?");
|
||||
webCustomization.entityCustomizations.push_back(emsEntity);
|
||||
// EMS entities
|
||||
webCustomization.entityCustomizations.clear();
|
||||
auto emsEntity = EntityCustomization();
|
||||
emsEntity.product_id = 123;
|
||||
emsEntity.device_id = 8;
|
||||
emsEntity.entity_ids.push_back("08heatingactive|is my heating on?");
|
||||
webCustomization.entityCustomizations.push_back(emsEntity);
|
||||
|
||||
return StateUpdateResult::CHANGED; // persist the changes
|
||||
},
|
||||
"local");
|
||||
return StateUpdateResult::CHANGED; // persist the changes
|
||||
});
|
||||
|
||||
EMSESP::analogsensor_.reload(); // this is needed to active the analog sensors
|
||||
}
|
||||
|
||||
@@ -59,12 +59,10 @@ uuid::log::Level WebLogService::log_level() const {
|
||||
}
|
||||
|
||||
void WebLogService::log_level(uuid::log::Level level) {
|
||||
EMSESP::webSettingsService.update(
|
||||
[&](WebSettings & settings) {
|
||||
settings.weblog_level = level;
|
||||
return StateUpdateResult::CHANGED;
|
||||
},
|
||||
"local");
|
||||
EMSESP::webSettingsService.update([&](WebSettings & settings) {
|
||||
settings.weblog_level = level;
|
||||
return StateUpdateResult::CHANGED;
|
||||
});
|
||||
uuid::log::Logger::register_handler(this, level);
|
||||
if (level == uuid::log::Level::OFF) {
|
||||
log_messages_.clear();
|
||||
@@ -87,12 +85,10 @@ void WebLogService::maximum_log_messages(size_t count) {
|
||||
while (log_messages_.size() > maximum_log_messages_) {
|
||||
log_messages_.pop_front();
|
||||
}
|
||||
EMSESP::webSettingsService.update(
|
||||
[&](WebSettings & settings) {
|
||||
settings.weblog_buffer = count;
|
||||
return StateUpdateResult::CHANGED;
|
||||
},
|
||||
"local");
|
||||
EMSESP::webSettingsService.update([&](WebSettings & settings) {
|
||||
settings.weblog_buffer = count;
|
||||
return StateUpdateResult::CHANGED;
|
||||
});
|
||||
}
|
||||
|
||||
bool WebLogService::compact() const {
|
||||
@@ -101,12 +97,10 @@ bool WebLogService::compact() const {
|
||||
|
||||
void WebLogService::compact(bool compact) {
|
||||
compact_ = compact;
|
||||
EMSESP::webSettingsService.update(
|
||||
[&](WebSettings & settings) {
|
||||
settings.weblog_compact = compact;
|
||||
return StateUpdateResult::CHANGED;
|
||||
},
|
||||
"local");
|
||||
EMSESP::webSettingsService.update([&](WebSettings & settings) {
|
||||
settings.weblog_compact = compact;
|
||||
return StateUpdateResult::CHANGED;
|
||||
});
|
||||
}
|
||||
|
||||
WebLogService::QueuedLogMessage::QueuedLogMessage(unsigned long id, std::shared_ptr<uuid::log::Message> && content)
|
||||
|
||||
@@ -432,25 +432,23 @@ void WebSchedulerService::loop() {
|
||||
// hard coded tests
|
||||
#if defined(EMSESP_TEST)
|
||||
void WebSchedulerService::test() {
|
||||
update(
|
||||
[&](WebScheduler & webScheduler) {
|
||||
webScheduler.scheduleItems.clear();
|
||||
// test 1
|
||||
auto si = ScheduleItem();
|
||||
si.active = true;
|
||||
si.flags = 1;
|
||||
si.time = "12:00";
|
||||
si.cmd = "system/fetch";
|
||||
si.value = "10";
|
||||
si.name = "test_scheduler";
|
||||
si.elapsed_min = 0;
|
||||
si.retry_cnt = 0xFF; // no startup retries
|
||||
update([&](WebScheduler & webScheduler) {
|
||||
webScheduler.scheduleItems.clear();
|
||||
// test 1
|
||||
auto si = ScheduleItem();
|
||||
si.active = true;
|
||||
si.flags = 1;
|
||||
si.time = "12:00";
|
||||
si.cmd = "system/fetch";
|
||||
si.value = "10";
|
||||
si.name = "test_scheduler";
|
||||
si.elapsed_min = 0;
|
||||
si.retry_cnt = 0xFF; // no startup retries
|
||||
|
||||
webScheduler.scheduleItems.push_back(si);
|
||||
webScheduler.scheduleItems.push_back(si);
|
||||
|
||||
return StateUpdateResult::CHANGED; // persist the changes
|
||||
},
|
||||
"local");
|
||||
return StateUpdateResult::CHANGED; // persist the changes
|
||||
});
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ WebSettingsService::WebSettingsService(AsyncWebServer * server, FS * fs, Securit
|
||||
HTTP_GET,
|
||||
securityManager->wrapRequest(std::bind(&WebSettingsService::board_profile, this, _1), AuthenticationPredicates::IS_ADMIN));
|
||||
|
||||
addUpdateHandler([&](const String & originId) { onUpdate(); }, false);
|
||||
addUpdateHandler([&] { onUpdate(); }, false);
|
||||
}
|
||||
|
||||
void WebSettings::read(WebSettings & settings, JsonObject root) {
|
||||
|
||||
Reference in New Issue
Block a user