|
24 | 24 | #include "zwave_controller_utils.h"
|
25 | 25 | #include "zpc_attribute_store_network_helper.h"
|
26 | 26 | #include "zpc_attribute_resolver.h"
|
| 27 | +#include "zwave_command_class_user_code_types.h" |
27 | 28 |
|
28 | 29 | // Includes from Unify Components
|
| 30 | +#include "dotdot_mqtt.h" |
| 31 | +#include "dotdot_mqtt_generated_commands.h" |
29 | 32 | #include "attribute_store.h"
|
30 | 33 | #include "attribute_store_helper.h"
|
31 | 34 | #include "attribute_resolver.h"
|
@@ -875,6 +878,19 @@ static void zwave_command_class_user_code_on_number_of_users_update(
|
875 | 878 | attribute_store_node_t endpoint_node
|
876 | 879 | = attribute_store_get_first_parent_with_type(updated_node,
|
877 | 880 | ATTRIBUTE_ENDPOINT_ID);
|
| 881 | + attribute_store_node_t version_node |
| 882 | + = attribute_store_get_first_child_by_type(endpoint_node, |
| 883 | + ATTRIBUTE(VERSION)); |
| 884 | + // We need to check the version of the supporting node: |
| 885 | + zwave_cc_version_t supporting_node_version = 0; |
| 886 | + attribute_store_get_reported(version_node, |
| 887 | + &supporting_node_version, |
| 888 | + sizeof(supporting_node_version)); |
| 889 | + if (supporting_node_version == 1) { |
| 890 | + sl_log_debug(LOG_TAG, "Skip creating User ID nodes for CC UserCode V1."); |
| 891 | + return; |
| 892 | + } |
| 893 | + |
878 | 894 | attribute_store_node_t data_node
|
879 | 895 | = attribute_store_get_first_child_by_type(endpoint_node, ATTRIBUTE(DATA));
|
880 | 896 |
|
@@ -905,6 +921,78 @@ static void zwave_command_class_user_code_on_capabilities_created(
|
905 | 921 | COUNT_OF(capabilities_attributes));
|
906 | 922 | }
|
907 | 923 |
|
| 924 | +static void zwave_command_class_user_code_on_code_update( |
| 925 | + attribute_store_node_t updated_node, attribute_store_change_t change) |
| 926 | +{ |
| 927 | + if (change != ATTRIBUTE_UPDATED) { |
| 928 | + return; |
| 929 | + } |
| 930 | + |
| 931 | + // Get pin code value |
| 932 | + char pin_code [ATTRIBUTE_STORE_MAXIMUM_VALUE_LENGTH] = {0}; |
| 933 | + attribute_store_get_reported_string(updated_node, |
| 934 | + pin_code, |
| 935 | + ATTRIBUTE_STORE_MAXIMUM_VALUE_LENGTH); |
| 936 | + attribute_store_node_t user_id_node |
| 937 | + = attribute_store_get_first_parent_with_type(updated_node, |
| 938 | + ATTRIBUTE(USER_ID)); |
| 939 | + // get user id value |
| 940 | + uint16_t user_id = 0; |
| 941 | + attribute_store_get_reported(user_id_node, &user_id, sizeof(user_id)); |
| 942 | + |
| 943 | + attribute_store_node_t endpoint_id_node |
| 944 | + = attribute_store_get_first_parent_with_type(user_id_node, |
| 945 | + ATTRIBUTE_ENDPOINT_ID); |
| 946 | + zwave_endpoint_id_t endpoint_id = 0; |
| 947 | + attribute_store_get_reported(endpoint_id_node, &endpoint_id, sizeof(endpoint_id)); |
| 948 | + |
| 949 | + attribute_store_node_t node_id_node |
| 950 | + = attribute_store_get_first_parent_with_type(endpoint_id_node, |
| 951 | + ATTRIBUTE_NODE_ID); |
| 952 | + zwave_node_id_t node_id = 0; |
| 953 | + attribute_store_get_reported(node_id_node, &node_id, sizeof(node_id)); |
| 954 | + |
| 955 | + unid_t node_unid; |
| 956 | + zwave_unid_from_node_id(node_id, node_unid); |
| 957 | + |
| 958 | + attribute_store_node_t status_node |
| 959 | + = attribute_store_get_first_child_by_type(user_id_node, |
| 960 | + ATTRIBUTE(USER_ID_STATUS)); |
| 961 | + uint8_t ustatus = 0; |
| 962 | + attribute_store_get_reported(status_node, &ustatus, sizeof(ustatus)); |
| 963 | + DrlkUserStatus user_status = 0; |
| 964 | + switch (ustatus) { |
| 965 | + case USER_STATUS_AVAILABLE: |
| 966 | + user_status = ZCL_DRLK_USER_STATUS_AVAILABLE; |
| 967 | + break; |
| 968 | + case USER_STATUS_ENABLED: |
| 969 | + user_status = ZCL_DRLK_USER_STATUS_OCCUPIED_ENABLED; |
| 970 | + break; |
| 971 | + case USER_STATUS_DISABLED: |
| 972 | + user_status = ZCL_DRLK_USER_STATUS_OCCUPIED_DISABLED; |
| 973 | + break; |
| 974 | + case USER_STATUS_MESSAGING: |
| 975 | + user_status = ZCL_DRLK_USER_STATUS_OCCUPIED_ENABLED; |
| 976 | + break; |
| 977 | + case USER_STATUS_PASSAGE_MODE: |
| 978 | + user_status = ZCL_DRLK_USER_STATUS_OCCUPIED_DISABLED; |
| 979 | + break; |
| 980 | + } |
| 981 | + |
| 982 | + if (attribute_store_is_desired_defined(updated_node) == false) { |
| 983 | + uic_mqtt_dotdot_door_lock_command_getpin_code_response_fields_t fields = |
| 984 | + { |
| 985 | + .userid = (DrlkPINUserID) user_id, |
| 986 | + .user_status = (DrlkUserStatus) user_status, |
| 987 | + .user_type = (DrlkUserType) ZCL_DRLK_USER_TYPE_UNRESTRICTED_USER, |
| 988 | + .code = pin_code |
| 989 | + }; |
| 990 | + |
| 991 | + uic_mqtt_dotdot_door_lock_publish_generated_getpin_code_response_command( |
| 992 | + node_unid, endpoint_id, &fields); |
| 993 | + } |
| 994 | +} |
| 995 | + |
908 | 996 | ///////////////////////////////////////////////////////////////////////////////
|
909 | 997 | // Attribute Resolver callback functions
|
910 | 998 | ///////////////////////////////////////////////////////////////////////////////
|
@@ -1067,6 +1155,10 @@ static sl_status_t
|
1067 | 1155 | memcpy(user_code, &frame[4], user_code_length);
|
1068 | 1156 | user_code[user_code_length] = '\0';
|
1069 | 1157 | attribute_store_set_reported_string(user_code_node, user_code);
|
| 1158 | + if (user_code_node != ATTRIBUTE_STORE_INVALID_NODE) { |
| 1159 | + zwave_command_class_user_code_on_code_update(user_code_node, |
| 1160 | + ATTRIBUTE_UPDATED); |
| 1161 | + } |
1070 | 1162 | attribute_store_undefine_desired(user_code_node);
|
1071 | 1163 |
|
1072 | 1164 | return SL_STATUS_OK;
|
@@ -1167,6 +1259,10 @@ static sl_status_t handle_extended_user_code_report(
|
1167 | 1259 | }
|
1168 | 1260 |
|
1169 | 1261 | attribute_store_set_reported_string(user_code_node, user_code);
|
| 1262 | + if (user_code_node != ATTRIBUTE_STORE_INVALID_NODE) { |
| 1263 | + zwave_command_class_user_code_on_code_update(user_code_node, |
| 1264 | + ATTRIBUTE_UPDATED); |
| 1265 | + } |
1170 | 1266 | attribute_store_undefine_desired(user_code_node);
|
1171 | 1267 |
|
1172 | 1268 | j += 4 + user_code_length;
|
|
0 commit comments