mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-15 16:06:54 +03:00
homeassistant service discovery: derive node_id when using nested topics (#3088)
* derive correct node_id for homeassistant service discovery in nested topics (fixes #1792) * explicit use of std::string * move nodeId creation to separate function add unit-tests * add documentation about node_id generation for Home Assistant MQTT Service Discovery
This commit is contained in:
22
code/test/components/jomjol_mqtt/test_server_mqtt.cpp
Normal file
22
code/test/components/jomjol_mqtt/test_server_mqtt.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <unity.h>
|
||||
#include <server_mqtt.h>
|
||||
|
||||
void test_createNodeId()
|
||||
{
|
||||
std::string topic = "watermeter";
|
||||
TEST_ASSERT_EQUAL_STRING("watermeter", createNodeId(topic).c_str());
|
||||
|
||||
topic = "/watermeter";
|
||||
TEST_ASSERT_EQUAL_STRING("watermeter", createNodeId(topic).c_str());
|
||||
|
||||
topic = "home/test/watermeter";
|
||||
TEST_ASSERT_EQUAL_STRING("watermeter", createNodeId(topic).c_str());
|
||||
|
||||
topic = "home/test/subtopic/something/test/watermeter";
|
||||
TEST_ASSERT_EQUAL_STRING("watermeter", createNodeId(topic).c_str());
|
||||
}
|
||||
|
||||
void test_mqtt()
|
||||
{
|
||||
test_createNodeId();
|
||||
}
|
||||
@@ -20,7 +20,7 @@
|
||||
#include "components/jomjol-flowcontroll/test_PointerEvalAnalogToDigitNew.cpp"
|
||||
#include "components/jomjol-flowcontroll/test_getReadoutRawString.cpp"
|
||||
#include "components/jomjol-flowcontroll/test_cnnflowcontroll.cpp"
|
||||
|
||||
#include "components/jomjol_mqtt/test_server_mqtt.cpp"
|
||||
|
||||
bool Init_NVS_SDCard()
|
||||
{
|
||||
@@ -167,6 +167,7 @@ extern "C" void app_main()
|
||||
|
||||
// getReadoutRawString test
|
||||
RUN_TEST(test_getReadoutRawString);
|
||||
RUN_TEST(test_mqtt);
|
||||
|
||||
UNITY_END();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user