Public Access
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:
1 parent
abd63d070f
commit
35e678d78d
13 files changed
+155
-31
No files matched your search
@@ -50,10 +50,16 @@ const char *validateSchedule(const PageSchedule &s)
|
||||
return "Rules need an entity id like sensor.printer_state";
|
||||
if (!terminated(r.attribute, sizeof(r.attribute)) || !validAttribute(r.attribute))
|
||||
return "Invalid attribute";
|
||||
if (r.compare >= Compare::Count || r.mode >= TriggerMode::Count)
|
||||
if (r.compare >= Compare::Count || r.and_compare >= Compare::Count || r.mode >= TriggerMode::Count)
|
||||
return "Unknown rule setting";
|
||||
if (!terminated(r.value, sizeof(r.value)))
|
||||
return "Rule value too long (32 characters)";
|
||||
if (!terminated(r.and_entity, sizeof(r.and_entity)) || (r.and_entity[0] && !validEntityId(r.and_entity)))
|
||||
return "Rules need an entity id like sensor.printer_state";
|
||||
if (!terminated(r.and_attribute, sizeof(r.and_attribute)) || !validAttribute(r.and_attribute))
|
||||
return "Invalid attribute";
|
||||
if (!terminated(r.and_value, sizeof(r.and_value)))
|
||||
return "Rule value too long (32 characters)";
|
||||
if (!terminated(r.page, sizeof(r.page)) || !validBitmapName(r.page))
|
||||
return "Choose a page for each rule";
|
||||
if (r.mode != TriggerMode::WhileTrue && (r.seconds < 1 || r.seconds > ITEM_SECONDS_MAX))
|
||||
@@ -74,6 +80,21 @@ static bool sameText(const char *a, const char *b)
|
||||
return *a == *b;
|
||||
}
|
||||
|
||||
// Whether `part` is somewhere in `text`, without case
|
||||
static bool hasText(const char *text, const char *part)
|
||||
{
|
||||
for (;; text++)
|
||||
{
|
||||
const char *a = text, *b = part;
|
||||
while (*a && *b && tolower((unsigned char)*a) == tolower((unsigned char)*b))
|
||||
a++, b++;
|
||||
if (!*b)
|
||||
return true;
|
||||
if (!*text)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static bool number(const char *text, double &value)
|
||||
{
|
||||
char *end;
|
||||
@@ -86,26 +107,36 @@ bool ruleInBlock(const TriggerRule &rule, int block)
|
||||
return rule.blocks == 0 || block < 0 || (rule.blocks >> block) & 1;
|
||||
}
|
||||
|
||||
bool ruleMatches(const TriggerRule &rule, const char *value)
|
||||
static bool conditionTrue(Compare compare, const char *value, const char *wanted)
|
||||
{
|
||||
if (value == nullptr)
|
||||
return false;
|
||||
double a, b;
|
||||
switch (rule.compare)
|
||||
switch (compare)
|
||||
{
|
||||
case Compare::Equal:
|
||||
return sameText(value, rule.value);
|
||||
return sameText(value, wanted);
|
||||
case Compare::NotEqual:
|
||||
return !sameText(value, rule.value);
|
||||
return !sameText(value, wanted);
|
||||
case Compare::Above:
|
||||
return number(value, a) && number(rule.value, b) && a > b;
|
||||
return number(value, a) && number(wanted, b) && a > b;
|
||||
case Compare::Below:
|
||||
return number(value, a) && number(rule.value, b) && a < b;
|
||||
return number(value, a) && number(wanted, b) && a < b;
|
||||
case Compare::Contains:
|
||||
return hasText(value, wanted);
|
||||
case Compare::NotContains:
|
||||
return !hasText(value, wanted);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ruleMatches(const TriggerRule &rule, const char *value, const char *and_value)
|
||||
{
|
||||
return conditionTrue(rule.compare, value, rule.value) &&
|
||||
(!rule.and_entity[0] || conditionTrue(rule.and_compare, and_value, rule.and_value));
|
||||
}
|
||||
|
||||
bool scheduleUses(const PageSchedule &s, const char *name)
|
||||
{
|
||||
for (int i = 0; i < s.block_count; i++)
|
||||
|
||||
Reference in new issue
Block a user