Skip to content

Commit

Permalink
Merge pull request emsesp#2029 from proddy/dev
Browse files Browse the repository at this point in the history
incorporated Michael's changes emsesp#2027
  • Loading branch information
proddy authored Sep 19, 2024
2 parents 384eb9b + 5b1493b commit e292aa3
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 13 deletions.
7 changes: 4 additions & 3 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,10 @@ lib_ldf_mode = off
lib_ignore = Module EMS-ESP-Modules

; unit tests
; pio run -e native-test -t exec
; works on Linux, Windows, and MacOS
; to update the test results, compile with -DEMSESP_UNITY_CREATE, run and capture the output and then paste this into the test_api.cpp file
; The code is in test/test_api.h/cpp
; to run use `pio run -e native-test -t exec`. All tests should PASS.
; to update the test results, compile with -DEMSESP_UNITY_CREATE by uncommenting the line below
; then run and capture the output between "START - CUT HERE" and "END - CUT HERE" into the test_api.h file
[env:native-test]
platform = native
test_build_src = true
Expand Down
5 changes: 3 additions & 2 deletions src/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,9 @@ bool Command::set_attribute(JsonObject output, const char * cmd, const char * at
if (attribute == nullptr) {
return true;
}
if (output[attribute].is<std::string>()) {
std::string data = output[attribute];

if (output[attribute].is<JsonVariantConst>()) {
std::string data = output[attribute].as<std::string>();
output.clear();
output["api_data"] = data; // always as a string
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {

if (return_code == CommandRet::OK) {
if (json.size()) {
if (json["api_data"].is<String>()) {
if (json["api_data"].is<std::string>()) {
String data = json["api_data"];
shell.println(data.c_str());
return;
Expand Down
3 changes: 2 additions & 1 deletion src/emsesp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1709,7 +1709,8 @@ void EMSESP::loop() {
if (c != -1) {
show_prompt = true;
}
if (c == '\x03' || c == '\x0C') {
// https://daleswanson.org/ascii.htm#:~:text=0
if (c == '\x03') {
start_serial_console();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/web/WebSchedulerService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ void WebSchedulerService::publish(const bool force) {
JsonDocument doc;
bool ha_created = ha_registered_;
for (const ScheduleItem & scheduleItem : *scheduleItems_) {
if (!scheduleItem.name.empty() && !doc[scheduleItem.name].is<const char *>()) {
if (!scheduleItem.name.empty() && !doc[scheduleItem.name].is<JsonVariantConst>()) {
if (EMSESP::system_.bool_format() == BOOL_FORMAT_TRUEFALSE) {
doc[scheduleItem.name] = scheduleItem.active;
} else if (EMSESP::system_.bool_format() == BOOL_FORMAT_10) {
Expand Down
10 changes: 5 additions & 5 deletions test/test_api/test_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void test_19() {
auto expected_response =
"[{\"system\":{\"version\":\"dev\",\"uptime\":\"000+00:00:00.000\",\"uptimeSec\":0,\"resetReason\":\"Unknown / "
"Unknown\"},\"network\":{\"network\":\"WiFi\",\"hostname\":\"ems-esp\",\"RSSI\":-23,\"TxPowerSetting\":0,\"staticIP\":false,\"lowBandwidth\":false,"
"\"disableSleep\":false,\"enableMDNS\":true,\"enableCORS\":false},\"ntp\":{},\"mqtt\":{\"MQTTStatus\":\"disconnected\",\"MQTTPublishes\":0,"
"\"disableSleep\":true,\"enableMDNS\":true,\"enableCORS\":false},\"ntp\":{},\"mqtt\":{\"MQTTStatus\":\"disconnected\",\"MQTTPublishes\":0,"
"\"MQTTQueued\":0,\"MQTTPublishFails\":0,\"MQTTConnects\":1,\"enabled\":true,\"clientID\":\"ems-esp\",\"keepAlive\":60,\"cleanSession\":false,"
"\"entityFormat\":1,\"base\":\"ems-esp\",\"discoveryPrefix\":\"homeassistant\",\"discoveryType\":0,\"nestedFormat\":1,\"haEnabled\":true,\"mqttQos\":0,"
"\"mqttRetain\":false,\"publishTimeHeartbeat\":60,\"publishTimeBoiler\":10,\"publishTimeThermostat\":10,\"publishTimeSolar\":10,\"publishTimeMixer\":"
Expand All @@ -169,7 +169,7 @@ void test_19() {
"\"busRxLineQuality\":100,\"busTxLineQuality\":100},\"settings\":{\"boardProfile\":\"S32\",\"locale\":\"en\",\"txMode\":8,\"emsBusID\":11,"
"\"showerTimer\":false,\"showerMinDuration\":180,\"showerAlert\":false,\"hideLed\":false,\"noTokenApi\":false,\"readonlyMode\":false,\"fahrenheit\":"
"false,\"dallasParasite\":false,\"boolFormat\":1,\"boolDashboard\":1,\"enumFormat\":1,\"analogEnabled\":true,\"telnetEnabled\":true,"
"\"maxWebLogBuffer\":50,\"webLogBuffer\":0,\"modbusEnabled\":false},\"devices\":[{\"type\":\"boiler\",\"name\":\"Custom "
"\"maxWebLogBuffer\":25,\"webLogBuffer\":0,\"modbusEnabled\":false,\"forceHeatingOff\":false},\"devices\":[{\"type\":\"boiler\",\"name\":\"Custom "
"Name!!\",\"deviceID\":\"0x08\",\"productID\":123,\"brand\":\"\",\"version\":\"01.00\",\"entities\":37,\"handlersReceived\":\"0x18\","
"\"handlersFetched\":\"0x14 0x33\",\"handlersPending\":\"0xBF 0x10 0x11 0xC2 0x15 0x1C 0x19 0x1A 0x35 0x34 0x2A 0xD1 0xE3 0xE4 0xE5 0xE9 0x2E "
"0x3B\"},{\"type\":\"thermostat\",\"name\":\"FW120\",\"deviceID\":\"0x10\",\"productID\":192,\"brand\":\"\",\"version\":\"01.00\",\"entities\":15,"
Expand All @@ -181,7 +181,7 @@ void test_20() {
auto expected_response =
"[{\"system\":{\"version\":\"dev\",\"uptime\":\"000+00:00:00.000\",\"uptimeSec\":0,\"resetReason\":\"Unknown / "
"Unknown\"},\"network\":{\"network\":\"WiFi\",\"hostname\":\"ems-esp\",\"RSSI\":-23,\"TxPowerSetting\":0,\"staticIP\":false,\"lowBandwidth\":false,"
"\"disableSleep\":false,\"enableMDNS\":true,\"enableCORS\":false},\"ntp\":{},\"mqtt\":{\"MQTTStatus\":\"disconnected\",\"MQTTPublishes\":0,"
"\"disableSleep\":true,\"enableMDNS\":true,\"enableCORS\":false},\"ntp\":{},\"mqtt\":{\"MQTTStatus\":\"disconnected\",\"MQTTPublishes\":0,"
"\"MQTTQueued\":0,\"MQTTPublishFails\":0,\"MQTTConnects\":1,\"enabled\":true,\"clientID\":\"ems-esp\",\"keepAlive\":60,\"cleanSession\":false,"
"\"entityFormat\":1,\"base\":\"ems-esp\",\"discoveryPrefix\":\"homeassistant\",\"discoveryType\":0,\"nestedFormat\":1,\"haEnabled\":true,\"mqttQos\":0,"
"\"mqttRetain\":false,\"publishTimeHeartbeat\":60,\"publishTimeBoiler\":10,\"publishTimeThermostat\":10,\"publishTimeSolar\":10,\"publishTimeMixer\":"
Expand All @@ -192,7 +192,7 @@ void test_20() {
"\"busRxLineQuality\":100,\"busTxLineQuality\":100},\"settings\":{\"boardProfile\":\"S32\",\"locale\":\"en\",\"txMode\":8,\"emsBusID\":11,"
"\"showerTimer\":false,\"showerMinDuration\":180,\"showerAlert\":false,\"hideLed\":false,\"noTokenApi\":false,\"readonlyMode\":false,\"fahrenheit\":"
"false,\"dallasParasite\":false,\"boolFormat\":1,\"boolDashboard\":1,\"enumFormat\":1,\"analogEnabled\":true,\"telnetEnabled\":true,"
"\"maxWebLogBuffer\":50,\"webLogBuffer\":0,\"modbusEnabled\":false},\"devices\":[{\"type\":\"boiler\",\"name\":\"Custom "
"\"maxWebLogBuffer\":25,\"webLogBuffer\":0,\"modbusEnabled\":false,\"forceHeatingOff\":false},\"devices\":[{\"type\":\"boiler\",\"name\":\"Custom "
"Name!!\",\"deviceID\":\"0x08\",\"productID\":123,\"brand\":\"\",\"version\":\"01.00\",\"entities\":37,\"handlersReceived\":\"0x18\","
"\"handlersFetched\":\"0x14 0x33\",\"handlersPending\":\"0xBF 0x10 0x11 0xC2 0x15 0x1C 0x19 0x1A 0x35 0x34 0x2A 0xD1 0xE3 0xE4 0xE5 0xE9 0x2E "
"0x3B\"},{\"type\":\"thermostat\",\"name\":\"FW120\",\"deviceID\":\"0x10\",\"productID\":192,\"brand\":\"\",\"version\":\"01.00\",\"entities\":15,"
Expand All @@ -213,7 +213,7 @@ void test_22() {

void test_23() {
auto expected_response = "[{\"network\":\"WiFi\",\"hostname\":\"ems-esp\",\"RSSI\":\"-23\",\"TxPowerSetting\":\"0\",\"staticIP\":\"false\","
"\"lowBandwidth\":\"false\",\"disableSleep\":\"false\",\"enableMDNS\":\"true\",\"enableCORS\":\"false\"}]";
"\"lowBandwidth\":\"false\",\"disableSleep\":\"true\",\"enableMDNS\":\"true\",\"enableCORS\":\"false\"}]";
TEST_ASSERT_EQUAL_STRING(expected_response, call_url("api/system/network/values"));
}

Expand Down

0 comments on commit e292aa3

Please sign in to comment.