1use serde::{Deserialize, Serialize};
6
7pub enum WeaveMethod {
9 GetPairingCode,
10 GetPairingState,
11 GetQrCode,
12 ResetConfig,
13}
14
15impl std::str::FromStr for WeaveMethod {
16 type Err = anyhow::Error;
17
18 fn from_str(method: &str) -> Result<Self, Self::Err> {
19 match method {
20 "GetPairingCode" => Ok(WeaveMethod::GetPairingCode),
21 "GetPairingState" => Ok(WeaveMethod::GetPairingState),
22 "GetQrCode" => Ok(WeaveMethod::GetQrCode),
23 "ResetConfig" => Ok(WeaveMethod::ResetConfig),
24 _ => return Err(format_err!("invalid Weave FIDL method: {}", method)),
25 }
26 }
27}
28
29#[derive(Serialize, PartialEq, Copy, Clone, Debug)]
30pub struct PairingState {
31 pub is_weave_fully_provisioned: Option<bool>,
34 pub is_wlan_provisioned: Option<bool>,
36 pub is_thread_provisioned: Option<bool>,
38 pub is_fabric_provisioned: Option<bool>,
40 pub is_service_provisioned: Option<bool>,
42}
43
44#[derive(Deserialize, PartialEq, Copy, Clone, Debug)]
45pub struct ResetConfig {
46 pub network_config: Option<bool>,
48 pub fabric_config: Option<bool>,
50 pub service_config: Option<bool>,
52 pub operational_credentials: Option<bool>,
54}
55
56impl From<PairingState> for fidl_fuchsia_weave::PairingState {
57 fn from(item: PairingState) -> Self {
58 fidl_fuchsia_weave::PairingState {
59 is_weave_fully_provisioned: item.is_weave_fully_provisioned,
60 is_wlan_provisioned: item.is_wlan_provisioned,
61 is_thread_provisioned: item.is_thread_provisioned,
62 is_fabric_provisioned: item.is_fabric_provisioned,
63 is_service_provisioned: item.is_service_provisioned,
64 ..Default::default()
65 }
66 }
67}
68
69impl From<fidl_fuchsia_weave::PairingState> for PairingState {
70 fn from(item: fidl_fuchsia_weave::PairingState) -> Self {
71 PairingState {
72 is_weave_fully_provisioned: item.is_weave_fully_provisioned,
73 is_wlan_provisioned: item.is_wlan_provisioned,
74 is_thread_provisioned: item.is_thread_provisioned,
75 is_fabric_provisioned: item.is_fabric_provisioned,
76 is_service_provisioned: item.is_service_provisioned,
77 }
78 }
79}
80
81impl From<ResetConfig> for fidl_fuchsia_weave::ResetConfigFlags {
82 fn from(item: ResetConfig) -> Self {
83 let mut flags: fidl_fuchsia_weave::ResetConfigFlags =
84 fidl_fuchsia_weave::ResetConfigFlags::empty();
85 flags.set(
86 fidl_fuchsia_weave::ResetConfigFlags::NETWORK_CONFIG,
87 item.network_config.unwrap_or(false),
88 );
89 flags.set(
90 fidl_fuchsia_weave::ResetConfigFlags::FABRIC_CONFIG,
91 item.fabric_config.unwrap_or(false),
92 );
93 flags.set(
94 fidl_fuchsia_weave::ResetConfigFlags::SERVICE_CONFIG,
95 item.service_config.unwrap_or(false),
96 );
97 flags.set(
98 fidl_fuchsia_weave::ResetConfigFlags::OPERATIONAL_CREDENTIALS,
99 item.operational_credentials.unwrap_or(false),
100 );
101 flags
102 }
103}