From 47c4f4e3b340b2a3a557e809dbf707ee809dde4d Mon Sep 17 00:00:00 2001 From: Tester23 Date: Tue, 7 May 2024 12:59:36 +0200 Subject: [PATCH] self test for motion --- src/httpserver/http_fns.c | 2 +- src/selftest/selftest_hass_discovery_ext.c | 64 ++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index cea403ea2..9c594eac3 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -1846,7 +1846,7 @@ void doHomeAssistantDiscovery(const char* topic, http_request_t* request) { { case ChType_Motion: { - dev_info = hass_init_binary_sensor_device_info(i, false); + dev_info = hass_init_binary_sensor_device_info(i, true); cJSON_AddStringToObject(dev_info->root, "dev_cla", "motion"); } break; diff --git a/src/selftest/selftest_hass_discovery_ext.c b/src/selftest/selftest_hass_discovery_ext.c index 2f998cf8f..3918bd2aa 100644 --- a/src/selftest/selftest_hass_discovery_ext.c +++ b/src/selftest/selftest_hass_discovery_ext.c @@ -275,6 +275,66 @@ void Test_HassDiscovery_Channel_Toggle() { SELFTEST_ASSERT_JSON_VALUE_STRING(0, "pl_on", "1"); SELFTEST_ASSERT_JSON_VALUE_STRING(0, "pl_off", "0"); } +void Test_HassDiscovery_Channel_Motion() { + const char *shortName = "WinMotionTest"; + const char *fullName = "Windows Fake Motion"; + const char *mqttName = "testMotion"; + SIM_ClearOBK(shortName); + SIM_ClearAndPrepareForMQTTTesting(mqttName, "bekens"); + + CFG_SetShortDeviceName(shortName); + CFG_SetDeviceName(fullName); + + CHANNEL_SetType(4, ChType_Motion); + + SIM_ClearMQTTHistory(); + CMD_ExecuteCommand("scheduleHADiscovery 1", 0); + Sim_RunSeconds(5, false); + + // OBK device should publish JSON on MQTT topic "homeassistant" + SELFTEST_ASSERT_HAS_MQTT_JSON_SENT("homeassistant", true); + SELFTEST_ASSERT_JSON_VALUE_STRING("dev", "name", shortName); + SELFTEST_ASSERT_JSON_VALUE_STRING("dev", "sw", USER_SW_VER); + SELFTEST_ASSERT_JSON_VALUE_STRING("dev", "mf", MANUFACTURER); + SELFTEST_ASSERT_JSON_VALUE_STRING("dev", "mdl", PLATFORM_MCU_NAME); + SELFTEST_ASSERT_JSON_VALUE_STRING(0, "~", mqttName); + SELFTEST_ASSERT_JSON_VALUE_STRING(0, "dev_cla", "motion"); + SELFTEST_ASSERT_JSON_VALUE_STRING(0, "stat_t", "~/4/get"); + SELFTEST_ASSERT_JSON_VALUE_STRING(0, "pl_on", "1"); + SELFTEST_ASSERT_JSON_VALUE_STRING(0, "pl_off", "0"); +} +void Test_HassDiscovery_Channel_Motion_With_dInput() { + const char *shortName = "WinMotionTest"; + const char *fullName = "Windows Fake Motion"; + const char *mqttName = "testMotion"; + SIM_ClearOBK(shortName); + SIM_ClearAndPrepareForMQTTTesting(mqttName, "bekens"); + + CFG_SetShortDeviceName(shortName); + CFG_SetDeviceName(fullName); + + CHANNEL_SetType(4, ChType_Motion); + + // dInput should not SHADOW the channel type + PIN_SetPinRoleForPinIndex(10, IOR_DigitalInput); + PIN_SetPinChannelForPinIndex(10, 4); + + SIM_ClearMQTTHistory(); + CMD_ExecuteCommand("scheduleHADiscovery 1", 0); + Sim_RunSeconds(5, false); + + // OBK device should publish JSON on MQTT topic "homeassistant" + SELFTEST_ASSERT_HAS_MQTT_JSON_SENT("homeassistant", true); + SELFTEST_ASSERT_JSON_VALUE_STRING("dev", "name", shortName); + SELFTEST_ASSERT_JSON_VALUE_STRING("dev", "sw", USER_SW_VER); + SELFTEST_ASSERT_JSON_VALUE_STRING("dev", "mf", MANUFACTURER); + SELFTEST_ASSERT_JSON_VALUE_STRING("dev", "mdl", PLATFORM_MCU_NAME); + SELFTEST_ASSERT_JSON_VALUE_STRING(0, "~", mqttName); + SELFTEST_ASSERT_JSON_VALUE_STRING(0, "dev_cla", "motion"); + SELFTEST_ASSERT_JSON_VALUE_STRING(0, "stat_t", "~/4/get"); + SELFTEST_ASSERT_JSON_VALUE_STRING(0, "pl_on", "1"); + SELFTEST_ASSERT_JSON_VALUE_STRING(0, "pl_off", "0"); +} void Test_HassDiscovery_Channel_DimmerLightDetection_Dual() { const char *shortName = "DualMCUDimmer"; const char *fullName = "WinDualMCUDimmer"; @@ -415,6 +475,10 @@ void Test_HassDiscovery_Ext() { Test_HassDiscovery_Channel_Toggle_2x(); Test_HassDiscovery_Channel_DimmerLightDetection(); Test_HassDiscovery_Channel_DimmerLightDetection_Dual(); + Test_HassDiscovery_Channel_Motion(); + Test_HassDiscovery_Channel_Motion_With_dInput(); + + }