mirror of https://github.com/arendst/Tasmota.git
Merge pull request #12924 from s-hadinger/berry_rules
Berry system events for rules
This commit is contained in:
commit
0f49a21dd0
|
@ -15,6 +15,7 @@ class Timer
|
|||
end
|
||||
end
|
||||
|
||||
tasmota = nil
|
||||
class Tasmota
|
||||
|
||||
# add `chars_in_string(s:string,c:string) -> int``
|
||||
|
|
|
@ -801,6 +801,11 @@ bool RuleSetProcess(uint8_t rule_set, String &event_saved)
|
|||
|
||||
bool RulesProcessEvent(const char *json_event)
|
||||
{
|
||||
#ifdef USE_BERRY
|
||||
// events are passed to Berry before Rules engine
|
||||
callBerryRule(json_event);
|
||||
#endif
|
||||
|
||||
if (Rules.busy) { return false; }
|
||||
|
||||
Rules.busy = true;
|
||||
|
@ -858,7 +863,11 @@ void RulesInit(void)
|
|||
|
||||
void RulesEvery50ms(void)
|
||||
{
|
||||
#ifdef USE_BERRY
|
||||
if (!Rules.busy) { // Emitting Rules events is always enabled with Berry
|
||||
#else
|
||||
if (Settings->rule_enabled && !Rules.busy) { // Any rule enabled
|
||||
#endif
|
||||
char json_event[120];
|
||||
|
||||
if (-1 == Rules.new_power) { Rules.new_power = TasmotaGlobal.power; }
|
||||
|
|
|
@ -93,12 +93,13 @@ extern "C" {
|
|||
\*********************************************************************************************/
|
||||
// // call a function (if exists) of type void -> void
|
||||
|
||||
bool callBerryRule(void) {
|
||||
// If event == nullptr, then take XdrvMailbox.data
|
||||
bool callBerryRule(const char *event) {
|
||||
if (berry.rules_busy) { return false; }
|
||||
berry.rules_busy = true;
|
||||
char * json_event = XdrvMailbox.data;
|
||||
bool serviced = false;
|
||||
serviced = callBerryEventDispatcher(PSTR("rule"), nullptr, 0, XdrvMailbox.data);
|
||||
serviced = callBerryEventDispatcher(PSTR("rule"), nullptr, 0, event ? event : XdrvMailbox.data);
|
||||
berry.rules_busy = false;
|
||||
return serviced; // TODO event not handled
|
||||
}
|
||||
|
@ -732,7 +733,7 @@ bool Xdrv52(uint8_t function)
|
|||
|
||||
// Berry wide commands and events
|
||||
case FUNC_RULES_PROCESS:
|
||||
result = callBerryRule();
|
||||
result = callBerryRule(nullptr);
|
||||
break;
|
||||
case FUNC_MQTT_DATA:
|
||||
result = callBerryEventDispatcher(PSTR("mqtt_data"), XdrvMailbox.topic, 0, XdrvMailbox.data, XdrvMailbox.data_len);
|
||||
|
|
|
@ -1083,8 +1083,8 @@ bool XdrvRulesProcess(bool teleperiod, const char* event) {
|
|||
char* data_save = XdrvMailbox.data;
|
||||
XdrvMailbox.data = (char*)event;
|
||||
bool rule_handled = XdrvCallDriver(10, (teleperiod) ? FUNC_TELEPERIOD_RULES_PROCESS : FUNC_RULES_PROCESS);
|
||||
#ifdef USE_BERRY
|
||||
// events are passed to both Rules engine AND Berry engine
|
||||
#if defined(USE_BERRY) && !defined(USE_RULES)
|
||||
// events are sent to Berry in Rules driver, or here if USE_RULES is not defined (only on a subset)
|
||||
bool berry_handled = XdrvCallDriver(52, FUNC_RULES_PROCESS);
|
||||
rule_handled |= berry_handled;
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue