mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
Merge pull request #2050 from MichaelDvP/dev
show emsesp-devices in system info, add common fields to value_info #2033
This commit is contained in:
@@ -665,11 +665,15 @@ bool AnalogSensor::get_value_info(JsonObject output, const char * cmd, const int
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AnalogSensor::get_value_json(JsonObject output, const Sensor & sensor) {
|
void AnalogSensor::get_value_json(JsonObject output, const Sensor & sensor) {
|
||||||
|
output["name"] = sensor.name();
|
||||||
|
output["fullname"] = sensor.name();
|
||||||
output["gpio"] = sensor.gpio();
|
output["gpio"] = sensor.gpio();
|
||||||
output["type"] = F_(number);
|
output["type"] = F_(number);
|
||||||
output["analog"] = FL_(list_sensortype)[sensor.type()];
|
output["analog"] = FL_(list_sensortype)[sensor.type()];
|
||||||
output["value"] = sensor.value();
|
output["value"] = sensor.value();
|
||||||
|
output["readable"] = true;
|
||||||
output["writeable"] = sensor.type() == AnalogType::COUNTER || (sensor.type() >= AnalogType::DIGITAL_OUT && sensor.type() <= AnalogType::PWM_2);
|
output["writeable"] = sensor.type() == AnalogType::COUNTER || (sensor.type() >= AnalogType::DIGITAL_OUT && sensor.type() <= AnalogType::PWM_2);
|
||||||
|
output["visible"] = true;
|
||||||
if (sensor.type() == AnalogType::COUNTER) {
|
if (sensor.type() == AnalogType::COUNTER) {
|
||||||
output["min"] = 0;
|
output["min"] = 0;
|
||||||
output["max"] = 4000000;
|
output["max"] = 4000000;
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ class AnalogSensor {
|
|||||||
return (!sensors_.empty());
|
return (!sensors_.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t no_sensors() const {
|
size_t count_entities() const {
|
||||||
return sensors_.size();
|
return sensors_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1593,12 +1593,12 @@ bool System::command_info(const char * value, const int8_t id, JsonObject output
|
|||||||
// Sensor Status
|
// Sensor Status
|
||||||
node = output["sensor"].to<JsonObject>();
|
node = output["sensor"].to<JsonObject>();
|
||||||
if (EMSESP::sensor_enabled()) {
|
if (EMSESP::sensor_enabled()) {
|
||||||
node["temperatureSensors"] = EMSESP::temperaturesensor_.no_sensors();
|
node["temperatureSensors"] = EMSESP::temperaturesensor_.count_entities();
|
||||||
node["temperatureSensorReads"] = EMSESP::temperaturesensor_.reads();
|
node["temperatureSensorReads"] = EMSESP::temperaturesensor_.reads();
|
||||||
node["temperatureSensorFails"] = EMSESP::temperaturesensor_.fails();
|
node["temperatureSensorFails"] = EMSESP::temperaturesensor_.fails();
|
||||||
}
|
}
|
||||||
if (EMSESP::analog_enabled()) {
|
if (EMSESP::analog_enabled()) {
|
||||||
node["analogSensors"] = EMSESP::analogsensor_.no_sensors();
|
node["analogSensors"] = EMSESP::analogsensor_.count_entities();
|
||||||
node["analogSensorReads"] = EMSESP::analogsensor_.reads();
|
node["analogSensorReads"] = EMSESP::analogsensor_.reads();
|
||||||
node["analogSensorFails"] = EMSESP::analogsensor_.fails();
|
node["analogSensorFails"] = EMSESP::analogsensor_.fails();
|
||||||
}
|
}
|
||||||
@@ -1691,8 +1691,8 @@ bool System::command_info(const char * value, const int8_t id, JsonObject output
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Devices - show EMS devices if we have any
|
// Devices - show EMS devices if we have any
|
||||||
|
JsonArray devices = output["devices"].to<JsonArray>();
|
||||||
if (!EMSESP::emsdevices.empty()) {
|
if (!EMSESP::emsdevices.empty()) {
|
||||||
JsonArray devices = output["devices"].to<JsonArray>();
|
|
||||||
for (const auto & device_class : EMSFactory::device_handlers()) {
|
for (const auto & device_class : EMSFactory::device_handlers()) {
|
||||||
for (const auto & emsdevice : EMSESP::emsdevices) {
|
for (const auto & emsdevice : EMSESP::emsdevices) {
|
||||||
if (emsdevice && (emsdevice->device_type() == device_class.first)) {
|
if (emsdevice && (emsdevice->device_type() == device_class.first)) {
|
||||||
@@ -1725,6 +1725,32 @@ bool System::command_info(const char * value, const int8_t id, JsonObject output
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Also show EMSESP devices if we have any
|
||||||
|
if (EMSESP::temperaturesensor_.count_entities()) {
|
||||||
|
JsonObject obj = devices.add<JsonObject>();
|
||||||
|
obj["type"] = F_(temperaturesensor);
|
||||||
|
obj["name"] = F_(temperaturesensor);
|
||||||
|
obj["entities"] = EMSESP::temperaturesensor_.count_entities();
|
||||||
|
}
|
||||||
|
// if (EMSESP::analog_enabled()) {
|
||||||
|
if (EMSESP::analogsensor_.count_entities()) {
|
||||||
|
JsonObject obj = devices.add<JsonObject>();
|
||||||
|
obj["type"] = F_(analogsensor);
|
||||||
|
obj["name"] = F_(analogsensor);
|
||||||
|
obj["entities"] = EMSESP::analogsensor_.count_entities();
|
||||||
|
}
|
||||||
|
if (EMSESP::webSchedulerService.count_entities()) {
|
||||||
|
JsonObject obj = devices.add<JsonObject>();
|
||||||
|
obj["type"] = F_(scheduler);
|
||||||
|
obj["name"] = F_(scheduler);
|
||||||
|
obj["entities"] = EMSESP::webSchedulerService.count_entities();
|
||||||
|
}
|
||||||
|
if (EMSESP::webCustomEntityService.count_entities()) {
|
||||||
|
JsonObject obj = devices.add<JsonObject>();
|
||||||
|
obj["type"] = F_(custom);
|
||||||
|
obj["name"] = F_(custom);
|
||||||
|
obj["entities"] = EMSESP::webCustomEntityService.count_entities();
|
||||||
|
}
|
||||||
|
|
||||||
return true; // this function always returns true!
|
return true; // this function always returns true!
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -380,8 +380,9 @@ bool TemperatureSensor::get_value_info(JsonObject output, const char * cmd, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TemperatureSensor::get_value_json(JsonObject output, const Sensor & sensor) {
|
void TemperatureSensor::get_value_json(JsonObject output, const Sensor & sensor) {
|
||||||
output["id"] = sensor.id();
|
output["id"] = sensor.id();
|
||||||
output["name"] = sensor.name();
|
output["name"] = sensor.name();
|
||||||
|
output["fullname"] = sensor.name();
|
||||||
if (Helpers::hasValue(sensor.temperature_c)) {
|
if (Helpers::hasValue(sensor.temperature_c)) {
|
||||||
char val[10];
|
char val[10];
|
||||||
output["value"] = serialized(Helpers::render_value(val, sensor.temperature_c, 10, EMSESP::system_.fahrenheit() ? 2 : 0));
|
output["value"] = serialized(Helpers::render_value(val, sensor.temperature_c, 10, EMSESP::system_.fahrenheit() ? 2 : 0));
|
||||||
@@ -389,7 +390,9 @@ void TemperatureSensor::get_value_json(JsonObject output, const Sensor & sensor)
|
|||||||
|
|
||||||
output["type"] = F_(number);
|
output["type"] = F_(number);
|
||||||
output["uom"] = EMSdevice::uom_to_string(DeviceValueUOM::DEGREES);
|
output["uom"] = EMSdevice::uom_to_string(DeviceValueUOM::DEGREES);
|
||||||
|
output["readable"] = true;
|
||||||
output["writeable"] = false;
|
output["writeable"] = false;
|
||||||
|
output["visible"] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ class TemperatureSensor {
|
|||||||
return (!sensors_.empty());
|
return (!sensors_.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t no_sensors() {
|
size_t count_entities() {
|
||||||
return sensors_.size();
|
return sensors_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -320,9 +320,10 @@ bool WebCustomEntityService::get_value_info(JsonObject output, const char * cmd)
|
|||||||
|
|
||||||
// build the json for specific entity
|
// build the json for specific entity
|
||||||
void WebCustomEntityService::get_value_json(JsonObject output, const CustomEntityItem & entity) {
|
void WebCustomEntityService::get_value_json(JsonObject output, const CustomEntityItem & entity) {
|
||||||
output["name"] = entity.name;
|
output["name"] = entity.name;
|
||||||
output["storage"] = entity.ram ? "ram" : "ems";
|
output["fullname"] = entity.name;
|
||||||
output["type"] = entity.value_type == DeviceValueType::BOOL ? "boolean" : entity.value_type == DeviceValueType::STRING ? "string" : F_(number);
|
output["storage"] = entity.ram ? "ram" : "ems";
|
||||||
|
output["type"] = entity.value_type == DeviceValueType::BOOL ? "boolean" : entity.value_type == DeviceValueType::STRING ? "string" : F_(number);
|
||||||
if (entity.uom > 0) {
|
if (entity.uom > 0) {
|
||||||
output["uom"] = EMSdevice::uom_to_string(entity.uom);
|
output["uom"] = EMSdevice::uom_to_string(entity.uom);
|
||||||
}
|
}
|
||||||
@@ -471,15 +472,6 @@ uint8_t WebCustomEntityService::count_entities() {
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t WebCustomEntityService::has_commands() {
|
|
||||||
uint8_t count = 0;
|
|
||||||
for (const CustomEntityItem & entity : *customEntityItems_) {
|
|
||||||
count += entity.writeable ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
// send to dashboard, msgpack don't like serialized, use number
|
// send to dashboard, msgpack don't like serialized, use number
|
||||||
void WebCustomEntityService::generate_value_web(JsonObject output) {
|
void WebCustomEntityService::generate_value_web(JsonObject output) {
|
||||||
JsonArray data = output["data"].to<JsonArray>();
|
JsonArray data = output["data"].to<JsonArray>();
|
||||||
|
|||||||
@@ -67,7 +67,6 @@ class WebCustomEntityService : public StatefulService<WebCustomEntity> {
|
|||||||
void generate_value_web(JsonObject output);
|
void generate_value_web(JsonObject output);
|
||||||
|
|
||||||
uint8_t count_entities();
|
uint8_t count_entities();
|
||||||
uint8_t has_commands();
|
|
||||||
void ha_reset() {
|
void ha_reset() {
|
||||||
ha_registered_ = false;
|
ha_registered_ = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -178,8 +178,9 @@ bool WebSchedulerService::get_value_info(JsonObject output, const char * cmd) {
|
|||||||
|
|
||||||
// build the json for specific entity
|
// build the json for specific entity
|
||||||
void WebSchedulerService::get_value_json(JsonObject output, const ScheduleItem & scheduleItem) {
|
void WebSchedulerService::get_value_json(JsonObject output, const ScheduleItem & scheduleItem) {
|
||||||
output["name"] = scheduleItem.name;
|
output["name"] = scheduleItem.name;
|
||||||
output["type"] = "boolean";
|
output["fullname"] = scheduleItem.name;
|
||||||
|
output["type"] = "boolean";
|
||||||
if (EMSESP::system_.bool_format() == BOOL_FORMAT_TRUEFALSE) {
|
if (EMSESP::system_.bool_format() == BOOL_FORMAT_TRUEFALSE) {
|
||||||
output["value"] = scheduleItem.active;
|
output["value"] = scheduleItem.active;
|
||||||
} else if (EMSESP::system_.bool_format() == BOOL_FORMAT_10) {
|
} else if (EMSESP::system_.bool_format() == BOOL_FORMAT_10) {
|
||||||
@@ -299,18 +300,15 @@ void WebSchedulerService::publish(const bool force) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebSchedulerService::has_commands() {
|
// count number of entries, default: only named items
|
||||||
if (scheduleItems_->size() == 0) {
|
uint8_t WebSchedulerService::count_entities(bool cmd_only) {
|
||||||
return false;
|
uint8_t count = 0;
|
||||||
}
|
|
||||||
|
|
||||||
for (const ScheduleItem & scheduleItem : *scheduleItems_) {
|
for (const ScheduleItem & scheduleItem : *scheduleItems_) {
|
||||||
if (!scheduleItem.name.empty()) {
|
if (!scheduleItem.name.empty() || !cmd_only) {
|
||||||
return true;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return count;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "shuntingYard.hpp"
|
#include "shuntingYard.hpp"
|
||||||
|
|||||||
@@ -65,14 +65,14 @@ class WebSchedulerService : public StatefulService<WebScheduler> {
|
|||||||
void loop();
|
void loop();
|
||||||
void publish_single(const char * name, const bool state);
|
void publish_single(const char * name, const bool state);
|
||||||
void publish(const bool force = false);
|
void publish(const bool force = false);
|
||||||
bool has_commands();
|
|
||||||
bool command_setvalue(const char * value, const int8_t id, const char * name);
|
bool command_setvalue(const char * value, const int8_t id, const char * name);
|
||||||
bool get_value_info(JsonObject output, const char * cmd);
|
bool get_value_info(JsonObject output, const char * cmd);
|
||||||
void get_value_json(JsonObject output, const ScheduleItem & scheduleItem);
|
void get_value_json(JsonObject output, const ScheduleItem & scheduleItem);
|
||||||
void ha_reset() {
|
void ha_reset() {
|
||||||
ha_registered_ = false;
|
ha_registered_ = false;
|
||||||
}
|
}
|
||||||
bool onChange(const char * cmd);
|
uint8_t count_entities(bool cmd_only = false);
|
||||||
|
bool onChange(const char * cmd);
|
||||||
|
|
||||||
#if defined(EMSESP_TEST)
|
#if defined(EMSESP_TEST)
|
||||||
void test();
|
void test();
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ void WebStatusService::systemStatus(AsyncWebServerRequest * request) {
|
|||||||
root["bus_status"] = EMSESP::bus_status(); // 0, 1 or 2
|
root["bus_status"] = EMSESP::bus_status(); // 0, 1 or 2
|
||||||
root["bus_uptime"] = EMSbus::bus_uptime();
|
root["bus_uptime"] = EMSbus::bus_uptime();
|
||||||
root["num_devices"] = EMSESP::count_devices();
|
root["num_devices"] = EMSESP::count_devices();
|
||||||
root["num_sensors"] = EMSESP::temperaturesensor_.no_sensors();
|
root["num_sensors"] = EMSESP::temperaturesensor_.count_entities();
|
||||||
root["num_analogs"] = EMSESP::analogsensor_.no_sensors();
|
root["num_analogs"] = EMSESP::analogsensor_.count_entities();
|
||||||
root["free_heap"] = EMSESP::system_.getHeapMem();
|
root["free_heap"] = EMSESP::system_.getHeapMem();
|
||||||
root["uptime"] = uuid::get_uptime_sec();
|
root["uptime"] = uuid::get_uptime_sec();
|
||||||
root["mqtt_status"] = EMSESP::mqtt_.connected();
|
root["mqtt_status"] = EMSESP::mqtt_.connected();
|
||||||
|
|||||||
Reference in New Issue
Block a user