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+
15+ // System
16+ #include <stdlib.h>
17+
18+ #include "zwave_command_class_humidity_control_operating_state.h"
19+ #include "zwave_command_class_humidity_control_types.h"
20+ #include "zwave_command_classes_utils.h"
21+ #include "ZW_classcmd.h"
22+
23+ // Includes from other ZPC Components
24+ #include "zwave_command_class_indices.h"
25+ #include "zwave_command_handler.h"
26+ #include "zwave_command_class_version_types.h"
27+ #include "zpc_attribute_store_network_helper.h"
28+ #include "attribute_store_defined_attribute_types.h"
29+
30+ // Unify
31+ #include "attribute_resolver.h"
32+ #include "attribute_store.h"
33+ #include "attribute_store_helper.h"
34+ #include "sl_log.h"
35+
36+ #define LOG_TAG "zwave_command_class_humidity_control_operating_state"
37+
38+ /////////////////////////////////////////////////////////////////////////////
39+ // Version & Attribute Creation
40+ /////////////////////////////////////////////////////////////////////////////
41+ static void
42+ zwave_command_class_humidity_control_operating_state_on_version_attribute_update (
43+ attribute_store_node_t updated_node , attribute_store_change_t change )
44+ {
45+ if (change == ATTRIBUTE_DELETED ) {
46+ return ;
47+ }
48+
49+ zwave_cc_version_t version = 0 ;
50+ attribute_store_get_reported (updated_node , & version , sizeof (version ));
51+
52+ if (version == 0 ) {
53+ return ;
54+ }
55+
56+ attribute_store_node_t endpoint_node
57+ = attribute_store_get_first_parent_with_type (updated_node ,
58+ ATTRIBUTE_ENDPOINT_ID );
59+
60+ // The order of the attribute matter since it defines the order of the
61+ // Z-Wave get command order.
62+ const attribute_store_type_t attributes []
63+ = {ATTRIBUTE_COMMAND_CLASS_HUMIDITY_CONTROL_OPERATING_STATE_CURRENT_STATE };
64+
65+ attribute_store_add_if_missing (endpoint_node ,
66+ attributes ,
67+ COUNT_OF (attributes ));
68+ }
69+
70+ /////////////////////////////////////////////////////////////////////////////
71+ // Humidity Control Operating State State Get/Report
72+ /////////////////////////////////////////////////////////////////////////////
73+
74+ static sl_status_t zwave_command_class_humidity_control_operating_state_get (
75+ attribute_store_node_t node , uint8_t * frame , uint16_t * frame_length )
76+ {
77+ (void )node ; // unused.
78+ ZW_HUMIDITY_CONTROL_OPERATING_STATE_GET_FRAME * get_frame
79+ = (ZW_HUMIDITY_CONTROL_OPERATING_STATE_GET_FRAME * )frame ;
80+ get_frame -> cmdClass = COMMAND_CLASS_HUMIDITY_CONTROL_OPERATING_STATE ;
81+ get_frame -> cmd = HUMIDITY_CONTROL_OPERATING_STATE_GET ;
82+ * frame_length = sizeof (ZW_HUMIDITY_CONTROL_OPERATING_STATE_GET_FRAME );
83+ return SL_STATUS_OK ;
84+ }
85+
86+ sl_status_t zwave_command_class_humidity_control_operating_state_handle_report (
87+ const zwave_controller_connection_info_t * connection_info ,
88+ const uint8_t * frame_data ,
89+ uint16_t frame_length )
90+ {
91+ if (frame_length < 3 ) {
92+ return SL_STATUS_FAIL ;
93+ }
94+
95+ humidity_control_operating_state_t fan_state
96+ = frame_data [2 ]
97+ & HUMIDITY_CONTROL_OPERATING_STATE_REPORT_PROPERTIES1_OPERATING_STATE_MASK ;
98+
99+ attribute_store_node_t endpoint_node
100+ = zwave_command_class_get_endpoint_node (connection_info );
101+
102+ attribute_store_set_child_reported (
103+ endpoint_node ,
104+ ATTRIBUTE_COMMAND_CLASS_HUMIDITY_CONTROL_OPERATING_STATE_CURRENT_STATE ,
105+ & fan_state ,
106+ sizeof (fan_state ));
107+
108+ return SL_STATUS_OK ;
109+ }
110+
111+ sl_status_t
112+ zwave_command_class_humidity_control_operating_state_control_handler (
113+ const zwave_controller_connection_info_t * connection_info ,
114+ const uint8_t * frame_data ,
115+ uint16_t frame_length )
116+ {
117+ if (frame_length <= COMMAND_INDEX ) {
118+ return SL_STATUS_NOT_SUPPORTED ;
119+ }
120+
121+ switch (frame_data [COMMAND_INDEX ]) {
122+ case HUMIDITY_CONTROL_OPERATING_STATE_REPORT :
123+ return zwave_command_class_humidity_control_operating_state_handle_report (
124+ connection_info ,
125+ frame_data ,
126+ frame_length );
127+ default :
128+ return SL_STATUS_NOT_SUPPORTED ;
129+ }
130+ }
131+
132+ sl_status_t zwave_command_class_humidity_control_operating_state_init ()
133+ {
134+ attribute_store_register_callback_by_type (
135+ & zwave_command_class_humidity_control_operating_state_on_version_attribute_update ,
136+ ATTRIBUTE_COMMAND_CLASS_HUMIDITY_CONTROL_OPERATING_STATE_VERSION );
137+
138+ attribute_resolver_register_rule (
139+ ATTRIBUTE_COMMAND_CLASS_HUMIDITY_CONTROL_OPERATING_STATE_CURRENT_STATE ,
140+ NULL ,
141+ & zwave_command_class_humidity_control_operating_state_get );
142+
143+ zwave_command_handler_t handler = {};
144+ handler .support_handler = NULL ;
145+ handler .control_handler
146+ = zwave_command_class_humidity_control_operating_state_control_handler ;
147+ handler .minimal_scheme = ZWAVE_CONTROLLER_ENCAPSULATION_NONE ;
148+ handler .manual_security_validation = false;
149+ handler .command_class = COMMAND_CLASS_HUMIDITY_CONTROL_OPERATING_STATE ;
150+ handler .version = 1 ;
151+ handler .command_class_name = "Humidity Control Operating State" ;
152+ handler .comments = "Experimental" ;
153+
154+ return zwave_command_handler_register_handler (handler );
155+ }
0 commit comments