Rules can have a second condition, and contains / does not contain

A paused printer that is only soaking no longer brings the printer page to the
front: print state = paused and display message does not contain soaking.

The schedule format changes (version 6), so the stored schedule has to be saved
again after flashing. Pins espressif32@6.10.0: the unpinned platform now resolves
to Arduino core 3, which the firmware doesn't build on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mangavalkandClaude Opus 5.5 committed 2026-11-03 22:43:17 +01:00
1 parent abd63d070f
commit 35e678d78d
13 files changed
+155 -31

No files matched your search

+61
View File
@@ -1976,6 +1976,64 @@ void test_rule_comparisons()
TEST_ASSERT_TRUE(ruleMatches(r, "-3"));
}
void test_rule_contains()
{
const char *soaking = "Soaking -- temp: 51.3C / 46.0C -- 26.8m remaining";
TriggerRule r = rule("x", TriggerMode::WhileTrue);
r.compare = Compare::Contains;
strcpy(r.value, "soaking");
TEST_ASSERT_TRUE(ruleMatches(r, soaking)); // without case
TEST_ASSERT_FALSE(ruleMatches(r, "Heating"));
TEST_ASSERT_FALSE(ruleMatches(r, ""));
TEST_ASSERT_FALSE(ruleMatches(r, nullptr));
strcpy(r.value, "remaining");
TEST_ASSERT_TRUE(ruleMatches(r, soaking)); // at the very end
strcpy(r.value, "remaining!");
TEST_ASSERT_FALSE(ruleMatches(r, soaking)); // longer than what is left of the text
strcpy(r.value, "soaking");
r.compare = Compare::NotContains;
TEST_ASSERT_FALSE(ruleMatches(r, soaking));
TEST_ASSERT_TRUE(ruleMatches(r, "Heating"));
TEST_ASSERT_TRUE(ruleMatches(r, ""));
TEST_ASSERT_FALSE(ruleMatches(r, nullptr)); // unknown is never true
}
void test_rule_second_condition()
{
TriggerRule r = rule("x", TriggerMode::WhileTrue);
strcpy(r.value, "paused");
// Without a second entity its value doesn't matter
TEST_ASSERT_TRUE(ruleMatches(r, "paused"));
TEST_ASSERT_TRUE(ruleMatches(r, "paused", "Soaking"));
strcpy(r.and_entity, "sensor.message");
r.and_compare = Compare::NotContains;
strcpy(r.and_value, "soaking");
TEST_ASSERT_TRUE(ruleMatches(r, "paused", "Filament runout"));
TEST_ASSERT_FALSE(ruleMatches(r, "paused", "Soaking -- temp: 51.3C"));
TEST_ASSERT_FALSE(ruleMatches(r, "printing", "Filament runout"));
TEST_ASSERT_FALSE(ruleMatches(r, nullptr, "Filament runout"));
TEST_ASSERT_FALSE(ruleMatches(r, "paused", nullptr)); // unknown is never true
}
void test_schedule_checks_the_second_condition()
{
PageSchedule s;
s.rule_count = 1;
s.rules[0] = rule("x", TriggerMode::WhileTrue);
TEST_ASSERT_NULL(validateSchedule(s)); // no second condition is fine
strcpy(s.rules[0].and_entity, "sensor.message");
TEST_ASSERT_NULL(validateSchedule(s));
strcpy(s.rules[0].and_entity, "not an entity");
TEST_ASSERT_NOT_NULL(validateSchedule(s));
strcpy(s.rules[0].and_entity, "sensor.message");
strcpy(s.rules[0].and_attribute, "a b");
TEST_ASSERT_NOT_NULL(validateSchedule(s));
s.rules[0].and_attribute[0] = '\0';
s.rules[0].and_compare = Compare::Count;
TEST_ASSERT_NOT_NULL(validateSchedule(s));
}
void test_selector_without_schedule_shows_the_chosen_page()
{
PageSelector sel;
@@ -3375,6 +3433,9 @@ int main()
RUN_TEST(test_moving_page_is_redrawn_when_due);
RUN_TEST(test_schedule_validation);
RUN_TEST(test_rule_comparisons);
RUN_TEST(test_rule_contains);
RUN_TEST(test_rule_second_condition);
RUN_TEST(test_schedule_checks_the_second_condition);
RUN_TEST(test_selector_without_schedule_shows_the_chosen_page);
RUN_TEST(test_selector_rotates_the_block);
RUN_TEST(test_selector_manual_pick_until_the_next_block);