Skip to content

Commit 9b848f1

Browse files
committed
GH-33: Thermostat Fan Control/State Mode CC implementation
Forwarded: #33 Bug-SiliconLabs: UIC-1224 Bug-Github: #33
1 parent 3b43b68 commit 9b848f1

File tree

67 files changed

+5919
-8
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+5919
-8
lines changed

applications/dev_ui/dev_gui/zap-generated/src/cluster-types/cluster-type-attributes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//This file is generated automatically. Don't try to change something here.
22
//To add support for new clusters, modify addon-helper.js
33
//To change the stucture of the ClusterTypeAttrs, modify cluster-type-attributes.zapt
4-
5-
4+
5+
66
//generate ClusterTypes
77
export let ClusterTypeAttrs: any = {
88
Basic: {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
def zwTHERMOSTAT_FAN_MODE_CURRENT_FAN_MODE 0x4402
2+
def zwTHERMOSTAT_FAN_MODE_SUPPORTED_FAN_MODE 0x4403
3+
4+
def zwTHERMOSTAT_FAN_STATE 0x4502
5+
6+
def zbZWAVE_FAN_MODE 0x02020002
7+
def zbZWAVE_SUPPORTED_FAN_MODE 0x02020003
8+
def zbZWAVE_FAN_STATE 0x02020004
9+
10+
def zwave_no_thermostat_fan_mode (e'zwTHERMOSTAT_FAN_MODE_CURRENT_FAN_MODE == 0)
11+
12+
scope 25 chain_reaction(0) {
13+
// Linking attributes zwave -> zigbee
14+
r'zbZWAVE_FAN_MODE =
15+
if (zwave_no_thermostat_fan_mode) undefined
16+
r'zwTHERMOSTAT_FAN_MODE_CURRENT_FAN_MODE
17+
d'zbZWAVE_FAN_MODE =
18+
if (zwave_no_thermostat_fan_mode) undefined
19+
d'zwTHERMOSTAT_FAN_MODE_CURRENT_FAN_MODE
20+
21+
22+
// Linking attributes zigbee -> zwave
23+
r'zwTHERMOSTAT_FAN_MODE_CURRENT_FAN_MODE =
24+
if (zwave_no_thermostat_fan_mode) undefined
25+
r'zbZWAVE_FAN_MODE
26+
d'zwTHERMOSTAT_FAN_MODE_CURRENT_FAN_MODE =
27+
if (zwave_no_thermostat_fan_mode) undefined
28+
d'zbZWAVE_FAN_MODE
29+
30+
// Supported fan mode (read only)
31+
r'zbZWAVE_SUPPORTED_FAN_MODE =
32+
if (zwave_no_thermostat_fan_mode) undefined
33+
r'zwTHERMOSTAT_FAN_MODE_SUPPORTED_FAN_MODE
34+
35+
// Supported state(read only)
36+
r'zbZWAVE_FAN_STATE =
37+
if (zwave_no_thermostat_fan_mode) undefined
38+
r'zwTHERMOSTAT_FAN_STATE
39+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ target_add_unittest(
2727
uic_dotdot_mqtt_mock
2828
zwave_network_management_mock)
2929

30+
3031
# Binding Cluster Mapper Helper test
3132
target_add_unittest(
3233
dotdot_mapper_binding_cluster_helper

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_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_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_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_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+
}

applications/zpc/components/zpc_attribute_store/include/attribute_store_defined_attribute_types.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,31 @@ DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_MAX_VALUE,
691691
DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_MAX_VALUE_SCALE,
692692
((COMMAND_CLASS_THERMOSTAT_SETPOINT << 8) | 0x09))
693693

694+
/////////////////////////////////////////////////
695+
// Thermostat Fan Mode Command Class
696+
/// zwave_cc_version_t
697+
DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_FAN_MODE_VERSION,
698+
ZWAVE_CC_VERSION_ATTRIBUTE(COMMAND_CLASS_THERMOSTAT_FAN_MODE))
699+
/// Current Fan mode
700+
DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_FAN_MODE_CURRENT_MODE,
701+
((COMMAND_CLASS_THERMOSTAT_FAN_MODE << 8) | 0x02))
702+
/// Supported Fans modes
703+
DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_FAN_MODE_SUPPORTED_MODES,
704+
((COMMAND_CLASS_THERMOSTAT_FAN_MODE << 8) | 0x03))
705+
/// Off flag (v2+)
706+
DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_FAN_MODE_OFF_FLAG,
707+
((COMMAND_CLASS_THERMOSTAT_FAN_MODE << 8) | 0x05))
708+
709+
/////////////////////////////////////////////////
710+
// Thermostat Fan State Command Class
711+
/// zwave_cc_version_t
712+
DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_FAN_STATE_VERSION,
713+
ZWAVE_CC_VERSION_ATTRIBUTE(COMMAND_CLASS_THERMOSTAT_FAN_STATE))
714+
/// Current Fan operating state
715+
DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_FAN_STATE_FAN_OPERATING_STATE,
716+
((COMMAND_CLASS_THERMOSTAT_FAN_STATE << 8) | 0x02))
717+
718+
694719
/////////////////////////////////////////////////
695720
// Wakeup command class
696721
DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_WAKE_UP_VERSION,

0 commit comments

Comments
 (0)