mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-02-04 08:55:37 +00:00
fx special char in full name (#1934)
* Update selftest_hass_discovery.c * test special name * fxes * fixes * substr * fx
This commit is contained in:
@ -316,7 +316,11 @@ const char* skipToNextWord(const char* p) {
|
||||
int STR_ReplaceWhiteSpacesWithUnderscore(char *p) {
|
||||
int r = 0;
|
||||
while (*p) {
|
||||
if (*p == ' ' || *p == '\t') {
|
||||
bool bSpecialChar = false;
|
||||
if (*((byte*)p) > 127) {
|
||||
bSpecialChar = true;
|
||||
}
|
||||
if (*p == ' ' || *p == '\t' || bSpecialChar) {
|
||||
r++;
|
||||
*p = '_';
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
#ifdef WINDOWS
|
||||
#ifdef WINDOWS
|
||||
|
||||
#include "selftest_local.h"
|
||||
|
||||
@ -238,7 +238,7 @@ void Test_HassDiscovery_DHT11() {
|
||||
SELFTEST_ASSERT_HAS_MQTT_JSON_SENT("homeassistant", true);
|
||||
//SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY("homeassistant", true, "dev", 0, "name", shortName);
|
||||
// first dev - as temperature
|
||||
//SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY("homeassistant", true, 0, 0, "unit_of_meas", "<EFBFBD>C");
|
||||
//SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY("homeassistant", true, 0, 0, "unit_of_meas", "°C");
|
||||
// old method - round
|
||||
//SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY("homeassistant", true, 0, 0, "val_tpl", "{{ float(value)*0.1|round(2) }}");
|
||||
// new method - format
|
||||
@ -320,7 +320,7 @@ void Test_HassDiscovery_SHTSensor() {
|
||||
"dev_cla", "temperature",
|
||||
"stat_t", "~/2/get",
|
||||
"stat_cla", "measurement");
|
||||
//SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY("homeassistant", true, 0, 0, "unit_of_meas", "<EFBFBD>C");
|
||||
//SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY("homeassistant", true, 0, 0, "unit_of_meas", "°C");
|
||||
// second dev -
|
||||
SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY_4KEY("homeassistant", true, 0, 0,
|
||||
"dev_cla", "humidity",
|
||||
@ -484,7 +484,46 @@ void Test_HassDiscovery_digitalInputNoAVTY() {
|
||||
|
||||
}
|
||||
|
||||
// 0xC6 is ã in CP850
|
||||
void Test_HassDiscovery_SpecialChar() {
|
||||
// Our test name
|
||||
const char *shortName = "TestChar";
|
||||
// 0xC6 is 198 decimal
|
||||
char fullName[128];
|
||||
const char *mqttName = "testChar";
|
||||
|
||||
strcpy(fullName, "Salão de Festas");
|
||||
fullName[3] = 0xC6;
|
||||
|
||||
SIM_ClearOBK(shortName);
|
||||
SIM_ClearAndPrepareForMQTTTesting(mqttName, "bekens");
|
||||
|
||||
CFG_SetShortDeviceName(shortName);
|
||||
CFG_SetDeviceName(fullName);
|
||||
|
||||
const char *verify = CFG_GetDeviceName();
|
||||
SELFTEST_ASSERT_STRING(verify, fullName);
|
||||
|
||||
// fake relay
|
||||
PIN_SetPinRoleForPinIndex(24, IOR_Relay);
|
||||
PIN_SetPinChannelForPinIndex(24, 1);
|
||||
|
||||
SIM_ClearMQTTHistory();
|
||||
CMD_ExecuteCommand("scheduleHADiscovery 1", 0);
|
||||
Sim_RunSeconds(5, false);
|
||||
|
||||
// OBK device should publish JSON on MQTT topic "homeassistant"
|
||||
// Verify that the device block contains our special name
|
||||
SELFTEST_ASSERT_HAS_MQTT_JSON_SENT("homeassistant", true);
|
||||
SELFTEST_ASSERT_JSON_VALUE_STRING_NESTED_ARRAY("dev", "ids", 0, fullName);
|
||||
SELFTEST_ASSERT_JSON_VALUE_STRING_NESTED_ARRAY("dev", "ids", 0, fullName);
|
||||
// hack for linux
|
||||
SELFTEST_ASSERT_JSON_ONE_OF_TWO_VALUES_STRING(0, "uniq_id", "Sal_o_de_Festas_relay_1", "Sal__o_de_Festas_relay_1");
|
||||
SELFTEST_ASSERT(0xC6 == ((byte*)fullName)[3]);
|
||||
}
|
||||
|
||||
void Test_HassDiscovery() {
|
||||
Test_HassDiscovery_SpecialChar();
|
||||
Test_HassDiscovery_SHTSensor();
|
||||
#if ENABLE_DRIVER_BL0942
|
||||
Test_HassDiscovery_BL0942();
|
||||
@ -509,3 +548,4 @@ void Test_HassDiscovery() {
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -30,6 +30,8 @@ void SelfTest_Failed(const char *file, const char *function, int line, const cha
|
||||
#define SELFTEST_ASSERT_ARGUMENT_INTEGER(argumentIndex, res) SELFTEST_ASSERT((Tokenizer_GetArgInteger(argumentIndex)== res));
|
||||
#define SELFTEST_ASSERT_ARGUMENTS_COUNT(wantedCount) SELFTEST_ASSERT((Tokenizer_GetArgsCount()==wantedCount));
|
||||
#define SELFTEST_ASSERT_JSON_VALUE_STRING(obj, varName, res) SELFTEST_ASSERT(!strcmp(Test_GetJSONValue_String(varName,obj), res));
|
||||
#define SELFTEST_ASSERT_JSON_ONE_OF_TWO_VALUES_STRING(obj, varName, res, res2) SELFTEST_ASSERT(!strcmp(Test_GetJSONValue_String(varName,obj), res) || !strcmp(Test_GetJSONValue_String(varName,obj), res2));
|
||||
#define SELFTEST_ASSERT_JSON_VALUE_STRING_STARTSWITH(obj, varName, res) SELFTEST_ASSERT(!strncmp(Test_GetJSONValue_String(varName,obj), res, strlen(res)));
|
||||
#define SELFTEST_ASSERT_JSON_VALUE_STRING_NOT_PRESENT(obj, varName) SELFTEST_ASSERT((*Test_GetJSONValue_String(varName,obj))==0);
|
||||
#define SELFTEST_ASSERT_JSON_VALUE_EXISTS(obj, varName) SELFTEST_ASSERT(Test_GetJSONValue_Generic(varName,obj));
|
||||
#define SELFTEST_ASSERT_JSON_VALUE_INTEGER(obj, varName, res) SELFTEST_ASSERT((Test_GetJSONValue_Integer(varName,obj) == res));
|
||||
|
||||
Reference in New Issue
Block a user