mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 08:49:52 +03:00
Merge branch 'dev' of https://github.com/emsesp/EMS-ESP32 into dev2x
This commit is contained in:
@@ -182,7 +182,8 @@ bool WebCustomEntityService::command_setvalue(const char * value, const std::str
|
||||
}
|
||||
|
||||
// output of a single value
|
||||
void WebCustomEntityService::render_value(JsonObject & output, CustomEntityItem entity, const bool useVal, const bool web) {
|
||||
// if add_uom is true it will add the UOM string to the value
|
||||
void WebCustomEntityService::render_value(JsonObject & output, CustomEntityItem entity, const bool useVal, const bool web, const bool add_uom) {
|
||||
char payload[12];
|
||||
std::string name = useVal ? "value" : entity.name;
|
||||
switch (entity.value_type) {
|
||||
@@ -201,28 +202,33 @@ void WebCustomEntityService::render_value(JsonObject & output, CustomEntityItem
|
||||
break;
|
||||
case DeviceValueType::INT:
|
||||
if ((int8_t)entity.value != EMS_VALUE_INT_NOTSET) {
|
||||
output[name] = serialized(Helpers::render_value(payload, entity.factor * (int8_t)entity.value, 2));
|
||||
std::string v = Helpers::render_value(payload, entity.factor * (int8_t)entity.value, 2);
|
||||
output[name] = add_uom ? serialized(v + ' ' + EMSdevice::uom_to_string(entity.uom)) : serialized(v);
|
||||
}
|
||||
break;
|
||||
case DeviceValueType::UINT:
|
||||
if ((uint8_t)entity.value != EMS_VALUE_UINT_NOTSET) {
|
||||
output[name] = serialized(Helpers::render_value(payload, entity.factor * (uint8_t)entity.value, 2));
|
||||
std::string v = Helpers::render_value(payload, entity.factor * (uint8_t)entity.value, 2);
|
||||
output[name] = add_uom ? serialized(v + ' ' + EMSdevice::uom_to_string(entity.uom)) : serialized(v);
|
||||
}
|
||||
break;
|
||||
case DeviceValueType::SHORT:
|
||||
if ((int16_t)entity.value != EMS_VALUE_SHORT_NOTSET) {
|
||||
output[name] = serialized(Helpers::render_value(payload, entity.factor * (int16_t)entity.value, 2));
|
||||
std::string v = Helpers::render_value(payload, entity.factor * (int16_t)entity.value, 2);
|
||||
output[name] = add_uom ? serialized(v + ' ' + EMSdevice::uom_to_string(entity.uom)) : serialized(v);
|
||||
}
|
||||
break;
|
||||
case DeviceValueType::USHORT:
|
||||
if ((uint16_t)entity.value != EMS_VALUE_USHORT_NOTSET) {
|
||||
output[name] = serialized(Helpers::render_value(payload, entity.factor * (uint16_t)entity.value, 2));
|
||||
std::string v = Helpers::render_value(payload, entity.factor * (uint16_t)entity.value, 2);
|
||||
output[name] = add_uom ? serialized(v + ' ' + EMSdevice::uom_to_string(entity.uom)) : serialized(v);
|
||||
}
|
||||
break;
|
||||
case DeviceValueType::ULONG:
|
||||
case DeviceValueType::TIME:
|
||||
if (entity.value != EMS_VALUE_ULONG_NOTSET) {
|
||||
output[name] = serialized(Helpers::render_value(payload, entity.factor * entity.value, 2));
|
||||
std::string v = Helpers::render_value(payload, entity.factor * entity.value, 2);
|
||||
output[name] = add_uom ? serialized(v + ' ' + EMSdevice::uom_to_string(entity.uom)) : serialized(v);
|
||||
}
|
||||
break;
|
||||
case DeviceValueType::STRING:
|
||||
@@ -236,6 +242,15 @@ void WebCustomEntityService::render_value(JsonObject & output, CustomEntityItem
|
||||
}
|
||||
}
|
||||
|
||||
// display all custom entities
|
||||
// adding each one, with UOM to a json object string
|
||||
void WebCustomEntityService::show_values(JsonObject & output) {
|
||||
for (const CustomEntityItem & entity : *customEntityItems) {
|
||||
render_value(output, entity, false, false, true); // with add_uom
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// process json output for info/commands and value_info
|
||||
bool WebCustomEntityService::get_value_info(JsonObject & output, const char * cmd) {
|
||||
EMSESP::webCustomEntityService.read([&](WebCustomEntity & webEntity) { customEntityItems = &webEntity.customEntityItems; });
|
||||
@@ -247,11 +262,13 @@ bool WebCustomEntityService::get_value_info(JsonObject & output, const char * cm
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// if no entries, return empty json
|
||||
// https://github.com/emsesp/EMS-ESP32/issues/1297
|
||||
if (customEntityItems->size() == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strlen(cmd) == 0 || Helpers::toLower(cmd) == F_(values) || Helpers::toLower(cmd) == F_(info)) {
|
||||
// list all names
|
||||
for (const CustomEntityItem & entity : *customEntityItems) {
|
||||
@@ -410,7 +427,8 @@ void WebCustomEntityService::publish(const bool force) {
|
||||
}
|
||||
}
|
||||
JsonObject dev = config.createNestedObject("dev");
|
||||
JsonArray ids = dev.createNestedArray("ids");
|
||||
dev["name"] = Mqtt::basename();
|
||||
JsonArray ids = dev.createNestedArray("ids");
|
||||
ids.add(Mqtt::basename());
|
||||
|
||||
// add "availability" section
|
||||
|
||||
@@ -52,22 +52,23 @@ class WebCustomEntityService : public StatefulService<WebCustomEntity> {
|
||||
public:
|
||||
WebCustomEntityService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager);
|
||||
|
||||
void begin();
|
||||
void publish_single(const CustomEntityItem & entity);
|
||||
void publish(const bool force = false);
|
||||
bool command_setvalue(const char * value, const std::string name);
|
||||
bool get_value_info(JsonObject & output, const char * cmd);
|
||||
bool get_value(std::shared_ptr<const Telegram> telegram);
|
||||
void fetch();
|
||||
void render_value(JsonObject & output, CustomEntityItem entity, const bool useVal = false, const bool web = false);
|
||||
void begin();
|
||||
void publish_single(const CustomEntityItem & entity);
|
||||
void publish(const bool force = false);
|
||||
bool command_setvalue(const char * value, const std::string name);
|
||||
bool get_value_info(JsonObject & output, const char * cmd);
|
||||
bool get_value(std::shared_ptr<const Telegram> telegram);
|
||||
void fetch();
|
||||
void render_value(JsonObject & output, CustomEntityItem entity, const bool useVal = false, const bool web = false, const bool add_uom = false);
|
||||
void show_values(JsonObject & output);
|
||||
void generate_value_web(JsonObject & output);
|
||||
|
||||
uint8_t count_entities();
|
||||
uint8_t has_commands();
|
||||
void generate_value_web(JsonObject & output);
|
||||
void ha_reset() {
|
||||
ha_registered_ = false;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
HttpEndpoint<WebCustomEntity> _httpEndpoint;
|
||||
FSPersistence<WebCustomEntity> _fsPersistence;
|
||||
|
||||
@@ -99,7 +99,7 @@ StateUpdateResult WebCustomization::update(JsonObject & root, WebCustomization &
|
||||
#ifdef EMSESP_STANDALONE
|
||||
// invoke some fake data for testing
|
||||
const char * json = "{\"ts\":[],\"as\":[],\"masked_entities\":[{\"product_id\":123,\"device_id\":8,\"entity_ids\":[\"08heatingactive|my custom "
|
||||
"name for heating active\",\"08tapwateractive\"]}]}";
|
||||
"name for heating active (HS1)\",\"08tapwateractive\"]}]}";
|
||||
StaticJsonDocument<500> doc;
|
||||
deserializeJson(doc, json);
|
||||
root = doc.as<JsonObject>();
|
||||
|
||||
@@ -288,7 +288,8 @@ void WebSchedulerService::publish(const bool force) {
|
||||
}
|
||||
|
||||
JsonObject dev = config.createNestedObject("dev");
|
||||
JsonArray ids = dev.createNestedArray("ids");
|
||||
dev["name"] = Mqtt::basename();
|
||||
JsonArray ids = dev.createNestedArray("ids");
|
||||
ids.add(Mqtt::basename());
|
||||
|
||||
// add "availability" section
|
||||
|
||||
Reference in New Issue
Block a user