From 2b23bbf178d2ddbebbe184dff1671e5341bff981 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Wed, 8 Oct 2025 10:14:59 +0200 Subject: [PATCH] fix tests --- src/ha.h | 2 +- src/mqtt.h | 2 +- test/native/ha/test_components/main.cpp | 16 +++++++++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/ha.h b/src/ha.h index 10eac93..c8c568a 100644 --- a/src/ha.h +++ b/src/ha.h @@ -12,7 +12,7 @@ using namespace std; #define BASE_TOPIC MAIN_DEVICE_ID "/%s" namespace Ha { - uint16(*publisher)(const char*, const char*); + uint16_t (*publisher)(const char*, const char*); typedef void (*onMessage)(const char*); struct Config { diff --git a/src/mqtt.h b/src/mqtt.h index d3bddfa..9aa6886 100644 --- a/src/mqtt.h +++ b/src/mqtt.h @@ -22,7 +22,7 @@ namespace Mqtt { client.disconnect(); } - uint16 publish(const char* topic, const char* message) { + uint16_t publish(const char* topic, const char* message) { return client.publish(topic, 0, true, message); } diff --git a/test/native/ha/test_components/main.cpp b/test/native/ha/test_components/main.cpp index 1fe6f05..785a2d7 100644 --- a/test/native/ha/test_components/main.cpp +++ b/test/native/ha/test_components/main.cpp @@ -8,7 +8,9 @@ using namespace Ha; void setUp(void) { - // set stuff up here + Ha::publisher = [](const char* topic, const char* message) -> uint16_t { + return 0; + }; } void tearDown(void) { @@ -38,7 +40,7 @@ void testButton(void) { b.buildConfig(doc); TEST_ASSERT_EQUAL_STRING(MAIN_DEVICE_ID"_id", doc["unique_id"]); - TEST_ASSERT_EQUAL_STRING("homeassistant/button/" MAIN_DEVICE_ID "/id/set", doc["command_topic"]); + TEST_ASSERT_EQUAL_STRING(MAIN_DEVICE_ID "/id/set", doc["command_topic"]); TEST_ASSERT_FALSE(doc["retain"]); TEST_ASSERT_EQUAL_STRING("a_name", doc["name"]); TEST_ASSERT_EQUAL_STRING(NULL, doc["device_class"]); @@ -53,14 +55,14 @@ void testSensor(void) { s.buildConfig(doc); TEST_ASSERT_EQUAL_STRING(MAIN_DEVICE_ID"_id", doc["unique_id"]); - TEST_ASSERT_EQUAL_STRING("homeassistant/sensor/" MAIN_DEVICE_ID "/id/state", doc["state_topic"]); + TEST_ASSERT_EQUAL_STRING(MAIN_DEVICE_ID "/id/state", doc["state_topic"]); TEST_ASSERT_EQUAL_STRING("a_name", doc["name"]); TEST_ASSERT_EQUAL_STRING(NULL, doc["device_class"]); TEST_ASSERT_EQUAL_STRING(NULL, doc["entity_category"]); TEST_ASSERT_EQUAL_STRING(NULL, doc["unit_of_measurement"]); TEST_ASSERT_EQUAL_STRING(NULL, doc["value_template"]); TEST_ASSERT_EQUAL_INT(0, doc["suggested_display_precision"]); - TEST_ASSERT_NOT_NULL(Sensor::mapSensors["id"]); + TEST_ASSERT_NOT_NULL(GenericSensor::mapSensors["id"]); } void testNumericSensor1(void) { @@ -90,7 +92,7 @@ void testSwitch(void) { s.buildConfig(doc); TEST_ASSERT_EQUAL_STRING(MAIN_DEVICE_ID"_id", doc["unique_id"]); - TEST_ASSERT_EQUAL_STRING("homeassistant/switch/" MAIN_DEVICE_ID "/id/set", doc["command_topic"]); + TEST_ASSERT_EQUAL_STRING(MAIN_DEVICE_ID "/id/set", doc["command_topic"]); TEST_ASSERT_FALSE(doc["retain"]); TEST_ASSERT_EQUAL_STRING("a_name", doc["name"]); TEST_ASSERT_EQUAL_STRING(NULL, doc["device_class"]); @@ -107,7 +109,7 @@ void testSwitchWithState(void) { StaticJsonDocument<256> doc; s.buildConfig(doc); - TEST_ASSERT_EQUAL_STRING("homeassistant/switch/" MAIN_DEVICE_ID "/id/state", doc["state_topic"]); + TEST_ASSERT_EQUAL_STRING(MAIN_DEVICE_ID "/id/state", doc["state_topic"]); } void testNumber(void) { @@ -121,7 +123,7 @@ void testNumber(void) { TEST_ASSERT_EQUAL_INT16(100, doc["max"]); TEST_ASSERT_EQUAL_INT16(1, doc["step"]); - TEST_ASSERT_EQUAL_STRING("homeassistant/number/" MAIN_DEVICE_ID "/id/set", doc["command_topic"]); + TEST_ASSERT_EQUAL_STRING(MAIN_DEVICE_ID "/id/set", doc["command_topic"]); TEST_ASSERT_FALSE(doc["retain"]); TEST_ASSERT_EQUAL_STRING("a_name", doc["name"]); TEST_ASSERT_EQUAL_STRING(NULL, doc["device_class"]);