mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-09 01:09:51 +03:00
Merge branch 'dev' of https://github.com/emsesp/EMS-ESP32 into dev
This commit is contained in:
@@ -52,18 +52,19 @@ using string_vector = std::vector<const char *>;
|
||||
#define F_(string_name) (__pstr__##string_name)
|
||||
#define FL_(list_name) (__pstr__L_##list_name)
|
||||
|
||||
// The language settings below must match system.cpp
|
||||
#if defined(EMSESP_TEST)
|
||||
// in Test mode use two languages (en & de) to save flash memory needed for the tests
|
||||
#define MAKE_WORD_TRANSLATION(list_name, en, de, ...) static const char * const __pstr__L_##list_name[] = {de, nullptr};
|
||||
#define MAKE_TRANSLATION(list_name, shortname, en, de, ...) static const char * const __pstr__L_##list_name[] = {shortname, de, nullptr};
|
||||
#define MAKE_WORD_TRANSLATION(list_name, en, de, ...) static const char * const __pstr__L_##list_name[] = {en, de, nullptr};
|
||||
#define MAKE_TRANSLATION(list_name, shortname, en, de, ...) static const char * const __pstr__L_##list_name[] = {shortname, en, de, nullptr};
|
||||
#elif defined(EMSESP_EN_ONLY)
|
||||
// EN only
|
||||
#define MAKE_WORD_TRANSLATION(list_name, en, ...) static const char * const __pstr__L_##list_name[] = {en, nullptr};
|
||||
#define MAKE_TRANSLATION(list_name, shortname, en, ...) static const char * const __pstr__L_##list_name[] = {shortname, en, nullptr};
|
||||
#elif defined(EMSESP_DE_ONLY)
|
||||
// EN + DE
|
||||
#define MAKE_WORD_TRANSLATION(list_name, en, de, ...) static const char * const __pstr__L_##list_name[] = {de, nullptr};
|
||||
#define MAKE_TRANSLATION(list_name, shortname, en, de, ...) static const char * const __pstr__L_##list_name[] = {shortname, de, nullptr};
|
||||
#define MAKE_WORD_TRANSLATION(list_name, en, de, ...) static const char * const __pstr__L_##list_name[] = {en, de, nullptr};
|
||||
#define MAKE_TRANSLATION(list_name, shortname, en, de, ...) static const char * const __pstr__L_##list_name[] = {shortname, en, de, nullptr};
|
||||
#else
|
||||
#define MAKE_WORD_TRANSLATION(list_name, ...) static const char * const __pstr__L_##list_name[] = {__VA_ARGS__, nullptr};
|
||||
#define MAKE_TRANSLATION(list_name, ...) static const char * const __pstr__L_##list_name[] = {__VA_ARGS__, nullptr};
|
||||
|
||||
@@ -1271,7 +1271,7 @@ void EMSdevice::getCustomizationEntities(std::vector<std::string> & entity_ids)
|
||||
// pipe symbols (|) are escaped so they can be converted to Markdown in the Wiki
|
||||
// format is: device name,device type,product id,shortname,fullname,type [options...] \\| (min/max),uom,writeable,discovery entityid v3.4, discovery entityid
|
||||
#if defined(EMSESP_STANDALONE)
|
||||
void EMSdevice::dump_value_info() {
|
||||
void EMSdevice::dump_devicevalue_info() {
|
||||
for (auto & dv : devicevalues_) {
|
||||
if (dv.fullname != nullptr) {
|
||||
Serial.print('\"');
|
||||
@@ -1438,8 +1438,6 @@ void EMSdevice::dump_value_info() {
|
||||
Serial.print(",");
|
||||
|
||||
// modbus specific infos
|
||||
|
||||
|
||||
Serial.print(device_type());
|
||||
Serial.print(',');
|
||||
|
||||
|
||||
@@ -483,7 +483,7 @@ class EMSdevice {
|
||||
}
|
||||
};
|
||||
void dump_telegram_info(std::vector<TelegramFunctionDump> & telegram_functions_dump);
|
||||
void dump_value_info();
|
||||
void dump_devicevalue_info();
|
||||
#endif
|
||||
|
||||
private:
|
||||
@@ -518,14 +518,13 @@ class EMSdevice {
|
||||
}
|
||||
};
|
||||
|
||||
std::vector<TelegramFunction> telegram_functions_; // each EMS device has its own set of registered telegram types
|
||||
|
||||
std::vector<uint16_t> handlers_ignored_;
|
||||
|
||||
#if defined(EMSESP_STANDALONE) || defined(EMSESP_TEST)
|
||||
public: // so we can call it from WebCustomizationService::test()
|
||||
public: // so we can call it from WebCustomizationService::test() and EMSESP::dump_all_entities()
|
||||
#endif
|
||||
std::vector<DeviceValue> devicevalues_; // all the device values
|
||||
std::vector<TelegramFunction> telegram_functions_; // each EMS device has its own set of registered telegram types
|
||||
std::vector<DeviceValue> devicevalues_; // all the device values
|
||||
};
|
||||
|
||||
} // namespace emsesp
|
||||
|
||||
@@ -332,7 +332,7 @@ void EMSESP::show_ems(uuid::console::Shell & shell) {
|
||||
// Dump all entities to Serial out
|
||||
// this is intended to run within the OS with lots of available memory!
|
||||
#if defined(EMSESP_STANDALONE)
|
||||
void EMSESP::dump_all_values(uuid::console::Shell & shell) {
|
||||
void EMSESP::dump_all_entities(uuid::console::Shell & shell) {
|
||||
Serial.println("---- CSV START ----"); // marker use by py script
|
||||
// add header for CSV
|
||||
Serial.println("device name,device type,product id,shortname,fullname,type [options...] \\| (min/max),uom,writeable,discovery entityid v3.4,discovery "
|
||||
@@ -361,7 +361,7 @@ void EMSESP::dump_all_values(uuid::console::Shell & shell) {
|
||||
// for testing the mixer use ... if (device.product_id == 69) {
|
||||
emsdevices.push_back(
|
||||
EMSFactory::add(device.device_type, device_id, device.product_id, "1.0", device.default_name, device.flags, EMSdevice::Brand::NO_BRAND));
|
||||
emsdevices.back()->dump_value_info();
|
||||
emsdevices.back()->dump_devicevalue_info();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
16
src/emsesp.h
16
src/emsesp.h
@@ -124,25 +124,23 @@ class EMSESP {
|
||||
static void send_write_request(const uint16_t type_id, const uint8_t dest, const uint8_t offset, const uint8_t value);
|
||||
static void send_write_request(const uint16_t type_id, const uint8_t dest, const uint8_t offset, const uint8_t value, const uint16_t validate_typeid);
|
||||
|
||||
static bool device_exists(const uint8_t device_id);
|
||||
static void device_active(const uint8_t device_id, const bool active);
|
||||
static bool cmd_is_readonly(const uint8_t device_type, const uint8_t device_id, const char * cmd, const int8_t id);
|
||||
|
||||
static bool device_exists(const uint8_t device_id);
|
||||
static void device_active(const uint8_t device_id, const bool active);
|
||||
static bool cmd_is_readonly(const uint8_t device_type, const uint8_t device_id, const char * cmd, const int8_t id);
|
||||
static uint8_t device_id_from_cmd(const uint8_t device_type, const char * cmd, const int8_t id);
|
||||
static uint8_t count_devices(const uint8_t device_type);
|
||||
static uint8_t count_devices();
|
||||
static uint8_t device_index(const uint8_t device_type, const uint8_t unique_id);
|
||||
|
||||
static bool get_device_value_info(JsonObject root, const char * cmd, const int8_t id, const uint8_t devicetype);
|
||||
static bool get_device_value_info(JsonObject root, const char * cmd, const int8_t id, const uint8_t devicetype);
|
||||
|
||||
static void show_device_values(uuid::console::Shell & shell);
|
||||
static void show_sensor_values(uuid::console::Shell & shell);
|
||||
static void dump_all_values(uuid::console::Shell & shell);
|
||||
static void dump_all_telegrams(uuid::console::Shell & shell);
|
||||
|
||||
static void show_devices(uuid::console::Shell & shell);
|
||||
static void show_ems(uuid::console::Shell & shell);
|
||||
|
||||
static void dump_all_entities(uuid::console::Shell & shell);
|
||||
static void dump_all_telegrams(uuid::console::Shell & shell);
|
||||
|
||||
static void uart_init();
|
||||
|
||||
static void incoming_telegram(uint8_t * data, const uint8_t length);
|
||||
|
||||
@@ -1141,6 +1141,9 @@ void Mqtt::add_ha_uom(JsonObject doc, const uint8_t type, const uint8_t uom, con
|
||||
doc[uom_ha] = "s";
|
||||
} else if (uom != DeviceValueUOM::NONE) {
|
||||
doc[uom_ha] = EMSdevice::uom_to_string(uom); // default
|
||||
} else if (discovery_type() != discoveryType::HOMEASSISTANT) {
|
||||
// Domoticz use " " for a no-uom
|
||||
doc[uom_ha] = " ";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -442,7 +442,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
||||
|
||||
if (command == "entity_dump") {
|
||||
System::test_set_all_active(true);
|
||||
EMSESP::dump_all_values(shell);
|
||||
EMSESP::dump_all_entities(shell);
|
||||
ok = true;
|
||||
}
|
||||
|
||||
@@ -1014,25 +1014,36 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const
|
||||
// request.url("/api");
|
||||
// EMSESP::webAPIService.webAPIService(&request, doc.as<JsonVariant>());
|
||||
|
||||
char data2[] = "{\"action\":\"customSupport\", \"param\":\"hello\"}";
|
||||
deserializeJson(doc, data2);
|
||||
// char data2[] = "{\"action\":\"customSupport\", \"param\":\"hello\"}";
|
||||
// deserializeJson(doc, data2);
|
||||
// request.url("/rest/action");
|
||||
// EMSESP::webStatusService.action(&request, doc.as<JsonVariant>());
|
||||
|
||||
// char data3[] = "{\"action\":\"export\", \"param\":\"schedule\"}";
|
||||
// deserializeJson(doc, data3);
|
||||
// request.url("/rest/action");
|
||||
// EMSESP::webStatusService.action(&request, doc.as<JsonVariant>());
|
||||
|
||||
// char data4[] = "{\"action\":\"export\", \"param\":\"allvalues\"}";
|
||||
// deserializeJson(doc, data4);
|
||||
// request.url("/rest/action");
|
||||
// EMSESP::webStatusService.action(&request, doc.as<JsonVariant>());
|
||||
|
||||
// test version checks
|
||||
// test with "current_version_s = "3.7.1-dev.8" in WebStatusService::checkUpgrade()
|
||||
request.url("/rest/action");
|
||||
deserializeJson(doc, "{\"action\":\"checkUpgrade\", \"param\":\"3.7.1-dev.9,3.7.0\"}"); // is upgradable
|
||||
EMSESP::webStatusService.action(&request, doc.as<JsonVariant>());
|
||||
deserializeJson(doc, "{\"action\":\"checkUpgrade\", \"param\":\"3.7.1-dev.7,3.7.0\"}"); // is not upgradable
|
||||
EMSESP::webStatusService.action(&request, doc.as<JsonVariant>());
|
||||
|
||||
char data3[] = "{\"action\":\"export\", \"param\":\"schedule\"}";
|
||||
deserializeJson(doc, data3);
|
||||
request.url("/rest/action");
|
||||
EMSESP::webStatusService.action(&request, doc.as<JsonVariant>());
|
||||
// test with "current_version_s = "3.6.5" in WebStatusService::checkUpgrade()
|
||||
// request.url("/rest/action");
|
||||
// deserializeJson(doc, "{\"action\":\"checkUpgrade\", \"param\":\"3.7.1-dev.9,3.6.5\"}"); // is noy upgradable
|
||||
// EMSESP::webStatusService.action(&request, doc.as<JsonVariant>());
|
||||
// deserializeJson(doc, "{\"action\":\"checkUpgrade\", \"param\":\"3.7.1-dev.7,3.7.0\"}"); // is upgradable
|
||||
// EMSESP::webStatusService.action(&request, doc.as<JsonVariant>());
|
||||
|
||||
char data4[] = "{\"action\":\"export\", \"param\":\"allvalues\"}";
|
||||
deserializeJson(doc, data4);
|
||||
request.url("/rest/action");
|
||||
EMSESP::webStatusService.action(&request, doc.as<JsonVariant>());
|
||||
|
||||
char data5[] = "{\"action\":\"checkUpgrade\", \"param\":\"3.7.0-dev.99\"}";
|
||||
deserializeJson(doc, data5);
|
||||
request.url("/rest/action");
|
||||
EMSESP::webStatusService.action(&request, doc.as<JsonVariant>());
|
||||
|
||||
// char data6[] = "{\"device\":\"system\", \"cmd\":\"read\",\"value\":\"8 2 27 1\"}";
|
||||
// deserializeJson(doc, data6);
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace emsesp {
|
||||
// #define EMSESP_DEBUG_DEFAULT "310"
|
||||
// #define EMSESP_DEBUG_DEFAULT "render"
|
||||
// #define EMSESP_DEBUG_DEFAULT "api"
|
||||
// #define EMSESP_DEBUG_DEFAULT "api3"
|
||||
#define EMSESP_DEBUG_DEFAULT "api3"
|
||||
// #define EMSESP_DEBUG_DEFAULT "crash"
|
||||
// #define EMSESP_DEBUG_DEFAULT "dv"
|
||||
// #define EMSESP_DEBUG_DEFAULT "lastcode"
|
||||
|
||||
@@ -1 +1 @@
|
||||
#define EMSESP_APP_VERSION "3.7.1-dev.4"
|
||||
#define EMSESP_APP_VERSION "3.7.1-dev.5"
|
||||
@@ -203,24 +203,44 @@ void WebStatusService::action(AsyncWebServerRequest * request, JsonVariant json)
|
||||
}
|
||||
|
||||
// action = checkUpgrade
|
||||
bool WebStatusService::checkUpgrade(JsonObject root, std::string & latest_version) {
|
||||
root["emsesp_version"] = EMSESP_APP_VERSION;
|
||||
|
||||
if (!latest_version.empty()) {
|
||||
#if defined(EMSESP_DEBUG)
|
||||
emsesp::EMSESP::logger().debug("Checking for upgrade: %s < %s", EMSESP_APP_VERSION, latest_version.c_str());
|
||||
// versions holds the latest development version and stable version in one string, comma separated
|
||||
bool WebStatusService::checkUpgrade(JsonObject root, std::string & versions) {
|
||||
std::string current_version_s;
|
||||
#ifndef EMSESP_STANDALONE
|
||||
current_version_s = EMSESP_APP_VERSION;
|
||||
#else
|
||||
// for testing only - see api3 test in test.cpp
|
||||
// current_version_s = "3.6.5";
|
||||
current_version_s = "3.7.1-dev.8";
|
||||
#endif
|
||||
|
||||
version::Semver200_version settings_version(EMSESP_APP_VERSION);
|
||||
version::Semver200_version this_version(latest_version);
|
||||
if (!versions.empty()) {
|
||||
version::Semver200_version current_version(current_version_s);
|
||||
bool using_dev_version = !current_version.prerelease().find("dev"); // look for dev in the name to determine if we're using dev version
|
||||
version::Semver200_version latest_version(using_dev_version ? versions.substr(0, versions.find(',')) : versions.substr(versions.find(',') + 1));
|
||||
bool upgradeable = (latest_version > current_version);
|
||||
|
||||
if ((this_version.prerelease().empty() && settings_version.prerelease().empty())
|
||||
|| (!this_version.prerelease().empty() && !settings_version.prerelease().empty())) {
|
||||
root["upgradeable"] = (this_version > settings_version);
|
||||
}
|
||||
#if defined(EMSESP_DEBUG)
|
||||
emsesp::EMSESP::logger()
|
||||
.debug("Checking Version upgrade. Using %s release branch. current version=%d.%d.%d-%s, latest version=%d.%d.%d-%s (%s upgradeable)",
|
||||
(using_dev_version ? "dev" : "stable"),
|
||||
current_version.major(),
|
||||
current_version.minor(),
|
||||
current_version.patch(),
|
||||
current_version.prerelease().c_str(),
|
||||
latest_version.major(),
|
||||
latest_version.minor(),
|
||||
latest_version.patch(),
|
||||
latest_version.prerelease().c_str(),
|
||||
upgradeable ? "IS" : "NOT");
|
||||
#endif
|
||||
|
||||
root["upgradeable"] = upgradeable;
|
||||
}
|
||||
|
||||
return true; // always ok
|
||||
root["emsesp_version"] = current_version_s; // always send back current version
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// action = allvalues
|
||||
|
||||
Reference in New Issue
Block a user