Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/clusters/gen/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
7 changes: 7 additions & 0 deletions src/clusters/gen/models/tlv_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 4 additions & 0 deletions src/clusters/gen/orchestrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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', ''),
Expand Down
4 changes: 4 additions & 0 deletions src/clusters/gen/type_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/tlv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ impl TlvItem {
Some(self)
}
}

pub fn get_int(&self, tag: &[u8]) -> Option<u64> {
let found = self.get(tag);
if let Some(TlvItemValue::Int(i)) = found {
Expand All @@ -314,6 +315,16 @@ impl TlvItem {
None
}
}

pub fn get_float(&self, tag: &[u8]) -> Option<f64> {
let found = self.get(tag);
if let Some(TlvItemValue::Float(f)) = found {
Some(*f)
} else {
None
}
}

pub fn get_t<T>(&self, tag: &[u8]) -> Option<T>
where
T: From<TlvItemValue>,
Expand Down
Loading