Skip to content

Commit

Permalink
SiliconLabsGH-46: Humidity Control Operating State CC
Browse files Browse the repository at this point in the history
ZPC implementation only
Fix documentation

Forwarded: SiliconLabs#46
Bug-SiliconLabs: UIC-3068
Bug-Github: SiliconLabs#46
  • Loading branch information
silabs-borisl committed May 21, 2024
1 parent a3f6881 commit ebe51f1
Show file tree
Hide file tree
Showing 8 changed files with 425 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,17 @@ DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_HUMIDITY_CONTROL_MODE_SUPPORTED_MODES,
DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_HUMIDITY_CONTROL_MODE_CURRENT_MODE,
((COMMAND_CLASS_HUMIDITY_CONTROL_MODE << 8) | 0x03))

/////////////////////////////////////////////////
// Humidity Control Operating State Command Class
///< This represents the version of the Humidity Control Mode Command class.
/// zwave_cc_version_t
DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_HUMIDITY_CONTROL_OPERATING_STATE_VERSION,
ZWAVE_CC_VERSION_ATTRIBUTE(COMMAND_CLASS_HUMIDITY_CONTROL_OPERATING_STATE))

// Current state
DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_HUMIDITY_CONTROL_OPERATING_STATE_CURRENT_STATE,
((COMMAND_CLASS_HUMIDITY_CONTROL_OPERATING_STATE << 8) | 0x02))

/////////////////////////////////////////////////
// Inclusion Controller Command Class
///< This represents the version of the Inclusion Controller Command class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ typedef uint8_t humidity_control_mode_t;
///> Humidity Control Suppoted Mode Bitmask. uint8_t
typedef uint8_t humidity_control_supported_modes_t;

//>> Humidity Control Operating State CC
///> Humidity Control Operating State. uint8_t
typedef uint8_t humidity_control_operating_state_t;

