matc/clusters/codec/
account_login.rs

1//! Matter TLV encoders and decoders for Account Login Cluster
2//! Cluster ID: 0x050E
3//!
4//! This file is automatically generated from AccountLogin.xml
5
6use crate::tlv;
7use anyhow;
8
9
10// Command encoders
11
12/// Encode GetSetupPIN command (0x00)
13pub fn encode_get_setup_pin(temp_account_identifier: String) -> anyhow::Result<Vec<u8>> {
14    let tlv = tlv::TlvItemEnc {
15        tag: 0,
16        value: tlv::TlvItemValueEnc::StructInvisible(vec![
17        (0, tlv::TlvItemValueEnc::String(temp_account_identifier)).into(),
18        ]),
19    };
20    Ok(tlv.encode()?)
21}
22
23/// Encode Login command (0x02)
24pub fn encode_login(temp_account_identifier: String, setup_pin: String, node: u64) -> anyhow::Result<Vec<u8>> {
25    let tlv = tlv::TlvItemEnc {
26        tag: 0,
27        value: tlv::TlvItemValueEnc::StructInvisible(vec![
28        (0, tlv::TlvItemValueEnc::String(temp_account_identifier)).into(),
29        (1, tlv::TlvItemValueEnc::String(setup_pin)).into(),
30        (2, tlv::TlvItemValueEnc::UInt64(node)).into(),
31        ]),
32    };
33    Ok(tlv.encode()?)
34}
35
36/// Encode Logout command (0x03)
37pub fn encode_logout(node: u64) -> anyhow::Result<Vec<u8>> {
38    let tlv = tlv::TlvItemEnc {
39        tag: 0,
40        value: tlv::TlvItemValueEnc::StructInvisible(vec![
41        (0, tlv::TlvItemValueEnc::UInt64(node)).into(),
42        ]),
43    };
44    Ok(tlv.encode()?)
45}
46
47#[derive(Debug, serde::Serialize)]
48pub struct GetSetupPINResponse {
49    pub setup_pin: Option<String>,
50}
51
52// Command response decoders
53
54/// Decode GetSetupPINResponse command response (01)
55pub fn decode_get_setup_pin_response(inp: &tlv::TlvItemValue) -> anyhow::Result<GetSetupPINResponse> {
56    if let tlv::TlvItemValue::List(_fields) = inp {
57        let item = tlv::TlvItem { tag: 0, value: inp.clone() };
58        Ok(GetSetupPINResponse {
59                setup_pin: item.get_string_owned(&[0]),
60        })
61    } else {
62        Err(anyhow::anyhow!("Expected struct fields"))
63    }
64}
65
66#[derive(Debug, serde::Serialize)]
67pub struct LoggedOutEvent {
68    pub node: Option<u64>,
69}
70
71// Event decoders
72
73/// Decode LoggedOut event (0x00, priority: critical)
74pub fn decode_logged_out_event(inp: &tlv::TlvItemValue) -> anyhow::Result<LoggedOutEvent> {
75    if let tlv::TlvItemValue::List(_fields) = inp {
76        let item = tlv::TlvItem { tag: 0, value: inp.clone() };
77        Ok(LoggedOutEvent {
78                                node: item.get_int(&[0]),
79        })
80    } else {
81        Err(anyhow::anyhow!("Expected struct fields"))
82    }
83}
84