Berry add `tasmota.publish_rule` (#15243)

* Berry add `tasmota.publish_rule`

* Fix return value
This commit is contained in:
s-hadinger 2022-03-28 22:29:06 +02:00 committed by GitHub
parent c2f827795d
commit 33120a85f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 103 additions and 83 deletions

View File

@ -674,6 +674,7 @@ extern const bcstring be_const_str_ptr;
extern const bcstring be_const_str_public_key;
extern const bcstring be_const_str_publish;
extern const bcstring be_const_str_publish_result;
extern const bcstring be_const_str_publish_rule;
extern const bcstring be_const_str_push;
extern const bcstring be_const_str_push_path;
extern const bcstring be_const_str_quality;

View File

@ -644,7 +644,7 @@ be_define_const_str(pc, "pc", 1313756516u, 0, 2, NULL);
be_define_const_str(pc_abs, "pc_abs", 920256495u, 0, 6, &be_const_str_signal_arcs);
be_define_const_str(pc_rel, "pc_rel", 991921176u, 0, 6, &be_const_str_string);
be_define_const_str(pct, "pct", 1431300144u, 0, 3, &be_const_str_remove_driver);
be_define_const_str(percentage, "percentage", 2538831285u, 0, 10, &be_const_str_splash_init);
be_define_const_str(percentage, "percentage", 2538831285u, 0, 10, &be_const_str_publish_rule);
be_define_const_str(persist, "persist", 3917083779u, 0, 7, NULL);
be_define_const_str(persist_X2E_p_X20is_X20not_X20a_X20map, "persist._p is not a map", 1176528732u, 0, 23, NULL);
be_define_const_str(pi, "pi", 1213090802u, 0, 2, &be_const_str_range);
@ -666,6 +666,7 @@ be_define_const_str(ptr, "ptr", 1433816073u, 0, 3, NULL);
be_define_const_str(public_key, "public_key", 4169142980u, 0, 10, &be_const_str_refr_size);
be_define_const_str(publish, "publish", 264247304u, 0, 7, &be_const_str_widget_width_def);
be_define_const_str(publish_result, "publish_result", 2013351252u, 0, 14, NULL);
be_define_const_str(publish_rule, "publish_rule", 1829459523u, 0, 12, &be_const_str_splash_init);
be_define_const_str(push, "push", 2272264157u, 0, 4, &be_const_str_remote_port);
be_define_const_str(push_path, "push_path", 1155254157u, 0, 9, NULL);
be_define_const_str(quality, "quality", 2597670950u, 0, 7, &be_const_str_wifi_arcs_icon);
@ -1425,6 +1426,6 @@ static const bstring* const m_string_table[] = {
static const struct bconststrtab m_const_string_table = {
.size = 466,
.count = 955,
.count = 956,
.table = m_string_table
};

View File

@ -2,96 +2,97 @@
static be_define_const_map_slots(be_class_tasmota_map) {
{ be_const_key(gc, -1), be_const_closure(Tasmota_gc_closure) },
{ be_const_key(resp_cmnd_done, -1), be_const_func(l_respCmndDone) },
{ be_const_key(web_send, 33), be_const_func(l_webSend) },
{ be_const_key(add_driver, 21), be_const_closure(Tasmota_add_driver_closure) },
{ be_const_key(wd, 12), be_const_var(0) },
{ be_const_key(resp_cmnd_error, 25), be_const_func(l_respCmndError) },
{ be_const_key(publish, 73), be_const_func(l_publish) },
{ be_const_key(gen_cb, 0), be_const_closure(Tasmota_gen_cb_closure) },
{ be_const_key(_settings_ptr, -1), be_const_comptr(&Settings) },
{ be_const_key(try_rule, -1), be_const_closure(Tasmota_try_rule_closure) },
{ be_const_key(resp_cmnd_str, -1), be_const_func(l_respCmndStr) },
{ be_const_key(time_dump, -1), be_const_func(l_time_dump) },
{ be_const_key(global, 16), be_const_var(1) },
{ be_const_key(millis, 35), be_const_func(l_millis) },
{ be_const_key(cmd_res, -1), be_const_var(2) },
{ be_const_key(get_power, -1), be_const_func(l_getpower) },
{ be_const_key(set_light, 40), be_const_closure(Tasmota_set_light_closure) },
{ be_const_key(set_power, -1), be_const_func(l_setpower) },
{ be_const_key(fast_loop, -1), be_const_closure(Tasmota_fast_loop_closure) },
{ be_const_key(get_option, -1), be_const_func(l_getoption) },
{ be_const_key(add_cron, -1), be_const_closure(Tasmota_add_cron_closure) },
{ be_const_key(_settings_def, -1), be_const_comptr(&be_tasmota_settings_struct) },
{ be_const_key(init, 41), be_const_closure(Tasmota_init_closure) },
{ be_const_key(add_rule, 19), be_const_closure(Tasmota_add_rule_closure) },
{ be_const_key(resp_cmnd_failed, -1), be_const_func(l_respCmndFailed) },
{ be_const_key(exec_tele, -1), be_const_closure(Tasmota_exec_tele_closure) },
{ be_const_key(add_fast_loop, -1), be_const_closure(Tasmota_add_fast_loop_closure) },
{ be_const_key(_global_def, -1), be_const_comptr(&be_tasmota_global_struct) },
{ be_const_key(yield, 71), be_const_func(l_yield) },
{ be_const_key(next_cron, -1), be_const_closure(Tasmota_next_cron_closure) },
{ be_const_key(web_send_decimal, -1), be_const_func(l_webSendDecimal) },
{ be_const_key(time_reached, 11), be_const_func(l_timereached) },
{ be_const_key(delay, -1), be_const_func(l_delay) },
{ be_const_key(rtc, -1), be_const_func(l_rtc) },
{ be_const_key(wire2, -1), be_const_var(3) },
{ be_const_key(add_cmd, 82), be_const_closure(Tasmota_add_cmd_closure) },
{ be_const_key(exec_rules, 14), be_const_closure(Tasmota_exec_rules_closure) },
{ be_const_key(set_timer, -1), be_const_closure(Tasmota_set_timer_closure) },
{ be_const_key(wire_scan, -1), be_const_closure(Tasmota_wire_scan_closure) },
{ be_const_key(run_cron, 37), be_const_closure(Tasmota_run_cron_closure) },
{ be_const_key(get_light, -1), be_const_closure(Tasmota_get_light_closure) },
{ be_const_key(cmd, -1), be_const_closure(Tasmota_cmd_closure) },
{ be_const_key(remove_cmd, -1), be_const_closure(Tasmota_remove_cmd_closure) },
{ be_const_key(hs2rgb, -1), be_const_closure(Tasmota_hs2rgb_closure) },
{ be_const_key(_fl, -1), be_const_var(4) },
{ be_const_key(gen_cb, -1), be_const_closure(Tasmota_gen_cb_closure) },
{ be_const_key(yield, 20), be_const_func(l_yield) },
{ be_const_key(log, 21), be_const_func(l_logInfo) },
{ be_const_key(find_op, -1), be_const_closure(Tasmota_find_op_closure) },
{ be_const_key(i2c_enabled, -1), be_const_func(l_i2cenabled) },
{ be_const_key(get_switches, -1), be_const_func(l_getswitch) },
{ be_const_key(_debug_present, 39), be_const_var(5) },
{ be_const_key(run_deferred, 18), be_const_closure(Tasmota_run_deferred_closure) },
{ be_const_key(load, -1), be_const_closure(Tasmota_load_closure) },
{ be_const_key(get_switch, 75), be_const_func(l_getswitch) },
{ be_const_key(chars_in_string, -1), be_const_closure(Tasmota_chars_in_string_closure) },
{ be_const_key(resp_cmnd, 51), be_const_func(l_respCmnd) },
{ be_const_key(event, 22), be_const_closure(Tasmota_event_closure) },
{ be_const_key(_ccmd, -1), be_const_var(6) },
{ be_const_key(_rules, 20), be_const_var(7) },
{ be_const_key(wire1, -1), be_const_var(8) },
{ be_const_key(remove_timer, 5), be_const_closure(Tasmota_remove_timer_closure) },
{ be_const_key(eth, -1), be_const_func(l_eth) },
{ be_const_key(arch, 43), be_const_func(l_arch) },
{ be_const_key(remove_driver, -1), be_const_closure(Tasmota_remove_driver_closure) },
{ be_const_key(response_append, -1), be_const_func(l_respAppend) },
{ be_const_key(wifi, -1), be_const_func(l_wifi) },
{ be_const_key(strptime, 56), be_const_func(l_strptime) },
{ be_const_key(find_op, 78), be_const_closure(Tasmota_find_op_closure) },
{ be_const_key(log, -1), be_const_func(l_logInfo) },
{ be_const_key(web_send, -1), be_const_func(l_webSend) },
{ be_const_key(hs2rgb, -1), be_const_closure(Tasmota_hs2rgb_closure) },
{ be_const_key(resolvecmnd, 1), be_const_func(l_resolveCmnd) },
{ be_const_key(load, -1), be_const_closure(Tasmota_load_closure) },
{ be_const_key(_fl, -1), be_const_var(0) },
{ be_const_key(get_power, -1), be_const_func(l_getpower) },
{ be_const_key(add_rule, 32), be_const_closure(Tasmota_add_rule_closure) },
{ be_const_key(eth, 30), be_const_func(l_eth) },
{ be_const_key(time_dump, -1), be_const_func(l_time_dump) },
{ be_const_key(exec_rules, -1), be_const_closure(Tasmota_exec_rules_closure) },
{ be_const_key(chars_in_string, -1), be_const_closure(Tasmota_chars_in_string_closure) },
{ be_const_key(cmd, -1), be_const_closure(Tasmota_cmd_closure) },
{ be_const_key(_rules, -1), be_const_var(1) },
{ be_const_key(exec_tele, -1), be_const_closure(Tasmota_exec_tele_closure) },
{ be_const_key(get_option, -1), be_const_func(l_getoption) },
{ be_const_key(get_switches, 46), be_const_func(l_getswitch) },
{ be_const_key(global, -1), be_const_var(2) },
{ be_const_key(arch, -1), be_const_func(l_arch) },
{ be_const_key(wire1, -1), be_const_var(3) },
{ be_const_key(scale_uint, 15), be_const_func(l_scaleuint) },
{ be_const_key(millis, 8), be_const_func(l_millis) },
{ be_const_key(resp_cmnd_error, 64), be_const_func(l_respCmndError) },
{ be_const_key(publish, -1), be_const_func(l_publish) },
{ be_const_key(_settings_def, 75), be_const_comptr(&be_tasmota_settings_struct) },
{ be_const_key(init, -1), be_const_closure(Tasmota_init_closure) },
{ be_const_key(_settings_ptr, -1), be_const_comptr(&Settings) },
{ be_const_key(publish_rule, 57), be_const_func(l_publish_rule) },
{ be_const_key(remove_driver, 49), be_const_closure(Tasmota_remove_driver_closure) },
{ be_const_key(run_deferred, 25), be_const_closure(Tasmota_run_deferred_closure) },
{ be_const_key(read_sensors, 82), be_const_func(l_read_sensors) },
{ be_const_key(_timers, -1), be_const_var(4) },
{ be_const_key(set_light, -1), be_const_closure(Tasmota_set_light_closure) },
{ be_const_key(memory, 31), be_const_func(l_memory) },
{ be_const_key(wire_scan, -1), be_const_closure(Tasmota_wire_scan_closure) },
{ be_const_key(get_light, -1), be_const_closure(Tasmota_get_light_closure) },
{ be_const_key(_cmd, 76), be_const_func(l_cmd) },
{ be_const_key(exec_cmd, -1), be_const_closure(Tasmota_exec_cmd_closure) },
{ be_const_key(find_key_i, -1), be_const_closure(Tasmota_find_key_i_closure) },
{ be_const_key(_global_addr, -1), be_const_comptr(&TasmotaGlobal) },
{ be_const_key(save, -1), be_const_func(l_save) },
{ be_const_key(exec_cmd, 63), be_const_closure(Tasmota_exec_cmd_closure) },
{ be_const_key(remove_rule, -1), be_const_closure(Tasmota_remove_rule_closure) },
{ be_const_key(wifi, -1), be_const_func(l_wifi) },
{ be_const_key(rtc, -1), be_const_func(l_rtc) },
{ be_const_key(time_str, -1), be_const_closure(Tasmota_time_str_closure) },
{ be_const_key(settings, -1), be_const_var(9) },
{ be_const_key(publish_result, -1), be_const_func(l_publish_result) },
{ be_const_key(resp_cmnd, 17), be_const_func(l_respCmnd) },
{ be_const_key(add_cmd, -1), be_const_closure(Tasmota_add_cmd_closure) },
{ be_const_key(get_switch, -1), be_const_func(l_getswitch) },
{ be_const_key(save, -1), be_const_func(l_save) },
{ be_const_key(wire2, -1), be_const_var(5) },
{ be_const_key(run_cron, 0), be_const_closure(Tasmota_run_cron_closure) },
{ be_const_key(delay, -1), be_const_func(l_delay) },
{ be_const_key(set_timer, -1), be_const_closure(Tasmota_set_timer_closure) },
{ be_const_key(time_reached, -1), be_const_func(l_timereached) },
{ be_const_key(set_power, -1), be_const_func(l_setpower) },
{ be_const_key(_global_addr, -1), be_const_comptr(&TasmotaGlobal) },
{ be_const_key(_ccmd, -1), be_const_var(6) },
{ be_const_key(next_cron, 16), be_const_closure(Tasmota_next_cron_closure) },
{ be_const_key(cmd_res, -1), be_const_var(7) },
{ be_const_key(strftime, 80), be_const_func(l_strftime) },
{ be_const_key(event, -1), be_const_closure(Tasmota_event_closure) },
{ be_const_key(settings, -1), be_const_var(8) },
{ be_const_key(strptime, -1), be_const_func(l_strptime) },
{ be_const_key(resp_cmnd_done, 51), be_const_func(l_respCmndDone) },
{ be_const_key(remove_cmd, -1), be_const_closure(Tasmota_remove_cmd_closure) },
{ be_const_key(try_rule, -1), be_const_closure(Tasmota_try_rule_closure) },
{ be_const_key(resp_cmnd_str, 59), be_const_func(l_respCmndStr) },
{ be_const_key(_drivers, -1), be_const_var(9) },
{ be_const_key(_crons, 56), be_const_var(10) },
{ be_const_key(check_not_method, 62), be_const_closure(Tasmota_check_not_method_closure) },
{ be_const_key(remove_cron, 65), be_const_closure(Tasmota_remove_cron_closure) },
{ be_const_key(get_free_heap, -1), be_const_func(l_getFreeHeap) },
{ be_const_key(_timers, -1), be_const_var(10) },
{ be_const_key(scale_uint, 10), be_const_func(l_scaleuint) },
{ be_const_key(strftime, 9), be_const_func(l_strftime) },
{ be_const_key(_cmd, -1), be_const_func(l_cmd) },
{ be_const_key(check_not_method, -1), be_const_closure(Tasmota_check_not_method_closure) },
{ be_const_key(remove_cron, -1), be_const_closure(Tasmota_remove_cron_closure) },
{ be_const_key(resolvecmnd, 54), be_const_func(l_resolveCmnd) },
{ be_const_key(_drivers, -1), be_const_var(11) },
{ be_const_key(_crons, 65), be_const_var(12) },
{ be_const_key(memory, -1), be_const_func(l_memory) },
{ be_const_key(read_sensors, 74), be_const_func(l_read_sensors) },
{ be_const_key(remove_timer, -1), be_const_closure(Tasmota_remove_timer_closure) },
{ be_const_key(resp_cmnd_failed, -1), be_const_func(l_respCmndFailed) },
{ be_const_key(add_driver, -1), be_const_closure(Tasmota_add_driver_closure) },
{ be_const_key(_debug_present, -1), be_const_var(11) },
{ be_const_key(wd, 14), be_const_var(12) },
{ be_const_key(_global_def, -1), be_const_comptr(&be_tasmota_global_struct) },
{ be_const_key(web_send_decimal, -1), be_const_func(l_webSendDecimal) },
{ be_const_key(publish_result, -1), be_const_func(l_publish_result) },
{ be_const_key(fast_loop, -1), be_const_closure(Tasmota_fast_loop_closure) },
{ be_const_key(add_cron, -1), be_const_closure(Tasmota_add_cron_closure) },
{ be_const_key(add_fast_loop, -1), be_const_closure(Tasmota_add_fast_loop_closure) },
{ be_const_key(remove_rule, -1), be_const_closure(Tasmota_remove_rule_closure) },
};
static be_define_const_map(
be_class_tasmota_map,
86
87
);
BE_EXPORT_VARIABLE be_define_const_class(

View File

@ -15,6 +15,7 @@ extern int l_getFreeHeap(bvm *vm);
extern int l_arch(bvm *vm);
extern int l_publish(bvm *vm);
extern int l_publish_result(bvm *vm);
extern int l_publish_rule(bvm *vm);
extern int l_cmd(bvm *vm);
extern int l_getoption(bvm *vm);
extern int l_millis(bvm *vm);
@ -2564,6 +2565,7 @@ class be_class_tasmota (scope: global, name: Tasmota) {
arch, func(l_arch)
publish, func(l_publish)
publish_result, func(l_publish_result)
publish_rule, func(l_publish_rule)
_cmd, func(l_cmd)
get_option, func(l_getoption)
millis, func(l_millis)

View File

@ -84,6 +84,21 @@ extern "C" {
be_raise(vm, kTypeError, nullptr);
}
// Berry: `tasmota.publish_rulet(payload:string) -> bool``
//
// Returns `true` if event was handled
int32_t l_publish_rule(struct bvm *vm);
int32_t l_publish_rule(struct bvm *vm) {
int32_t top = be_top(vm); // Get the number of arguments
if (top >= 2 && be_isstring(vm, 2)) { // 1 mandatory string argument
const char * payload = be_tostring(vm, 2);
bool handled = XdrvRulesProcess(0, payload);
be_pushbool(vm, handled);
be_return(vm); // Return
}
be_raise(vm, kTypeError, nullptr);
}
// Berry: `tasmota.cmd(command:string) -> string`
//
int32_t l_cmd(struct bvm *vm);