Skip to content

Commit e068b02

Browse files
committed
dunno
1 parent 8aea2e9 commit e068b02

File tree

8 files changed

+89
-22
lines changed

8 files changed

+89
-22
lines changed

src/selftest/selftest_DHT.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ void Test_DHT() {
2020
PIN_SetPinChannel2ForPinIndex(9, 2);
2121

2222
Sim_RunSeconds(5.0f, false);
23-
}
23+
// After removing the role the driver should no longer update the channels.
24+
// They must remain at the last values sampled while the DHT11 role was active.
25+
SELFTEST_ASSERT_CHANNEL(1, 190);
26+
SELFTEST_ASSERT_CHANNEL(2, 67);
2427

2528

2629
#endif

src/selftest/selftest_enums.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ void Test_Enum_LowMidH() {
2424

2525
SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY_4KEY("homeassistant", true, 0, 0,
2626
"state_topic", "~/13/get",
27-
"uniq_id", "Windows_Enum_select_13",
28-
"uniq_id", "Windows_Enum_select_13",
27+
"command_topic", "~/13/set",
28+
"~", "obkEnumDemo",
2929
"uniq_id", "Windows_Enum_select_13");
3030

3131
SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY_4KEY("homeassistant", true, 0, 0,
@@ -63,8 +63,8 @@ void Test_Enum_LowMidHighOff() {
6363

6464
SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY_4KEY("homeassistant", true, 0, 0,
6565
"state_topic", "~/12/get",
66-
"uniq_id", "Windows_Enum_select_12",
67-
"uniq_id", "Windows_Enum_select_12",
66+
"command_topic", "~/12/set",
67+
"~", "obkEnumDemo",
6868
"uniq_id", "Windows_Enum_select_12");
6969

7070
SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY_4KEY("homeassistant", true, 0, 0,
@@ -123,8 +123,8 @@ void Test_Enum_3opts() {
123123

124124
SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY_4KEY("homeassistant", true, 0, 0,
125125
"state_topic", "~/14/get",
126-
"unique_id", "14",
127-
"unique_id", "14",
126+
"command_topic", "~/14/set",
127+
"~", "obkEnumDemo",
128128
"uniq_id", "Windows_Enum_select_14");
129129

130130
SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY_4KEY("homeassistant", true, 0, 0,
@@ -195,8 +195,8 @@ void Test_Enum_BadOk() {
195195

196196
SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY_4KEY("homeassistant", true, 0, 0,
197197
"state_topic", "~/4/get",
198-
"unique_id", "4",
199-
"unique_id", "4",
198+
"command_topic", "~/4/set",
199+
"~", "obkEnumDemo",
200200
"uniq_id", "Windows_Enum_select_4");
201201

202202
SELFTEST_ASSERT_HAS_MQTT_JSON_SENT_ANY_4KEY("homeassistant", true, 0, 0,

src/selftest/selftest_flags.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void Test_Flags() {
4949
bool bSet = (i == 33 || i == 0 || i == 1 || i == 55 || i == 63);
5050
SELFTEST_ASSERT_FLAG(i, bSet);
5151
}
52-
// clear flag 63
52+
// clear flag 55
5353
CMD_ExecuteCommand("SetFlag 55 0", 0);
5454
for (int i = 0; i < 64; i++) {
5555
bool bSet = (i == 33 || i == 0 || i == 1 || i == 63);

src/selftest/selftest_if_inside_backlog.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,32 @@ void Test_IF_Inside_Backlog() {
1414
PIN_SetPinRoleForPinIndex(26, IOR_PWM);
1515
PIN_SetPinChannelForPinIndex(26, 2);
1616

17+
// Non-LED test: verify that "if" works correctly when nested inside a backlog alias.
18+
// Uses plain channels so this runs regardless of ENABLE_LED_BASIC.
19+
CMD_ExecuteCommand("alias pick_val backlog if $CH10>7&&$CH10<19 then setChannel 20 200; if $CH10<=7||$CH10>=19 then setChannel 20 500;", 0);
1720

18-
#if ENABLE_LED_BASIC
21+
// hour 10 -> day -> channel 20 = 200
22+
CMD_ExecuteCommand("setChannel 10 10", 0);
23+
CMD_ExecuteCommand("pick_val", 0);
24+
SELFTEST_ASSERT_CHANNEL(20, 200);
1925

26+
// hour 3 -> night -> channel 20 = 500
27+
CMD_ExecuteCommand("setChannel 10 3", 0);
28+
CMD_ExecuteCommand("pick_val", 0);
29+
SELFTEST_ASSERT_CHANNEL(20, 500);
30+
31+
// hour 12 -> day -> channel 20 = 200
32+
CMD_ExecuteCommand("setChannel 10 12", 0);
33+
CMD_ExecuteCommand("pick_val", 0);
34+
SELFTEST_ASSERT_CHANNEL(20, 200);
35+
36+
// hour 22 -> night -> channel 20 = 500
37+
CMD_ExecuteCommand("setChannel 10 22", 0);
38+
CMD_ExecuteCommand("pick_val", 0);
39+
SELFTEST_ASSERT_CHANNEL(20, 500);
40+
41+
#if ENABLE_LED_BASIC
42+
// LED-specific variant: same logic but driving led_temperature instead
2043
CMD_ExecuteCommand("led_enableAll 1", 0);
2144

2245
CMD_ExecuteCommand("alias day_lights backlog led_temperature 200", 0);

src/selftest/selftest_openWeatherMap.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ void Test_OpenWeatherMap() {
5151
SELFTEST_ASSERT_FLOATCOMPARE(w->lat, 50);
5252
SELFTEST_ASSERT_FLOATCOMPARE(w->lon, 10);
5353

54+
// Test with a response that has no "weather" array (edge case)
55+
Weather_SetReply(reply_no_weather);
56+
w = Weather_GetData();
57+
// Numeric fields from "main" and "coord" must still parse
58+
SELFTEST_ASSERT_FLOATCOMPARE(w->humidity, 60);
59+
SELFTEST_ASSERT_FLOATCOMPARE(w->pressure, 900);
60+
SELFTEST_ASSERT_FLOATCOMPARE(w->temp, 20);
61+
SELFTEST_ASSERT_FLOATCOMPARE(w->lat, 50);
62+
SELFTEST_ASSERT_FLOATCOMPARE(w->lon, 10);
63+
// Without a weather[] array the string fields should be empty/default
64+
SELFTEST_ASSERT_STRING(w->main_weather, "");
65+
SELFTEST_ASSERT_STRING(w->description, "");
5466

5567
}
5668

src/selftest/selftest_script.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,15 @@ void Test_Scripting_Loop3() {
129129
SELFTEST_ASSERT_INTEGER(CMD_GetCountActiveScriptThreads(), 1);
130130
SELFTEST_ASSERT_CHANNEL(0, 1);
131131
}
132-
for (int i = 0; i < 2; i++) {
133-
Sim_RunSeconds(1, false);
134-
}
132+
// Second 15: the script delay counts down to 0 and exits during this second.
133+
// The thread may finish at any point within this second, so we assert
134+
// it is still alive at the start but do not assert mid-second.
135+
Sim_RunSeconds(1, false);
136+
// After second 15 (the 15th delay_s 1 has elapsed) the script must have ended.
137+
SELFTEST_ASSERT_INTEGER(CMD_GetCountActiveScriptThreads(), 0);
138+
// Channel 0 should now be 0 (the script's final command sets it to 0)
139+
SELFTEST_ASSERT_CHANNEL(0, 0);
140+
// Run a couple more seconds to confirm nothing changes again
135141
for (int i = 0; i < 3; i++) {
136142
Sim_RunSeconds(1, false);
137143
SELFTEST_ASSERT_INTEGER(CMD_GetCountActiveScriptThreads(), 0);

src/selftest/selftest_shutters.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,30 @@ void Test_Shutters() {
1616
PIN_SetPinRoleForPinIndex(7, IOR_Button_ShutterDown);
1717

1818
CMD_ExecuteCommand("startDriver Shutters", 0);
19+
// Run 1 second so DRV_Shutters_RunEverySecond fires and registers the shutter struct.
20+
// The struct is lazily created the first time RunEverySecond scans the pins.
21+
Sim_RunSeconds(1.0f, false);
22+
// Initially both pins should be off (shutter is stopped at start)
1923
SELFTEST_ASSERT_PIN_BOOLEAN(4, false);
2024
SELFTEST_ASSERT_PIN_BOOLEAN(5, false);
25+
26+
// Issue an open command (100% = fully open = SHUTTER_OPENING direction)
2127
CMD_ExecuteCommand("ShutterMove0 100", 0);
28+
// After issuing the open command: ShutterA=1 (opening), ShutterB=0
29+
SELFTEST_ASSERT_PIN_BOOLEAN(4, true);
30+
SELFTEST_ASSERT_PIN_BOOLEAN(5, false);
31+
2232
Sim_RunSeconds(1.0f, false);
23-
//Sim_RunFrames(1, false);
24-
//SELFTEST_ASSERT_PIN_BOOLEAN(4, true);
25-
//SELFTEST_ASSERT_PIN_BOOLEAN(5, false);
33+
// Still moving after 1 second (default open time is 10s)
34+
SELFTEST_ASSERT_PIN_BOOLEAN(4, true);
35+
SELFTEST_ASSERT_PIN_BOOLEAN(5, false);
36+
37+
// Stop the shutter
2638
CMD_ExecuteCommand("ShutterMove0 Stop", 0);
2739
Sim_RunFrames(1, false);
28-
//SELFTEST_ASSERT_PIN_BOOLEAN(4, false);
29-
//SELFTEST_ASSERT_PIN_BOOLEAN(5, false);
40+
// After Stop: both pins must be off
41+
SELFTEST_ASSERT_PIN_BOOLEAN(4, false);
42+
SELFTEST_ASSERT_PIN_BOOLEAN(5, false);
3043

3144

3245

src/selftest/selftest_tclAC.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,34 @@ void Test_Driver_TCL_AC() {
88
SIM_ClearOBK(0);
99
CMD_ExecuteCommand("lfs_format", 0);
1010
SIM_ClearUART();
11+
// Required to set up the receive ring buffer before feeding bytes with uartFakeHex
12+
SIM_UART_InitReceiveRingBuffer(256);
1113

1214
CMD_ExecuteCommand("startDriver TCL", 0);
1315

16+
// ACMode 1 = COOL mode: builds a 35-byte set command and flags it for sending
1417
CMD_ExecuteCommand("ACMode 1", 0);
1518
TCL_UART_RunEverySecond();
19+
// TCL set command is always 35 bytes — verify bytes were sent
20+
SELFTEST_ASSERT_HAS_SOME_DATA_IN_UART();
1621
SIM_ClearUART();
1722

23+
// FANMode 1 = FAN_1: rebuilds and queues another 35-byte set command
1824
CMD_ExecuteCommand("FANMode 1", 0);
1925
TCL_UART_RunEverySecond();
26+
SELFTEST_ASSERT_HAS_SOME_DATA_IN_UART();
2027
SIM_ClearUART();
2128

22-
29+
// Feed a valid 49-byte get-response packet into the simulated UART receive buffer.
30+
// TCL_UART_RunEverySecond calls TCL_UART_TryToGetNextPacket which parses this packet
31+
// and updates MQTT state (ACMode/FANMode/temperature).
2332
CMD_ExecuteCommand("uartFakeHex BB 01 00 04 2D 04 00 00 00 00 00 00 FF 00 00 00 00 00 FF FF 00 00 00 00 00 00 F0 FF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 6A", 0);
2433
TCL_UART_RunEverySecond();
34+
// After parsing the incoming packet, the AC is reported as off (power=0x01 in packet -> COOL)
35+
// Verify by checking the MQTT state was published
36+
SELFTEST_ASSERT_HAD_MQTT_PUBLISH_STR("obk0000/stat/ACMode", "cool", false);
2537
}
2638

2739

2840

29-
#endif
30-
3141

0 commit comments

Comments
 (0)