add: macro endpoint for execution
This commit is contained in:
parent
01ffb1d58d
commit
d3fd48b35a
9 changed files with 110 additions and 26 deletions
|
@ -95,7 +95,7 @@ junction_relay_schedule_get_relay_ids_with_schedule(int schedule_id)
|
|||
{
|
||||
sqlite3_stmt *stmt;
|
||||
|
||||
sqlite3_prepare_v2(global_database, "SELECT relay_id FROM junction_relay_schedule WHERE schedule_id=?1;", -1, &stmt, NULL);
|
||||
sqlite3_prepare_v2(global_database, "SELECT DISTINCT relay_id FROM junction_relay_schedule WHERE schedule_id=?1;", -1, &stmt, NULL);
|
||||
sqlite3_bind_int(stmt, 1, schedule_id);
|
||||
|
||||
return database_helper_get_ids(stmt);
|
||||
|
|
|
@ -160,28 +160,6 @@ macro_remove(macro_t *macro)
|
|||
return rc != SQLITE_DONE;
|
||||
}
|
||||
|
||||
int
|
||||
macro_is_protected(macro_t *macro)
|
||||
{
|
||||
uuid_t tmp_uuid;
|
||||
|
||||
memset(tmp_uuid, 0, sizeof(uuid_t));
|
||||
memcpy(tmp_uuid, "off", 3);
|
||||
if(uuid_compare(macro->uid, tmp_uuid) == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
memset(tmp_uuid, 0, sizeof(uuid_t));
|
||||
memcpy(tmp_uuid, "on", 2);
|
||||
if(uuid_compare(macro->uid, tmp_uuid) == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
macro_free(macro_t *macro)
|
||||
{
|
||||
|
@ -339,3 +317,14 @@ macro_get_all()
|
|||
return macro_db_select(stmt);
|
||||
|
||||
}
|
||||
|
||||
int*
|
||||
macro_get_target_relay_ids(int macro_id)
|
||||
{
|
||||
sqlite3_stmt *stmt;
|
||||
|
||||
sqlite3_prepare_v2(global_database, "SELECT DISTINCT relay_id FROM macro_actions WHERE macro_id=?1;", -1, &stmt, NULL);
|
||||
sqlite3_bind_int(stmt, 1, macro_id);
|
||||
|
||||
return database_helper_get_ids(stmt);
|
||||
}
|
||||
|
|
|
@ -123,6 +123,28 @@ macro_action_get_for_macro(int macro_id)
|
|||
return macro_action_db_select(stmt);
|
||||
}
|
||||
|
||||
int
|
||||
macro_action_execute(macro_action_t *macro_action)
|
||||
{
|
||||
schedule_t *schedule = schedule_get_by_id(macro_action->schedule_id);
|
||||
if(!schedule)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
relay_t *relay = relay_get_by_id(macro_action->relay_id);
|
||||
if(!relay)
|
||||
{
|
||||
free(schedule);
|
||||
return 1;
|
||||
}
|
||||
|
||||
schedule_free(relay->schedules[macro_action->weekday]);
|
||||
relay->schedules[macro_action->weekday] = schedule;
|
||||
|
||||
return relay_save(relay);
|
||||
}
|
||||
|
||||
void
|
||||
macro_action_free_list(macro_action_t **macro_actions)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue