|
| 1 | + |
| 2 | +/****************************************************************************** |
| 3 | + * # License |
| 4 | + * <b>Copyright 2024 Silicon Laboratories Inc. www.silabs.com</b> |
| 5 | + ****************************************************************************** |
| 6 | + * The licensor of this software is Silicon Laboratories Inc. Your use of this |
| 7 | + * software is governed by the terms of Silicon Labs Master Software License |
| 8 | + * Agreement (MSLA) available at |
| 9 | + * www.silabs.com/about-us/legal/master-software-license-agreement. This |
| 10 | + * software is distributed to you in Source Code format and is governed by the |
| 11 | + * sections of the MSLA applicable to Source Code. |
| 12 | + * |
| 13 | + *****************************************************************************/ |
| 14 | +// Includes from this component |
| 15 | +#include "humidity_control_cluster_server.h" |
| 16 | + |
| 17 | +// Includes from Unify |
| 18 | +#include "sl_log.h" |
| 19 | +#include "sl_status.h" |
| 20 | +#include "attribute_store_helper.h" |
| 21 | +#include "zpc_attribute_store_network_helper.h" |
| 22 | +#include "zwave_command_class_humidity_control_types.h" |
| 23 | + |
| 24 | +#include "attribute_store_defined_attribute_types.h" |
| 25 | +#include "unify_dotdot_defined_attribute_types.h" |
| 26 | +#include "unify_dotdot_attribute_store.h" |
| 27 | +#include "unify_dotdot_attribute_store_node_state.h" |
| 28 | + |
| 29 | +// Includes from auto-generated files |
| 30 | +#include "dotdot_mqtt.h" |
| 31 | + |
| 32 | +// Setup Log ID |
| 33 | +#define LOG_TAG "unify_humidity_control_cluster_server" |
| 34 | + |
| 35 | +sl_status_t unify_humidity_control_mode_set( |
| 36 | + dotdot_unid_t unid, |
| 37 | + dotdot_endpoint_id_t endpoint, |
| 38 | + uic_mqtt_dotdot_callback_call_type_t call_type, |
| 39 | + ModeType mode) |
| 40 | +{ |
| 41 | + attribute_store_node_t endpoint_node |
| 42 | + = attribute_store_network_helper_get_endpoint_node(unid, endpoint); |
| 43 | + |
| 44 | + attribute_store_node_t current_mode_node |
| 45 | + = attribute_store_get_first_child_by_type( |
| 46 | + endpoint_node, |
| 47 | + ATTRIBUTE_COMMAND_CLASS_HUMIDITY_CONTROL_MODE_CURRENT_MODE); |
| 48 | + |
| 49 | + // First check the call type. If this is a support check support call, |
| 50 | + // we check the attributes |
| 51 | + if (call_type == UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK) { |
| 52 | + // Check user option automatic_deduction_of_supported_commands |
| 53 | + return attribute_store_node_exists(current_mode_node) ? SL_STATUS_OK |
| 54 | + : SL_STATUS_FAIL; |
| 55 | + } |
| 56 | + |
| 57 | + humidity_control_mode_t mode_value = mode; |
| 58 | + return attribute_store_set_desired(current_mode_node, |
| 59 | + &mode_value, |
| 60 | + sizeof(mode_value)); |
| 61 | +} |
| 62 | + |
| 63 | +sl_status_t unify_humidity_control_setpoint_set( |
| 64 | + dotdot_unid_t unid, |
| 65 | + dotdot_endpoint_id_t endpoint, |
| 66 | + uic_mqtt_dotdot_callback_call_type_t call_type, |
| 67 | + SetpointType type, |
| 68 | + uint8_t precision, |
| 69 | + uint8_t scale, |
| 70 | + int32_t value) |
| 71 | +{ |
| 72 | + // First check the call type. This command have too many requirements |
| 73 | + // so we support it by default |
| 74 | + if (call_type == UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK) { |
| 75 | + return SL_STATUS_OK; |
| 76 | + } |
| 77 | + |
| 78 | + attribute_store_node_t endpoint_node |
| 79 | + = attribute_store_network_helper_get_endpoint_node(unid, endpoint); |
| 80 | + |
| 81 | + humidity_control_setpoint_type_t setpoint_type = type; |
| 82 | + |
| 83 | + attribute_store_node_t setpoint_type_node |
| 84 | + = attribute_store_get_node_child_by_value( |
| 85 | + endpoint_node, |
| 86 | + ATTRIBUTE_COMMAND_CLASS_HUMIDITY_CONTROL_SETPOINT_TYPE, |
| 87 | + REPORTED_ATTRIBUTE, |
| 88 | + &setpoint_type, |
| 89 | + sizeof(setpoint_type), |
| 90 | + 0); |
| 91 | + |
| 92 | + if (setpoint_type == ATTRIBUTE_STORE_INVALID_NODE) { |
| 93 | + sl_log_warning(LOG_TAG, |
| 94 | + "Can't find humidity setpoint type %d", |
| 95 | + setpoint_type); |
| 96 | + return SL_STATUS_FAIL; |
| 97 | + } |
| 98 | + |
| 99 | + attribute_store_set_child_reported( |
| 100 | + setpoint_type_node, |
| 101 | + ATTRIBUTE_COMMAND_CLASS_HUMIDITY_CONTROL_SETPOINT_VALUE_PRECISION, |
| 102 | + &precision, |
| 103 | + sizeof(precision)); |
| 104 | + |
| 105 | + attribute_store_set_child_reported( |
| 106 | + setpoint_type_node, |
| 107 | + ATTRIBUTE_COMMAND_CLASS_HUMIDITY_CONTROL_SETPOINT_VALUE_SCALE, |
| 108 | + &scale, |
| 109 | + sizeof(scale)); |
| 110 | + |
| 111 | + return attribute_store_set_child_desired( |
| 112 | + setpoint_type_node, |
| 113 | + ATTRIBUTE_COMMAND_CLASS_HUMIDITY_CONTROL_SETPOINT_VALUE, |
| 114 | + &value, |
| 115 | + sizeof(value)); |
| 116 | +} |
| 117 | + |
| 118 | +/////////////////////////////////////////////////////////////////////////////// |
| 119 | +// Init and teardown functions |
| 120 | +/////////////////////////////////////////////////////////////////////////////// |
| 121 | +sl_status_t humidity_control_cluster_server_init() |
| 122 | +{ |
| 123 | + sl_log_debug(LOG_TAG, "Humidity Control cluster (ZWave) server initialization"); |
| 124 | + |
| 125 | + // Listen to the BASIC Value attribute is created |
| 126 | + uic_mqtt_dotdot_unify_humidity_control_mode_set_callback_set( |
| 127 | + &unify_humidity_control_mode_set); |
| 128 | + |
| 129 | + uic_mqtt_dotdot_unify_humidity_control_setpoint_set_callback_set( |
| 130 | + &unify_humidity_control_setpoint_set); |
| 131 | + |
| 132 | + return SL_STATUS_OK; |
| 133 | +} |
0 commit comments