Skip to content

Commit b3a99f2

Browse files
committed
SiliconLabsGH-46: Custom Humidity Control cluster
Forwarded: SiliconLabs#46 Bug-SiliconLabs: UIC-3042 Bug-Github: SiliconLabs#46
1 parent 4d6f50d commit b3a99f2

File tree

7 files changed

+532
-2
lines changed

7 files changed

+532
-2
lines changed

applications/zpc/components/zcl_cluster_servers/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ add_library(
1414
src/zcl_cluster_servers_helpers.cpp
1515
src/zcl_OTA_cluster_server.cpp
1616
src/zcl_rf_telemetry_cluster_server.c
17-
src/zcl_scenes_cluster_server.cpp)
17+
src/zcl_scenes_cluster_server.cpp
18+
src/humidity_control_cluster_server.c
19+
)
1820

1921
target_include_directories(
2022
zcl_cluster_servers
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/******************************************************************************
2+
* # License
3+
* <b>Copyright 2024 Silicon Laboratories Inc. www.silabs.com</b>
4+
******************************************************************************
5+
* The licensor of this software is Silicon Laboratories Inc. Your use of this
6+
* software is governed by the terms of Silicon Labs Master Software License
7+
* Agreement (MSLA) available at
8+
* www.silabs.com/about-us/legal/master-software-license-agreement. This
9+
* software is distributed to you in Source Code format and is governed by the
10+
* sections of the MSLA applicable to Source Code.
11+
*
12+
*****************************************************************************/
13+
14+
#ifndef HUMIDITY_CONTROL_CLUSTER_SERVER_H
15+
#define HUMIDITY_CONTROL_CLUSTER_SERVER_H
16+
17+
// Generic includes
18+
#include "sl_status.h"
19+
20+
#ifdef __cplusplus
21+
extern "C" {
22+
#endif
23+
24+
/**
25+
* @brief Initialize the FanControl cluster server
26+
*
27+
* @returns true on success
28+
* @returns false on failure
29+
*
30+
*/
31+
sl_status_t humidity_control_cluster_server_init(void);
32+
33+
#ifdef __cplusplus
34+
}
35+
#endif
36+
37+
#endif //HUMIDITY_CONTROL_CLUSTER_SERVER_H
38+
/** @} end humidity_control_cluster_server */

applications/zpc/components/zcl_cluster_servers/test/CMakeLists.txt

+13-1
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,16 @@ target_add_unittest(
102102
zcl_cluster_servers_fixture_test.c
103103
DEPENDS
104104
unify
105-
zpc_config_mock)
105+
zpc_config_mock)
106+
107+
# Humidity Control Cluster Mapper test
108+
target_add_unittest(
109+
zcl_cluster_servers
110+
NAME
111+
humidity_control_cluster_server_test
112+
SOURCES
113+
humidity_control_cluster_server_test.c
114+
DEPENDS
115+
zpc_attribute_store_test_helper
116+
uic_dotdot_mqtt_mock
117+
unify_dotdot_attribute_store)

0 commit comments

Comments
 (0)