Skip to content

Commit

Permalink
allow get sufix removal
Browse files Browse the repository at this point in the history
  • Loading branch information
openshwprojects committed Sep 29, 2024
1 parent 2c7cfd5 commit 94f370b
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/httpserver/http_fns.c
Original file line number Diff line number Diff line change
Expand Up @@ -2691,6 +2691,7 @@ const char* g_obk_flagNames[] = {
"[TuyaMCU] Store ALL data",
"[PWR] Invert AC dir",
"[HTTP] Hide ON/OFF for relays (only red/green buttons)",
"[MQTT] Never add get sufix",
"error",
"error",
"error",
Expand Down
4 changes: 4 additions & 0 deletions src/mqtt/new_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,10 @@ static OBK_Publish_Result MQTT_PublishTopicToClient(mqtt_client_t* client, const
{
appendGet = false;
}
if (CFG_HasFlag(OBK_FLAG_MQTT_NEVERAPPENDGET))
{
appendGet = false;
}


LOCK_TCPIP_CORE();
Expand Down
3 changes: 2 additions & 1 deletion src/new_pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -1114,8 +1114,9 @@ typedef struct pinsState_s {
#define OBK_FLAG_TUYAMCU_STORE_ALL_DATA 47
#define OBK_FLAG_POWER_INVERT_AC 48
#define OBK_FLAG_HTTP_NO_ONOFF_WORDS 49
#define OBK_FLAG_MQTT_NEVERAPPENDGET 50

#define OBK_TOTAL_FLAGS 50
#define OBK_TOTAL_FLAGS 51

#define LOGGER_FLAG_MQTT_DEDUPER 1
#define LOGGER_FLAG_POWER_SAVE 2
Expand Down
1 change: 1 addition & 0 deletions src/selftest/selftest_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ void Test_Role_ToggleAll_2();
void Test_WaitFor();
void Test_IF_Inside_Backlog();
void Test_MQTT_Get_LED_EnableAll();
void Test_MQTT_Get_Relay();
void Test_TuyaMCU_BatteryPowered();
void Test_ChargeLimitDriver();
void Test_WS2812B();
Expand Down
39 changes: 39 additions & 0 deletions src/selftest/selftest_mqtt_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
#include "selftest_local.h"
#include "../hal/hal_wifi.h"

void Test_MQTT_Get_Relay() {
SIM_ClearOBK(0);
SIM_ClearAndPrepareForMQTTTesting("myTestDevice", "bekens");

PIN_SetPinRoleForPinIndex(24, IOR_Relay);
PIN_SetPinChannelForPinIndex(24, 1);

SIM_ClearMQTTHistory();


}
void Test_MQTT_Get_LED_EnableAll() {
SIM_ClearOBK(0);
SIM_ClearAndPrepareForMQTTTesting("myTestDevice", "bekens");
Expand Down Expand Up @@ -112,6 +123,34 @@ void Test_MQTT_Get_LED_EnableAll() {
SIM_ClearMQTTHistory();

}

CFG_SetFlag(OBK_FLAG_MQTT_NEVERAPPENDGET, true);
for (int i = 0; i < 15; i++) {
char tgState[32];
int randVal = abs(rand() % 300) + 160;
sprintf(tgState, "%i", randVal);

#if 1
// send set
SIM_SendFakeMQTT("cmnd/myTestDevice/led_temperature", tgState);
#else
// cause an error
SIM_SendFakeMQTT("cmnd/myTestDevice/led_temperature", "0");
#endif
// expect get reply - led_dimmer will publish its value on change - NO GET SUFIX AS DISABLED IN FLAGS
SELFTEST_ASSERT_HAD_MQTT_PUBLISH_STR("myTestDevice/led_temperature", tgState, false);
SIM_ClearMQTTHistory();

// wait a bit
Sim_RunFrames(20, false);
// sending empty get should give us a state dump
SIM_ClearMQTTHistory();
SIM_SendFakeMQTT("myTestDevice/led_temperature/get", "");
Sim_RunFrames(4, false);
// expect get reply - led_dimmer will publish value because we have requested it - NO GET SUFIX AS DISABLED IN FLAGS
SELFTEST_ASSERT_HAD_MQTT_PUBLISH_STR("myTestDevice/led_temperature", tgState, false);
SIM_ClearMQTTHistory();
}
}


Expand Down
1 change: 1 addition & 0 deletions src/win_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ void Win_DoUnitTests() {
Test_TuyaMCU_BatteryPowered();
Test_JSON_Lib();
Test_MQTT_Get_LED_EnableAll();
Test_MQTT_Get_Relay();
Test_Commands_Startup();
Test_IF_Inside_Backlog();
Test_WaitFor();
Expand Down

0 comments on commit 94f370b

Please sign in to comment.