Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added fix for setSceneState #104

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ int ezlopi_core_scene_edit_update_id(uint32_t scene_id, cJSON* cj_updated_scene)
{
ezlopi_meshobot_service_stop_scene(scene_node);
_edit_scene(scene_node, cj_updated_scene);

TRACE_S("HERE : scene_node->enabled = [%s]", (scene_node->enabled) ? "true" : "false");
if (scene_node->enabled == true)
{
ezlopi_meshbot_service_start_scene(scene_node);
Expand Down
33 changes: 12 additions & 21 deletions ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_then_methods.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "ezlopi_core_http.h"
#include "ezlopi_core_reset.h"
#include "ezlopi_core_devices.h"
#include "ezlopi_core_scenes_v2.h"
#include "ezlopi_core_event_group.h"
#include "ezlopi_core_factory_info.h"
#include "ezlopi_core_scenes_scripts.h"
Expand All @@ -29,7 +30,7 @@ int ezlopi_scene_then_set_item_value(l_scenes_list_v2_t* curr_scene, void* arg)
l_fields_v2_t* curr_field = curr_then->fields;
while (curr_field)
{
if (0 == strncmp(curr_field->name, "item", 4))
if (0 == strncmp(curr_field->name, "item", 5))
{
cJSON_AddStringToObject(cj_params, ezlopi__id_str, curr_field->field_value.u_value.value_string);
item_id = strtoul(curr_field->field_value.u_value.value_string, NULL, 16);
Expand Down Expand Up @@ -315,27 +316,22 @@ int ezlopi_scene_then_set_scene_state(l_scenes_list_v2_t* curr_scene, void* arg)
l_fields_v2_t* curr_field = curr_then->fields;
while (curr_field)
{
if (0 == strncmp(curr_field->name, "sceneId", 7))
if (0 == strncmp(curr_field->name, ezlopi_sceneId_str, 8))
{
if (curr_field->field_value.e_type == VALUE_TYPE_STRING)
if (EZLOPI_VALUE_TYPE_SCENEID == curr_field->value_type)
{
sceneID = strtoul(curr_field->field_value.u_value.value_string, NULL, 16);
}
else
{
ret = 1;
}
}
else if (0 == strncmp(curr_field->name, "enabled", 5))
else if (0 == strncmp(curr_field->name, ezlopi_enabled_str, 8))
{
if (curr_field->field_value.e_type == VALUE_TYPE_BOOL)

TRACE_W("%s", (curr_field->field_value.u_value.value_bool ? "true" : "false"));

if (EZLOPI_VALUE_TYPE_BOOL == curr_field->value_type)
{
set_scene_enable = curr_field->field_value.u_value.value_bool;
}
else
{
ret = 1;
}
}
curr_field = curr_field->next;
}
Expand All @@ -345,20 +341,15 @@ int ezlopi_scene_then_set_scene_state(l_scenes_list_v2_t* curr_scene, void* arg)
if (1 == ezlopi_scenes_enable_disable_id_from_list_v2(sceneID, set_scene_enable))
{
ezlopi_scenes_status_change_broadcast(scene_node, scene_status_finished_str);
ret = 1;
}
else
{
TRACE_W("Failed set_scene_state");
ezlopi_scenes_status_change_broadcast(scene_node, scene_status_failed_str);
}
}
else
{
ret = 1;
}
}
else
{
ret = 1;
TRACE_W("ret = %d", ret);
}
return ret;
}
Expand Down
28 changes: 24 additions & 4 deletions ezlopi-core/ezlopi-core-scenes/ezlopi_core_scenes_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,19 +302,39 @@ int ezlopi_scenes_enable_disable_id_from_list_v2(uint32_t _id, bool enabled_flag
cJSON* cj_scene = cJSON_Parse(scene_str);
if (cj_scene)
{
cJSON* enable_item = (cJSON_GetObjectItem(cj_scene, "enabled"));
cJSON* enable_item = cJSON_GetObjectItem(cj_scene, ezlopi_enabled_str);
if (enable_item && cJSON_IsBool(enable_item))
{
cJSON_ReplaceItemInObject(cj_scene, "enabled", cJSON_CreateBool(enabled_flag));
if (1 == ezlopi_scene_edit_by_id(_id, cj_scene))
enable_item->type = (enabled_flag) ? cJSON_True : cJSON_False;

l_scenes_list_v2_t* curr_scene_head = scenes_list_head_v2;
while (curr_scene_head)
{
if (curr_scene_head->_id == _id)
{
curr_scene_head->enabled = enabled_flag;
break;
}

curr_scene_head = curr_scene_head->next;
}

CJSON_TRACE("cj_scene----2", cj_scene);

if (1 == ezlopi_core_scene_edit_store_updated_to_nvs(cj_scene))
{
ret = 1;
TRACE_W("nvs enabled successfull");
}
else
{
TRACE_E("HERE");
TRACE_E("Error!! failed");
}
}
else
{
TRACE_W("HERE-> enabled option invalid");
}
cJSON_Delete(cj_scene);
}
// free the scene_name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ int ezlopi_scene_when_is_scene_state(l_scenes_list_v2_t* scene_node, void* arg)
// {
// ret = (false == curr_scene->enabled)? 1:0;
// }
TRACE_E("scene_state : %s , ret = %d", ezlopi_scenes_status_to_string(curr_scene->status), ret);
// TRACE_E("scene_state : %s , ret = %d", ezlopi_scenes_status_to_string(curr_scene->status), ret);
break;
}
curr_scene = curr_scene->next;
Expand Down