#ifdef __cplusplus
extern "C" {
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ static const std::vector<attribute_schema_t> attribute_schema = {
{ATTRIBUTE_COMMAND_CLASS_HUMIDITY_CONTROL_MODE_SUPPORTED_MODES, "Humidity Control Mode Supported Modes", ATTRIBUTE_ENDPOINT_ID, U8_STORAGE_TYPE},
{ATTRIBUTE_COMMAND_CLASS_HUMIDITY_CONTROL_MODE_CURRENT_MODE, "Humidity Control Mode Current Mode", ATTRIBUTE_INDICATOR_INDICATOR_ID, U8_STORAGE_TYPE},

/////////////////////////////////////////////////////////////////////
// Humidity Control Operating State Command Class attributes
/////////////////////////////////////////////////////////////////////
{ATTRIBUTE_COMMAND_CLASS_HUMIDITY_CONTROL_OPERATING_STATE_VERSION, "Humidity Control Operating State Version", ATTRIBUTE_ENDPOINT_ID, U8_STORAGE_TYPE},
{ATTRIBUTE_COMMAND_CLASS_HUMIDITY_CONTROL_OPERATING_STATE_CURRENT_STATE, "Humidity Control Operating State Current State", ATTRIBUTE_INDICATOR_INDICATOR_ID, U8_STORAGE_TYPE},

/////////////////////////////////////////////////////////////////////
// Meter Command Class attributes
/////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ add_library(
src/zwave_command_class_door_lock_control.cpp
src/zwave_command_class_firmware_update.c
src/zwave_command_class_humidity_control_mode.c
src/zwave_command_class_humidity_control_operating_state.c
src/zwave_command_class_indicator.c
src/zwave_command_class_indicator_control.cpp
src/zwave_command_class_manufacturer_specific.c
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@

/******************************************************************************
* # 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.
*
*****************************************************************************/

// System
#include <stdlib.h>

#include "zwave_command_class_humidity_control_operating_state.h"
#include "zwave_command_class_humidity_control_types.h"
#include "zwave_command_classes_utils.h"
#include "ZW_classcmd.h"

// Includes from other ZPC Components
#include "zwave_command_class_indices.h"
#include "zwave_command_handler.h"
#include "zwave_command_class_version_types.h"
#include "zpc_attribute_store_network_helper.h"
#include "attribute_store_defined_attribute_types.h"

// Unify
#include "attribute_resolver.h"
#include "attribute_store.h"
#include "attribute_store_helper.h"
#include "sl_log.h"

#define LOG_TAG "zwave_command_class_humidity_control_operating_state"

/////////////////////////////////////////////////////////////////////////////
// Version & Attribute Creation
/////////////////////////////////////////////////////////////////////////////
static void
zwave_command_class_humidity_control_operating_state_on_version_attribute_update(
attribute_store_node_t updated_node, attribute_store_change_t change)
{
if (change == ATTRIBUTE_DELETED) {
return;
}

zwave_cc_version_t version = 0;
attribute_store_get_reported(updated_node, &version, sizeof(version));

if (version == 0) {
return;
}

attribute_store_node_t endpoint_node
= attribute_store_get_first_parent_with_type(updated_node,
ATTRIBUTE_ENDPOINT_ID);

// The order of the attribute matter since it defines the order of the
// Z-Wave get command order.
const attribute_store_type_t attributes[]
= {ATTRIBUTE_COMMAND_CLASS_HUMIDITY_CONTROL_OPERATING_STATE_CURRENT_STATE};

attribute_store_add_if_missing(endpoint_node,
attributes,
COUNT_OF(attributes));
}

/////////////////////////////////////////////////////////////////////////////
// Humidity Control Operating State State Get/Report
/////////////////////////////////////////////////////////////////////////////

static sl_status_t zwave_command_class_humidity_control_operating_state_get(
attribute_store_node_t node, uint8_t *frame, uint16_t *frame_length)
{
(void)node; // unused.
ZW_HUMIDITY_CONTROL_OPERATING_STATE_GET_FRAME *get_frame
= (ZW_HUMIDITY_CONTROL_OPERATING_STATE_GET_FRAME *)frame;
get_frame->cmdClass = COMMAND_CLASS_HUMIDITY_CONTROL_OPERATING_STATE;
get_frame->cmd = HUMIDITY_CONTROL_OPERATING_STATE_GET;
*frame_length = sizeof(ZW_HUMIDITY_CONTROL_OPERATING_STATE_GET_FRAME);
return SL_STATUS_OK;
}

sl_status_t zwave_command_class_humidity_control_operating_state_handle_report(
const zwave_controller_connection_info_t *connection_info,
const uint8_t *frame_data,
uint16_t frame_length)
{
if (frame_length < 3) {
return SL_STATUS_FAIL;
}

humidity_control_operating_state_t fan_state
= frame_data[2]
& HUMIDITY_CONTROL_OPERATING_STATE_REPORT_PROPERTIES1_OPERATING_STATE_MASK;

attribute_store_node_t endpoint_node
= zwave_command_class_get_endpoint_node(connection_info);

attribute_store_set_child_reported(
endpoint_node,
ATTRIBUTE_COMMAND_CLASS_HUMIDITY_CONTROL_OPERATING_STATE_CURRENT_STATE,
&fan_state,
sizeof(fan_state));

return SL_STATUS_OK;
}

sl_status_t
zwave_command_class_humidity_control_operating_state_control_handler(
const zwave_controller_connection_info_t *connection_info,
const uint8_t *frame_data,
uint16_t frame_length)
{
if (frame_length <= COMMAND_INDEX) {
return SL_STATUS_NOT_SUPPORTED;
}

switch (frame_data[COMMAND_INDEX]) {
case HUMIDITY_CONTROL_OPERATING_STATE_REPORT:
return zwave_command_class_humidity_control_operating_state_handle_report(
connection_info,
frame_data,
frame_length);
default:
return SL_STATUS_NOT_SUPPORTED;
}
}

sl_status_t zwave_command_class_humidity_control_operating_state_init()
{
attribute_store_register_callback_by_type(
&zwave_command_class_humidity_control_operating_state_on_version_attribute_update,
ATTRIBUTE_COMMAND_CLASS_HUMIDITY_CONTROL_OPERATING_STATE_VERSION);

attribute_resolver_register_rule(
ATTRIBUTE_COMMAND_CLASS_HUMIDITY_CONTROL_OPERATING_STATE_CURRENT_STATE,
NULL,
&zwave_command_class_humidity_control_operating_state_get);

zwave_command_handler_t handler = {};
handler.support_handler = NULL;
handler.control_handler
= zwave_command_class_humidity_control_operating_state_control_handler;
handler.minimal_scheme = ZWAVE_CONTROLLER_ENCAPSULATION_NONE;
handler.manual_security_validation = false;
handler.command_class = COMMAND_CLASS_HUMIDITY_CONTROL_OPERATING_STATE;
handler.version = 1;
handler.command_class_name = "Humidity Control Operating State";
handler.comments = "Experimental";

return zwave_command_handler_register_handler(handler);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

/******************************************************************************
* # 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 zwave_command_class_humidity_control_operating_state
* @brief Humidity Control Operating State Command Class handlers and control function
*
* This module implement some of the functions to control the
* Humidity Control Operating State Command Class
*
* @{
*/

#ifndef ZWAVE_COMMAND_CLASS_HUMIDITY_CONTROL_OPERATING_STATE_H
#define ZWAVE_COMMAND_CLASS_HUMIDITY_CONTROL_OPERATING_STATE_H

#include "sl_status.h"

#ifdef __cplusplus
extern "C" {
#endif

sl_status_t zwave_command_class_humidity_control_operating_state_init();

#ifdef __cplusplus
}
#endif

#endif //ZWAVE_COMMAND_CLASS_HUMIDITY_CONTROL_OPERATING_STATE_H
/** @} end zwave_command_class_humidity_control_operating_state */
Original file line number Diff line number Diff line change
Expand Up @@ -742,5 +742,20 @@ target_add_unittest(
zpc_attribute_resolver_mock
uic_dotdot_mqtt_mock)

# Humidity Control Mode test
target_add_unittest(
zwave_command_classes
NAME
zwave_command_class_humidity_control_operating_state_test
SOURCES
zwave_command_class_humidity_control_operating_state_test.c
DEPENDS
zpc_attribute_store_test_helper
zwave_controller
zwave_command_handler_mock
uic_attribute_resolver_mock
zpc_attribute_resolver_mock
uic_dotdot_mqtt_mock)



Loading

0 comments on commit ebe51f1

Please sign in to comment.