Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…T_App into SSIDret2
  • Loading branch information
MaxineMuster committed Dec 1, 2024
2 parents 6b7f3c3 + e7551a3 commit 1bbd07f
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/driver/drv_tuyaMCU.c
Original file line number Diff line number Diff line change
Expand Up @@ -1795,6 +1795,8 @@ void TuyaMCU_ProcessIncoming(const byte* data, int len) {
else if (dataCount == 2)
{
self_processing_mode = false;
addLogAdv(LOG_INFO, LOG_FEATURE_TUYAMCU, "IMPORTANT!!! mcu conf pins: %i %i",
(int)(data[6]), (int)(data[7]));
}
if (5 + dataCount + 2 != len) {
addLogAdv(LOG_INFO, LOG_FEATURE_TUYAMCU, "ProcessIncoming: TUYA_CMD_MCU_CONF had wrong data lenght?");
Expand Down
27 changes: 16 additions & 11 deletions src/selftest/selftest_hass_discovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,32 +314,37 @@ void Test_VerifyForCommonPowerMeteringStuff() {

// generic tests to see if something power-related was published

SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY_3KEY("homeassistant", true, 0, 0,
SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY_4KEY("homeassistant", true, 0, 0,
"dev_cla", "voltage",
"stat_t", "~/voltage/get",
"unit_of_meas", "V");
"unit_of_meas", "V",
"stat_cla", "measurement");

SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY_3KEY("homeassistant", true, 0, 0,
SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY_4KEY("homeassistant", true, 0, 0,
"dev_cla", "power",
"stat_t", "~/power/get",
"unit_of_meas", "W");
"unit_of_meas", "W",
"stat_cla", "measurement");

SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY_3KEY("homeassistant", true, 0, 0,
SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY_4KEY("homeassistant", true, 0, 0,
"dev_cla", "current",
"stat_t", "~/current/get",
"unit_of_meas", "A");
"unit_of_meas", "A",
"stat_cla", "measurement");

SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY_3KEY("homeassistant", true, 0, 0,
SIM_DumpMQTTHistory();
/*SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY_4KEY("homeassistant", true, 0, 0,
"dev_cla", "energy",
"stat_t", "~/energycounter/get",
"unit_of_meas", "Wh");
"unit_of_meas", "Wh",
"stat_cla", "measurement");
SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY_3KEY("homeassistant", true, 0, 0,
SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY_4KEY("homeassistant", true, 0, 0,
"dev_cla", "energy",
"stat_t", "~/energycounter_last_hour/get",
"unit_of_meas", "Wh");
"unit_of_meas", "Wh",
"stat_cla", "measurement");*/

SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY("homeassistant", true, 0, 0, "stat_cla", "measurement");
}
void Test_HassDiscovery_BL0942() {
const char *shortName = "PowerMeteringFake";
Expand Down
10 changes: 6 additions & 4 deletions src/selftest/selftest_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ void SelfTest_Failed(const char *file, const char *function, int line, const cha
#define SELFTEST_ASSERT_HAD_MQTT_PUBLISH_FLOAT(topic, value, bRetain) SELFTEST_ASSERT(SIM_CheckMQTTHistoryForFloat(topic,value,bRetain));
#define SELFTEST_ASSERT_FLAG(flag, value) SELFTEST_ASSERT(CFG_HasFlag(flag)==value);
#define SELFTEST_ASSERT_HAS_MQTT_JSON_SENT(topic, bPrefixMode) SELFTEST_ASSERT(!SIM_BeginParsingMQTTJSON(topic, bPrefixMode));
#define SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY(topic, bPrefixMode, object1, object2, key, value) SELFTEST_ASSERT(SIM_HasMQTTHistoryStringWithJSONPayload(topic, bPrefixMode, object1, object2, key, value, 0, 0, 0, 0));
#define SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY_TWOKEY(topic, bPrefixMode, object1, object2, key, value, key2, value2) SELFTEST_ASSERT(SIM_HasMQTTHistoryStringWithJSONPayload(topic, bPrefixMode, object1, object2, key, value, key2, value2, 0, 0));
#define SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY_3KEY(topic, bPrefixMode, object1, object2, key, value, key2, value2, key3, value3) SELFTEST_ASSERT(SIM_HasMQTTHistoryStringWithJSONPayload(topic, bPrefixMode, object1, object2, key, value, key2, value2, key3, value3));
#define SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY(topic, bPrefixMode, object1, object2, key, value) SELFTEST_ASSERT(SIM_HasMQTTHistoryStringWithJSONPayload(topic, bPrefixMode, object1, object2, key, value, 0, 0, 0, 0, 0, 0));
#define SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY_TWOKEY(topic, bPrefixMode, object1, object2, key, value, key2, value2) SELFTEST_ASSERT(SIM_HasMQTTHistoryStringWithJSONPayload(topic, bPrefixMode, object1, object2, key, value, key2, value2, 0, 0, 0, 0));
#define SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY_3KEY(topic, bPrefixMode, object1, object2, key, value, key2, value2, key3, value3) SELFTEST_ASSERT(SIM_HasMQTTHistoryStringWithJSONPayload(topic, bPrefixMode, object1, object2, key, value, key2, value2, key3, value3, 0, 0));
#define SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY_4KEY(topic, bPrefixMode, object1, object2, key, value, key2, value2, key3, value3, key4, value4) SELFTEST_ASSERT(SIM_HasMQTTHistoryStringWithJSONPayload(topic, bPrefixMode, object1, object2, key, value, key2, value2, key3, value3, key4, value4));
#define SELFTEST_ASSERT_HAS_SENT_UART_STRING(str) SELFTEST_ASSERT(SIM_UART_ExpectAndConsumeHexStr(str));
#define SELFTEST_ASSERT_HAS_UART_EMPTY() SELFTEST_ASSERT(SIM_UART_GetDataSize()==0);

Expand Down Expand Up @@ -188,11 +189,12 @@ void SIM_SendFakeMQTTAndRunSimFrame_CMND_ViaGroupTopic(const char *command, cons
void SIM_SendFakeMQTTRawChannelSet(int channelIndex, const char *arguments);
void SIM_SendFakeMQTTRawChannelSet_ViaGroupTopic(int channelIndex, const char *arguments);
void SIM_ClearMQTTHistory();
void SIM_DumpMQTTHistory();
bool SIM_CheckMQTTHistoryForString(const char *topic, const char *value, bool bRetain);
bool SIM_HasMQTTHistoryStringWithJSONPayload(const char *topic, bool bPrefixMode,
const char *object1, const char *object2,
const char *key, const char *value, const char *key2, const char *val2,
const char *key3, const char *val3);
const char *key3, const char *val3, const char *key4, const char *val4);
bool SIM_CheckMQTTHistoryForFloat(const char *topic, float value, bool bRetain);
const char *SIM_GetMQTTHistoryString(const char *topic, bool bPrefixMode);
bool SIM_BeginParsingMQTTJSON(const char *topic, bool bPrefixMode);
Expand Down
35 changes: 32 additions & 3 deletions src/selftest/selftest_util_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void SIM_SendFakeMQTTRawChannelSet_ViaGroupTopic(int channelIndex, const char *a
SIM_SendFakeMQTTRawChannelSet_Generic(myName, channelIndex, arguments);
}

#define MAX_MQTT_HISTORY 64
#define MAX_MQTT_HISTORY 256
typedef struct mqttHistoryEntry_s {
char topic[256];
char value[4096];
Expand Down Expand Up @@ -99,11 +99,36 @@ bool CheckForKeyVal(cJSON *tmp, const char *key, const char *value) {
}
return false;
}
void SIM_DumpMQTTHistory() {
int cur = history_tail;
int index = 0;

printf("MQTT history dump (total entries: %d):\n",
(history_head >= history_tail) ? (history_head - history_tail)
: (MAX_MQTT_HISTORY - history_tail + history_head));
printf("-------------------------------------------------------------\n");
while (cur != history_head) {
mqttHistoryEntry_t *entry = &mqtt_history[cur];
printf("Entry %d:\n", index++);
printf(" Topic: %s\n", entry->topic);
printf(" Payload: %s\n", entry->value);
printf(" QoS: %d\n", entry->qos);
printf(" Retain: %s\n", entry->bRetain ? "True" : "False");
printf("-------------------------------------------------------------\n");

cur++;
cur %= MAX_MQTT_HISTORY;
}
if (index == 0) {
printf("No MQTT history available.\n");
}
}
bool SIM_HasMQTTHistoryStringWithJSONPayload(const char *topic, bool bPrefixMode,
const char *object1, const char *object2,
const char *key, const char *value,
const char *key2, const char *value2,
const char *key3, const char *value3) {
const char *key3, const char *value3,
const char *key4, const char *value4) {
mqttHistoryEntry_t *ne;
int cur = history_tail;
while (cur != history_head) {
Expand Down Expand Up @@ -146,10 +171,14 @@ bool SIM_HasMQTTHistoryStringWithJSONPayload(const char *topic, bool bPrefixMode
bOk = false;
}
}
if (key4) {
if (CheckForKeyVal(tmp, key4, value4) == false) {
bOk = false;
}
}
if (bOk)
return true;
}

}
cJSON_Delete(json);
}
Expand Down

0 comments on commit 1bbd07f

Please sign in to comment.