scheduler: onChange and conditions

This commit is contained in:
MichaelDvP
2024-06-15 20:00:08 +02:00
parent ffb7fd3f12
commit fc75824921
10 changed files with 648 additions and 62 deletions

View File

@@ -175,6 +175,9 @@ bool WebCustomEntityService::command_setvalue(const char * value, const std::str
if (EMSESP::mqtt_.get_publish_onchange(0)) {
publish();
}
char cmd[COMMAND_MAX_LENGTH];
snprintf(cmd, sizeof(cmd_function_p), "custom/%s", entityItem.name.c_str());
EMSESP::webSchedulerService.onChange(cmd);
return true;
}
}
@@ -591,7 +594,7 @@ void WebCustomEntityService::fetch() {
bool WebCustomEntityService::get_value(std::shared_ptr<const Telegram> telegram) {
bool has_change = false;
EMSESP::webCustomEntityService.read([&](WebCustomEntity & webEntity) { customEntityItems = &webEntity.customEntityItems; });
// read-length of BOOL, INT, UINT, SHORT, USHORT, ULONG, TIME
// read-length of BOOL, INT8, UINT8, INT16, UINT16, UINT24, TIME, UINT32
const uint8_t len[] = {1, 1, 1, 2, 2, 3, 3, 4};
for (auto & entity : *customEntityItems) {
if (entity.value_type == DeviceValueType::STRING && telegram->type_id == entity.type_id && telegram->src == entity.device_id
@@ -604,6 +607,9 @@ bool WebCustomEntityService::get_value(std::shared_ptr<const Telegram> telegram)
} else if (EMSESP::mqtt_.get_publish_onchange(0)) {
has_change = true;
}
char cmd[COMMAND_MAX_LENGTH];
snprintf(cmd, sizeof(cmd_function_p), "custom/%s", entity.name.c_str());
EMSESP::webSchedulerService.onChange(cmd);
}
} else if (entity.value_type != DeviceValueType::STRING && telegram->type_id == entity.type_id && telegram->src == entity.device_id
&& telegram->offset <= entity.offset && (telegram->offset + telegram->message_length) >= (entity.offset + len[entity.value_type])) {
@@ -618,6 +624,9 @@ bool WebCustomEntityService::get_value(std::shared_ptr<const Telegram> telegram)
} else if (EMSESP::mqtt_.get_publish_onchange(0)) {
has_change = true;
}
char cmd[COMMAND_MAX_LENGTH];
snprintf(cmd, sizeof(cmd_function_p), "%s/%s", "custom", entity.name.c_str());
EMSESP::webSchedulerService.onChange(cmd);
}
// EMSESP::logger().debug("custom entity %s received with value %d", entity.name.c_str(), (int)entity.val);
}