Skip to content

Commit

Permalink
GH-33 : Fan Control Commands
Browse files Browse the repository at this point in the history
Forwarded: #33
Bug-SiliconLabs: UIC-3042
Bug-Github: #33
  • Loading branch information
silabs-borisl committed May 16, 2024
1 parent 5c9fd87 commit 518d63c
Show file tree
Hide file tree
Showing 11 changed files with 290 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ add_library(
zcl_cluster_servers
src/configuration_parameter_cluster_server.cpp
src/user_code_cluster_server.cpp
src/fan_control_cluster_server.c
src/zcl_binding_cluster_server.cpp
src/zcl_cluster_servers.cpp
src/zcl_cluster_servers_helpers.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@

/******************************************************************************
* # License
* <b>Copyright 2021 Silicon Laboratories Inc. www.silabs.com</b>
******************************************************************************
* The licensor of this software is Silicon Laboratories Inc. Your use of this
* software is governed by the terms of Silicon Labs Master Software License
* Agreement (MSLA) available at
* www.silabs.com/about-us/legal/master-software-license-agreement. This
* software is distributed to you in Source Code format and is governed by the
* sections of the MSLA applicable to Source Code.
*
*****************************************************************************/
// Includes from this component
#include "fan_control_cluster_server.h"

// Includes from Unify
#include "sl_log.h"
#include "sl_status.h"
#include "attribute_store_helper.h"
#include "zpc_attribute_store_network_helper.h"
#include "zwave_command_class_thermostat_fan_types.h"

#include "attribute_store_defined_attribute_types.h"
#include "unify_dotdot_defined_attribute_types.h"
#include "unify_dotdot_attribute_store.h"
#include "unify_dotdot_attribute_store_node_state.h"

// Includes from auto-generated files
#include "dotdot_mqtt.h"

// Setup Log ID
#define LOG_TAG "fan_control_cluster_server"

sl_status_t
zwave_fan_control_turn_off(dotdot_unid_t unid,
dotdot_endpoint_id_t endpoint,
uic_mqtt_dotdot_callback_call_type_t call_type)
{
attribute_store_node_t endpoint_node
= attribute_store_network_helper_get_endpoint_node(unid, endpoint);

attribute_store_node_t off_flag_node
= attribute_store_get_first_child_by_type(
endpoint_node,
ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_FAN_MODE_OFF_FLAG);

// First check the call type. If this is a support check support call,
// we check the attributes
if (call_type == UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK) {
// Check user option automatic_deduction_of_supported_commands
return attribute_store_node_exists(off_flag_node) ? SL_STATUS_OK
: SL_STATUS_FAIL;
}

thermostat_fan_mode_off_flag_t off_flag = 1;
return attribute_store_set_desired(off_flag_node,
&off_flag,
sizeof(off_flag));
}

///////////////////////////////////////////////////////////////////////////////
// Init and teardown functions
///////////////////////////////////////////////////////////////////////////////
sl_status_t fan_control_cluster_server_init()
{
sl_log_debug(LOG_TAG, "FanControl cluster (ZWave) server initialization");

// Listen to the BASIC Value attribute is created
uic_mqtt_dotdot_unify_fan_control_turn_off_callback_set(
&zwave_fan_control_turn_off);

return SL_STATUS_OK;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/******************************************************************************
* # License
* <b>Copyright 2024 Silicon Laboratories Inc. www.silabs.com</b>
******************************************************************************
* The licensor of this software is Silicon Laboratories Inc. Your use of this
* software is governed by the terms of Silicon Labs Master Software License
* Agreement (MSLA) available at
* www.silabs.com/about-us/legal/master-software-license-agreement. This
* software is distributed to you in Source Code format and is governed by the
* sections of the MSLA applicable to Source Code.
*
*****************************************************************************/

/**
* @defgroup zpc_on_off_cluster_mapper ZPC Fan Control
* @ingroup dotdot_mapper
* @brief Maps OnOff Cluster incoming Commands to attribute modifications.
*
* @{
*/

#ifndef FAN_CONTROL_CLUSTER_SERVER_H
#define FAN_CONTROL_CLUSTER_SERVER_H

// Generic includes
#include "sl_status.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Initialize the FanControl cluster server
*
* @returns true on success
* @returns false on failure
*
*/
sl_status_t fan_control_cluster_server_init(void);

#ifdef __cplusplus
}
#endif

#endif //FAN_CONTROL_CLUSTER_SERVER_H
/** @} end fan_control_cluster_server */
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "zcl_scenes_cluster_server.h"
#include "zcl_OTA_cluster_server.hpp"
#include "user_code_cluster_server.h"
#include "fan_control_cluster_server.h"

//Includes from other components
#include "attribute_store.h"
Expand All @@ -40,6 +41,8 @@ sl_status_t zcl_cluster_servers_init()
init_status |= binding_cluster_server_init();
init_status |= zcl_scenes_cluster_server_init();
init_status |= user_code_cluster_server_init();
init_status |= fan_control_cluster_server_init();

return init_status;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ target_include_directories(zcl_OTA_cluster_server_test PRIVATE ../src)
# zwave_api_mock
# zwave_api_transport_mock)

# FanControl Cluster Mapper test
target_add_unittest(
zcl_cluster_servers
NAME
fan_control_cluster_server_test
SOURCES
fan_control_cluster_server_test.c
DEPENDS
zpc_attribute_store_test_helper
uic_dotdot_mqtt_mock
unify_dotdot_attribute_store)

# Configuration Parameter Cluster Server test
target_add_unittest(
zcl_cluster_servers
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/******************************************************************************
* # License
* <b>Copyright 2022 Silicon Laboratories Inc. www.silabs.com</b>
******************************************************************************
* The licensor of this software is Silicon Laboratories Inc. Your use of this
* software is governed by the terms of Silicon Labs Master Software License
* Agreement (MSLA) available at
* www.silabs.com/about-us/legal/master-software-license-agreement. This
* software is distributed to you in Source Code format and is governed by the
* sections of the MSLA applicable to Source Code.
*
*****************************************************************************/
#include "fan_control_cluster_server.h"
#include "unify_dotdot_attribute_store.h"
#include "unity.h"

// Unify components
#include "datastore.h"
#include "attribute_store_fixt.h"
#include "attribute_store_helper.h"
#include "unify_dotdot_defined_attribute_types.h"
#include "dotdot_mqtt_mock.h"

// ZPC Components
#include "zwave_unid.h"
#include "zwave_command_class_thermostat_fan_types.h"

// Test helpers
#include "zpc_attribute_store_test_helper.h"
#include "attribute_store_defined_attribute_types.h"

uic_mqtt_dotdot_unify_fan_control_turn_off_callback_t
uic_mqtt_dotdot_fan_control_turn_off_callback;

void uic_mqtt_dotdot_fan_control_turn_off_callback_set_stub(
const uic_mqtt_dotdot_unify_fan_control_turn_off_callback_t callback,
int cmock_num_calls)
{
uic_mqtt_dotdot_fan_control_turn_off_callback = callback;
}

/// Setup the test suite (called once before all test_xxx functions are called)
void suiteSetUp()
{
datastore_init(":memory:");
attribute_store_init();
}

/// Teardown the test suite (called once after all test_xxx functions are called)
int suiteTearDown(int num_failures)
{
attribute_store_teardown();
datastore_teardown();
return num_failures;
}

/// Called before each and every test
void setUp()
{
zpc_attribute_store_test_helper_create_network();
uic_mqtt_dotdot_unify_fan_control_turn_off_callback_set_Stub(
&uic_mqtt_dotdot_fan_control_turn_off_callback_set_stub);

// Call init
TEST_ASSERT_EQUAL(SL_STATUS_OK, fan_control_cluster_server_init());
}

/// Called after each and every test
void tearDown()
{
attribute_store_delete_node(attribute_store_get_root());
}

void test_fan_control_command_mapping()
{
TEST_ASSERT_NOT_NULL(uic_mqtt_dotdot_fan_control_turn_off_callback);

TEST_ASSERT_EQUAL(SL_STATUS_FAIL,
uic_mqtt_dotdot_fan_control_turn_off_callback(
supporting_node_unid,
endpoint_id,
UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK));

attribute_store_node_t off_node = attribute_store_add_node(
ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_FAN_MODE_OFF_FLAG,
endpoint_id_node);

// test support
TEST_ASSERT_EQUAL(SL_STATUS_OK,
uic_mqtt_dotdot_fan_control_turn_off_callback(
supporting_node_unid,
endpoint_id,
UIC_MQTT_DOTDOT_CALLBACK_TYPE_SUPPORT_CHECK));
// Test callback
TEST_ASSERT_EQUAL(SL_STATUS_OK,
uic_mqtt_dotdot_fan_control_turn_off_callback(
supporting_node_unid,
endpoint_id,
UIC_MQTT_DOTDOT_CALLBACK_TYPE_NORMAL));

thermostat_fan_mode_off_flag_t off_flag = 0;

TEST_ASSERT_EQUAL_MESSAGE(
SL_STATUS_OK,
attribute_store_get_desired(off_node, &off_flag, sizeof(off_flag)),
"Can't get Off flag value");

// Test value
TEST_ASSERT_EQUAL(1, off_flag);
}
1 change: 1 addition & 0 deletions components/unify_dotdot_attribute_store/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ add_library(
src/unify_dotdot_attribute_store_command_callbacks_poll_control.c
src/unify_dotdot_attribute_store_command_callbacks_thermostat.c
src/unify_dotdot_attribute_store_command_callbacks_window_covering.c
src/unify_dotdot_attribute_store_command_callbacks_zwave_fan_control.c
src/unify_dotdot_attribute_store_node_state.cpp
src/unify_dotdot_attribute_store_group_cluster.cpp
src/unify_dotdot_attribute_store_descriptor.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "unify_dotdot_attribute_store_command_callbacks_poll_control.h"
#include "unify_dotdot_attribute_store_command_callbacks_thermostat.h"
#include "unify_dotdot_attribute_store_command_callbacks_window_covering.h"
#include "unify_dotdot_attribute_store_command_callbacks_zwave_fan_control.h"
#include "unify_dotdot_attribute_store_configuration.h"
#include "unify_dotdot_attribute_store_helpers.h"
#include "unify_dotdot_defined_attribute_types.h"
Expand All @@ -45,5 +46,7 @@ sl_status_t unify_dotdot_attribute_store_command_callbacks_init()
thermostat_cluster_mapper_init();
window_covering_cluster_mapper_init();

zwave_fan_control_cluster_mapper_init();

return SL_STATUS_OK;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/******************************************************************************
* # License
* <b>Copyright 2024 Silicon Laboratories Inc. www.silabs.com</b>
******************************************************************************
* The licensor of this software is Silicon Laboratories Inc. Your use of this
* software is governed by the terms of Silicon Labs Master Software License
* Agreement (MSLA) available at
* www.silabs.com/about-us/legal/master-software-license-agreement. This
* software is distributed to you in Source Code format and is governed by the
* sections of the MSLA applicable to Source Code.
*
*****************************************************************************/

#ifndef ZWAVE_FAN_CONTROL_CLUSTER_MAPPER_H
#define ZWAVE_FAN_CONTROL_CLUSTER_MAPPER_H

// Generic includes
#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Initialize the Zwave Fan Control cluster mapper
*
*/
void zwave_fan_control_cluster_mapper_init(void);

#ifdef __cplusplus
}
#endif

#endif //ZWAVE_FAN_CONTROL_CLUSTER_MAPPER_H
/** @} end unify_cluster_mapper */
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ target_add_unittest(
unify_dotdot_attribute_store_command_mapper_poll_control_test.c
unify_dotdot_attribute_store_command_mapper_thermostat_test.c
unify_dotdot_attribute_store_command_mapper_window_covering_test.c
unify_dotdot_attribute_store_command_mapper_zwave_fan_control_test.c

DEPENDS
uic_dotdot_mqtt_mock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ void test_window_covering_go_to_lift_value_command();
void test_window_covering_go_to_lift_percentage_command();
void test_window_covering_go_to_tilt_value_command();
void test_window_covering_go_to_tilt_percentage_command();
void test_zwave_fan_control_no_get_endpoint_function_registered();
void test_zwave_fan_control_set_fan_mode_command_support();
void test_zwave_fan_control_set_fan_mode_command_update_desired();
void test_zwave_fan_control_set_fan_mode_command_clear_reported();

/// Setup the test suite (called once before all test_xxx functions are called)
void suiteSetUp()
Expand Down

0 comments on commit 518d63c

Please sign in to comment.