2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "smartthings_resource.h"
20 #define VALUE_STR_LEN_MAX 32
22 static const char *PROP_POWER = "power";
23 static const char *VALUE_SWITCH_ON = "on";
24 static const char *VALUE_SWITCH_OFF = "off";
25 static char g_switch[VALUE_STR_LEN_MAX] = "off";
26 bool g_switch_is_on = false;
28 bool handle_get_request_on_resource_capability_switch_main_0(smartthings_payload_h resp_payload, void *user_data)
30 int error = SMARTTHINGS_RESOURCE_ERROR_NONE;
32 error = smartthings_payload_set_string(resp_payload, PROP_POWER, g_switch);
33 if (error != SMARTTHINGS_RESOURCE_ERROR_NONE) {
34 _E("smartthings_payload_set_string() failed, [%d]", error);
37 _D("get switch : %s", g_switch);
42 bool handle_set_request_on_resource_capability_switch_main_0(smartthings_payload_h payload, smartthings_payload_h resp_payload, void *user_data)
44 char *str_value = NULL;
45 int error = SMARTTHINGS_RESOURCE_ERROR_NONE;
47 error = smartthings_payload_get_string(payload, PROP_POWER, &str_value);
48 if (error != SMARTTHINGS_RESOURCE_ERROR_NONE) {
49 _E("smartthings_payload_get_string() failed, [%d]", error);
52 _D("set switch : %s", str_value);
54 /* check validation */
55 if ((0 != strncmp(str_value, VALUE_SWITCH_ON, strlen(VALUE_SWITCH_ON)))
56 && (0 != strncmp(str_value, VALUE_SWITCH_OFF, strlen(VALUE_SWITCH_OFF)))) {
57 _E("Not supported value!!");
62 if (0 != strncmp(str_value, g_switch, strlen(g_switch))) {
63 strncpy(g_switch, str_value, VALUE_STR_LEN_MAX);
64 if (0 == strncmp(g_switch, VALUE_SWITCH_ON, strlen(VALUE_SWITCH_ON))) {
65 g_switch_is_on = true;
67 g_switch_is_on = false;
72 error = smartthings_payload_set_string(resp_payload, PROP_POWER, g_switch);
73 if (error != SMARTTHINGS_RESOURCE_ERROR_NONE) {
74 _E("smartthings_payload_set_string() failed, [%d]", error);