Skip to content

Commit 518d63c

Browse files
committed
GH-33 : Fan Control Commands
Forwarded: #33 Bug-SiliconLabs: UIC-3042 Bug-Github: #33
1 parent 5c9fd87 commit 518d63c

File tree

11 files changed

+290
-0
lines changed

11 files changed

+290
-0
lines changed

applications/zpc/components/zcl_cluster_servers/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ add_library(
99
zcl_cluster_servers
1010
src/configuration_parameter_cluster_server.cpp
1111
src/user_code_cluster_server.cpp
12+
src/fan_control_cluster_server.c
1213
src/zcl_binding_cluster_server.cpp
1314
src/zcl_cluster_servers.cpp
1415
src/zcl_cluster_servers_helpers.cpp
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
2+
/******************************************************************************
3+
* # License
4+
* <b>Copyright 2021 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 "fan_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_thermostat_fan_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 "fan_control_cluster_server"
34+
35+
sl_status_t
36+
zwave_fan_control_turn_off(dotdot_unid_t unid,
37+
dotdot_endpoint_id_t endpoint,
38+
uic_mqtt_dotdot_callback_call_type_t call_type)
39+
{
40+
attribute_store_node_t endpoint_node
41+
= attribute_store_network_helper_get_endpoint_node(unid, endpoint);
42+
43+
attribute_store_node_t off_flag_node
44+
= attribute_store_get_first_child_by_type(
45+
endpoint_node,
46+
ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_FAN_MODE_OFF_FLAG);
47+
48+
// First check the call type. If this is a support check support call,
49+
// we check the attributes
50+
if (call_type == UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK) {
51+
// Check user option automatic_deduction_of_supported_commands
52+
return attribute_store_node_exists(off_flag_node) ? SL_STATUS_OK
53+
: SL_STATUS_FAIL;
54+
}
55+
56+
thermostat_fan_mode_off_flag_t off_flag = 1;
57+
return attribute_store_set_desired(off_flag_node,
58+
&off_flag,
59+
sizeof(off_flag));
60+
}
61+
62+
///////////////////////////////////////////////////////////////////////////////
63+
// Init and teardown functions
64+
///////////////////////////////////////////////////////////////////////////////
65+
sl_status_t fan_control_cluster_server_init()
66+
{
67+
sl_log_debug(LOG_TAG, "FanControl cluster (ZWave) server initialization");
68+
69+
// Listen to the BASIC Value attribute is created
70+
uic_mqtt_dotdot_unify_fan_control_turn_off_callback_set(
71+
&zwave_fan_control_turn_off);
72+
73+
return SL_STATUS_OK;
74+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
/**
15+
* @defgroup zpc_on_off_cluster_mapper ZPC Fan Control
16+
* @ingroup dotdot_mapper
17+
* @brief Maps OnOff Cluster incoming Commands to attribute modifications.
18+
*
19+
* @{
20+
*/
21+
22+
#ifndef FAN_CONTROL_CLUSTER_SERVER_H
23+
#define FAN_CONTROL_CLUSTER_SERVER_H
24+
25+
// Generic includes
26+
#include "sl_status.h"
27+
28+
#ifdef __cplusplus
29+
extern "C" {
30+
#endif
31+
32+
/**
33+
* @brief Initialize the FanControl cluster server
34+
*
35+
* @returns true on success
36+
* @returns false on failure
37+
*
38+
*/
39+
sl_status_t fan_control_cluster_server_init(void);
40+
41+
#ifdef __cplusplus
42+
}
43+
#endif
44+
45+
#endif //FAN_CONTROL_CLUSTER_SERVER_H
46+
/** @} end fan_control_cluster_server */

applications/zpc/components/zcl_cluster_servers/src/zcl_cluster_servers.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "zcl_scenes_cluster_server.h"
1919
#include "zcl_OTA_cluster_server.hpp"
2020
#include "user_code_cluster_server.h"
21+
#include "fan_control_cluster_server.h"
2122

2223
//Includes from other components
2324
#include "attribute_store.h"
@@ -40,6 +41,8 @@ sl_status_t zcl_cluster_servers_init()
4041
init_status |= binding_cluster_server_init();
4142
init_status |= zcl_scenes_cluster_server_init();
4243
init_status |= user_code_cluster_server_init();
44+
init_status |= fan_control_cluster_server_init();
45+
4346
return init_status;
4447
}
4548

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ target_include_directories(zcl_OTA_cluster_server_test PRIVATE ../src)
3636
# zwave_api_mock
3737
# zwave_api_transport_mock)
3838

