fix tests

This commit is contained in:
Nicu Hodos 2025-10-08 10:14:59 +02:00
parent 9511f08d2b
commit 2b23bbf178
3 changed files with 11 additions and 9 deletions

View File

@ -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 {

View File

@ -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);
}

View File

@ -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"]);