Skip to content

Commit

Permalink
stub custom HASS publish, self test, part 1 of sim power
Browse files Browse the repository at this point in the history
  • Loading branch information
openshwprojects committed Nov 1, 2024
1 parent 87a2da9 commit c0a2566
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/cmnds/cmd_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,11 @@ const char *CMD_ExpandConstantString(const char *s, const char *stop, char *out,
SIM_GenerateRepeatingEventsDesc(out, outLen);
return ret;
}
ret = strCompareBound(s, "$simPowerState", stop, false);
if (ret) {
SIM_GeneratePowerStateDesc(out, outLen);
return ret;
}
return false;
}
#endif
Expand Down
1 change: 1 addition & 0 deletions src/cmnds/cmd_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ void Tokenizer_TokenizeString(const char* s, int flags);
void RepeatingEvents_Init();
void RepeatingEvents_RunUpdate(float deltaTimeSeconds);
void SIM_GenerateRepeatingEventsDesc(char *o, int outLen);
void SIM_GeneratePowerStateDesc(char *o, int outLen);
// cmd_eventHandlers.c
void EventHandlers_Init();
// This is useful to fire an event when a certain UART string command is received.
Expand Down
1 change: 1 addition & 0 deletions src/httpserver/http_fns.c
Original file line number Diff line number Diff line change
Expand Up @@ -1908,6 +1908,7 @@ void doHomeAssistantDiscovery(const char* topic, http_request_t* request) {
dev_info = hass_init_sensor_device_info(ILLUMINANCE_SENSOR, i, -1, -1, 1);
}
break;
case ChType_Custom:
case ChType_ReadOnly:
{
dev_info = hass_init_sensor_device_info(CUSTOM_SENSOR, i, -1, -1, 1);
Expand Down
26 changes: 26 additions & 0 deletions src/selftest/selftest_hass_discovery_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,31 @@ void Test_HassDiscovery_Channel_LowMidHigh() {
SELFTEST_ASSERT_JSON_VALUE_STRING("dev", "mdl", PLATFORM_MCU_NAME);

}
void Test_HassDiscovery_Channel_Custom() {
const char *shortName = "WinCustom";
const char *fullName = "Windows Fake Custom";
const char *mqttName = "testCustom";
SIM_ClearOBK(shortName);
SIM_ClearAndPrepareForMQTTTesting(mqttName, "bekens");

CFG_SetShortDeviceName(shortName);
CFG_SetDeviceName(fullName);

CHANNEL_SetType(4, ChType_Custom);

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, "stat_t", "~/4/get");
}
void Test_HassDiscovery_Channel_Motion_longName() {
const char *shortName = "multifunction_PIR_obkE1552B06";
const char *fullName = "multifunction_PIR_OpenBK7231N_E1552B06";
Expand Down Expand Up @@ -591,6 +616,7 @@ void Test_HassDiscovery_Ext() {
Test_HassDiscovery_Channel_Motion_inv();
Test_HassDiscovery_Channel_Illuminance();
Test_HassDiscovery_Channel_LowMidHigh();
Test_HassDiscovery_Channel_Custom();


}
Expand Down
12 changes: 12 additions & 0 deletions src/sim/sim_sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,18 @@ bool FS_WriteTextFile(const char *data, const char *fname) {
return false;
}
CSimulator *g_sim;

extern "C" void SIM_GeneratePowerStateDesc(char *o, int outLen) {
class CSimulation *sim = g_sim->getSim();
if (sim == 0) {
strcpy(o, "No simulation");
return;
}
//sim->findFirstControllerOfType<Simulatio
// TODO
strcpy(o, "WiFi module power on");
}

extern "C" int SIM_CreateWindow(int argc, char **argv)
{
glutInit(&argc, argv);
Expand Down

0 comments on commit c0a2566

Please sign in to comment.