39+
# FanControl Cluster Mapper test
40+
target_add_unittest(
41+
zcl_cluster_servers
42+
NAME
43+
fan_control_cluster_server_test
44+
SOURCES
45+
fan_control_cluster_server_test.c
46+
DEPENDS
47+
zpc_attribute_store_test_helper
48+
uic_dotdot_mqtt_mock
49+
unify_dotdot_attribute_store)
50+
3951
# Configuration Parameter Cluster Server test
4052
target_add_unittest(
4153
zcl_cluster_servers
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/******************************************************************************
2+
* # License
3+
* <b>Copyright 2022 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+
#include "fan_control_cluster_server.h"
14+
#include "unify_dotdot_attribute_store.h"
15+
#include "unity.h"
16+
17+
// Unify components
18+
#include "datastore.h"
19+
#include "attribute_store_fixt.h"
20+
#include "attribute_store_helper.h"
21+
#include "unify_dotdot_defined_attribute_types.h"
22+
#include "dotdot_mqtt_mock.h"
23+
24+
// ZPC Components
25+
#include "zwave_unid.h"
26+
#include "zwave_command_class_thermostat_fan_types.h"
27+
28+
// Test helpers
29+
#include "zpc_attribute_store_test_helper.h"
30+
#include "attribute_store_defined_attribute_types.h"
31+
32+
uic_mqtt_dotdot_unify_fan_control_turn_off_callback_t
33+
uic_mqtt_dotdot_fan_control_turn_off_callback;
34+
35+
void uic_mqtt_dotdot_fan_control_turn_off_callback_set_stub(
36+
const uic_mqtt_dotdot_unify_fan_control_turn_off_callback_t callback,
37+
int cmock_num_calls)
38+
{
39+
uic_mqtt_dotdot_fan_control_turn_off_callback = callback;
40+
}
41+
42+
/// Setup the test suite (called once before all test_xxx functions are called)
43+
void suiteSetUp()
44+
{
45+
datastore_init(":memory:");
46+
attribute_store_init();
47+
}
48+
49+
/// Teardown the test suite (called once after all test_xxx functions are called)
50+
int suiteTearDown(int num_failures)
51+
{
52+
attribute_store_teardown();
53+
datastore_teardown();
54+
return num_failures;
55+
}
56+
57+
/// Called before each and every test
58+
void setUp()
59+
{
60+
zpc_attribute_store_test_helper_create_network();
61+
uic_mqtt_dotdot_unify_fan_control_turn_off_callback_set_Stub(
62+
&uic_mqtt_dotdot_fan_control_turn_off_callback_set_stub);
63+
64+
// Call init
65+
TEST_ASSERT_EQUAL(SL_STATUS_OK, fan_control_cluster_server_init());
66+
}
67+
68+
/// Called after each and every test
69+
void tearDown()
70+
{
71+
attribute_store_delete_node(attribute_store_get_root());
72+
}
73+
74+
void test_fan_control_command_mapping()
75+
{
76+
TEST_ASSERT_NOT_NULL(uic_mqtt_dotdot_fan_control_turn_off_callback);
77+
78+
TEST_ASSERT_EQUAL(SL_STATUS_FAIL,
79+
uic_mqtt_dotdot_fan_control_turn_off_callback(
80+
supporting_node_unid,
81+
endpoint_id,
82+
UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK));
83+
84+
attribute_store_node_t off_node = attribute_store_add_node(
85+
ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_FAN_MODE_OFF_FLAG,
86+
endpoint_id_node);
87+
88+
// test support
89+
TEST_ASSERT_EQUAL(SL_STATUS_OK,
90+
uic_mqtt_dotdot_fan_control_turn_off_callback(
91+
supporting_node_unid,
92+
endpoint_id,
93+
UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK));
94+
// Test callback
95+
TEST_ASSERT_EQUAL(SL_STATUS_OK,
96+
uic_mqtt_dotdot_fan_control_turn_off_callback(
97+
supporting_node_unid,
98+
endpoint_id,
99+
UIC_MQTT_DOTDOT_CALLBACK_TYPE_NORMAL));
100+
101+
thermostat_fan_mode_off_flag_t off_flag = 0;
102+
103+
TEST_ASSERT_EQUAL_MESSAGE(
104+
SL_STATUS_OK,
105+
attribute_store_get_desired(off_node, &off_flag, sizeof(off_flag)),
106+
"Can't get Off flag value");
107+
108+
// Test value
109+
TEST_ASSERT_EQUAL(1, off_flag);
110+
}

components/unify_dotdot_attribute_store/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ add_library(
1515
src/unify_dotdot_attribute_store_command_callbacks_poll_control.c
1616
src/unify_dotdot_attribute_store_command_callbacks_thermostat.c
1717
src/unify_dotdot_attribute_store_command_callbacks_window_covering.c
18+
src/unify_dotdot_attribute_store_command_callbacks_zwave_fan_control.c
1819
src/unify_dotdot_attribute_store_node_state.cpp
1920
src/unify_dotdot_attribute_store_group_cluster.cpp
2021
src/unify_dotdot_attribute_store_descriptor.cpp

components/unify_dotdot_attribute_store/src/unify_dotdot_attribute_store_command_callbacks.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "unify_dotdot_attribute_store_command_callbacks_poll_control.h"
2121
#include "unify_dotdot_attribute_store_command_callbacks_thermostat.h"
2222
#include "unify_dotdot_attribute_store_command_callbacks_window_covering.h"
23+
#include "unify_dotdot_attribute_store_command_callbacks_zwave_fan_control.h"
2324
#include "unify_dotdot_attribute_store_configuration.h"
2425
#include "unify_dotdot_attribute_store_helpers.h"
2526
#include "unify_dotdot_defined_attribute_types.h"
@@ -45,5 +46,7 @@ sl_status_t unify_dotdot_attribute_store_command_callbacks_init()
4546
thermostat_cluster_mapper_init();
4647
window_covering_cluster_mapper_init();
4748

49+
zwave_fan_control_cluster_mapper_init();
50+
4851
return SL_STATUS_OK;
4952
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 ZWAVE_FAN_CONTROL_CLUSTER_MAPPER_H
15+
#define ZWAVE_FAN_CONTROL_CLUSTER_MAPPER_H
16+
17+
// Generic includes
18+
#include <stdbool.h>
19+
20+
#ifdef __cplusplus
21+
extern "C" {
22+
#endif
23+
24+
/**
25+
* @brief Initialize the Zwave Fan Control cluster mapper
26+
*
27+
*/
28+
void zwave_fan_control_cluster_mapper_init(void);
29+
30+
#ifdef __cplusplus
31+
}
32+
#endif
33+
34+
#endif //ZWAVE_FAN_CONTROL_CLUSTER_MAPPER_H
35+
/** @} end unify_cluster_mapper */

components/unify_dotdot_attribute_store/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ target_add_unittest(
2323
unify_dotdot_attribute_store_command_mapper_poll_control_test.c
2424
unify_dotdot_attribute_store_command_mapper_thermostat_test.c
2525
unify_dotdot_attribute_store_command_mapper_window_covering_test.c
26+
unify_dotdot_attribute_store_command_mapper_zwave_fan_control_test.c
2627

2728
DEPENDS
2829
uic_dotdot_mqtt_mock

0 commit comments

Comments
 (0)