diff --git a/src/clusters/gen/gen.py b/src/clusters/gen/gen.py index 84e150d..4ec8d61 100644 --- a/src/clusters/gen/gen.py +++ b/src/clusters/gen/gen.py @@ -23,7 +23,12 @@ 'enum8': 'u8', 'enum16': 'u16', 'epoch-s': 'u64', - 'int16': 'u16', + 'int8': 'i8', + 'int16': 'i16', + 'int32': 'i32', + 'int64': 'i64', + 'single': 'f32', + 'double': 'f64', } tlv_getters = { diff --git a/src/clusters/gen/models/tlv_helpers.py b/src/clusters/gen/models/tlv_helpers.py index e034d3e..a211849 100644 --- a/src/clusters/gen/models/tlv_helpers.py +++ b/src/clusters/gen/models/tlv_helpers.py @@ -198,6 +198,9 @@ def _generate_single_value_decoder(attr_type: str, nullable: bool, enums: Option elif tlv_type == "OctetString": match_pattern = 'tlv::TlvItemValue::OctetString(v)' value_expr = 'v.clone()' + elif tlv_type.startswith("Float"): + match_pattern = 'tlv::TlvItemValue::Float(v)' + value_expr = _get_value_cast_expr('*v', attr_type, enums, bitmaps) elif tlv_type.startswith("UInt") or tlv_type.startswith("Int"): match_pattern = 'tlv::TlvItemValue::Int(v)' # Check if this is an enum type @@ -379,6 +382,10 @@ def _generate_struct_field_assignments(struct_fields: List[Tuple[int, str, str, None }} }},''') + elif field_type == 'single': + field_assignments.append(f" {rust_field_name}: {item_var}.get_float(&[{field_id}]).map(|v| v as f32),") + elif field_type == 'double': + field_assignments.append(f" {rust_field_name}: {item_var}.get_float(&[{field_id}]),") elif is_numeric_or_id_type(field_type): from ..naming import build_numeric_field_assignment field_assignments.append(build_numeric_field_assignment(rust_field_name, field_id, field_type, enums=enums, indent=' ', item_var=item_var)) diff --git a/src/clusters/gen/orchestrate.py b/src/clusters/gen/orchestrate.py index 421af72..c1db23b 100644 --- a/src/clusters/gen/orchestrate.py +++ b/src/clusters/gen/orchestrate.py @@ -702,6 +702,8 @@ def generate_main_event_list_dispatcher(cluster_info: List[Dict[str, str]]) -> s 'int16': 'I16', 'int32': 'I32', 'int64': 'I64', + 'single': 'F32', + 'double': 'F64', 'bool': 'Bool', 'string': 'String', 'octstr': 'OctetString', @@ -811,6 +813,8 @@ def _command_has_complex_fields(command, structs) -> bool: 'int16': ('get_i16', ''), 'int32': ('get_i32', ''), 'int64': ('get_i64', ''), + 'single': ('get_f32', ''), + 'double': ('get_f64', ''), 'bool': ('get_bool', ''), 'string': ('get_string', ''), 'octstr': ('get_octstr', ''), diff --git a/src/clusters/gen/type_mapping.py b/src/clusters/gen/type_mapping.py index 33861e5..217d700 100644 --- a/src/clusters/gen/type_mapping.py +++ b/src/clusters/gen/type_mapping.py @@ -24,6 +24,8 @@ class MatterType: 'int16': ('Int16', 'i16'), 'int32': ('Int32', 'i32'), 'int64': ('Int64', 'i64'), + 'single': ('Float32', 'f32'), + 'double': ('Float64', 'f64'), 'bool': ('Bool', 'bool'), 'string': ('String', 'String'), 'epoch-s': ('UInt64', 'u64'), @@ -61,11 +63,13 @@ class MatterType: TLV_TO_RUST = { 'UInt8': 'u8', 'UInt16': 'u16', 'UInt32': 'u32', 'UInt64': 'u64', 'Int8': 'i8', 'Int16': 'i16', 'Int32': 'i32', 'Int64': 'i64', + 'Float32': 'f32', 'Float64': 'f64', } RUST_TO_TLV = { 'u8': 'UInt8', 'u16': 'UInt16', 'u32': 'UInt32', 'u64': 'UInt64', 'i8': 'Int8', 'i16': 'Int16', 'i32': 'Int32', 'i64': 'Int64', + 'f32': 'Float32', 'f64': 'Float64', } @classmethod diff --git a/src/tlv.rs b/src/tlv.rs index 1eed330..f9f9854 100644 --- a/src/tlv.rs +++ b/src/tlv.rs @@ -306,6 +306,7 @@ impl TlvItem { Some(self) } } + pub fn get_int(&self, tag: &[u8]) -> Option { let found = self.get(tag); if let Some(TlvItemValue::Int(i)) = found { @@ -314,6 +315,16 @@ impl TlvItem { None } } + + pub fn get_float(&self, tag: &[u8]) -> Option { + let found = self.get(tag); + if let Some(TlvItemValue::Float(f)) = found { + Some(*f) + } else { + None + } + } + pub fn get_t(&self, tag: &[u8]) -> Option where T: From,