add test for BinarySensor

This commit is contained in:
Nicu Hodos 2025-10-08 11:03:28 +02:00
parent 2b23bbf178
commit 5bf3db20da

View File

@ -193,6 +193,21 @@ void testBatterySensor(void) {
TEST_ASSERT_EQUAL_INT(2, doc["suggested_display_precision"]);
}
void testBinarySensor(void) {
BinarySensor s("id", "a_name");
StaticJsonDocument<256> doc;
s.buildConfig(doc);
TEST_ASSERT_EQUAL_STRING(MAIN_DEVICE_ID"_id", doc["unique_id"]);
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["value_template"]);
TEST_ASSERT_NOT_NULL(GenericSensor::mapSensors["id"]);
}
int main(int argc, char **argv) {
UNITY_BEGIN();
RUN_TEST(testDevice);
@ -208,5 +223,6 @@ int main(int argc, char **argv) {
RUN_TEST(testSwitch);
RUN_TEST(testSwitchWithState);
RUN_TEST(testNumber);
RUN_TEST(testBinarySensor);
return UNITY_END();
}