use serde::{Deserialize, Serialize};
pub enum WeaveMethod {
GetPairingCode,
GetPairingState,
GetQrCode,
ResetConfig,
}
impl std::str::FromStr for WeaveMethod {
type Err = anyhow::Error;
fn from_str(method: &str) -> Result<Self, Self::Err> {
match method {
"GetPairingCode" => Ok(WeaveMethod::GetPairingCode),
"GetPairingState" => Ok(WeaveMethod::GetPairingState),
"GetQrCode" => Ok(WeaveMethod::GetQrCode),
"ResetConfig" => Ok(WeaveMethod::ResetConfig),
_ => return Err(format_err!("invalid Weave FIDL method: {}", method)),
}
}
}
#[derive(Serialize, PartialEq, Copy, Clone, Debug)]
pub struct PairingState {
pub is_weave_fully_provisioned: Option<bool>,
pub is_wlan_provisioned: Option<bool>,
pub is_thread_provisioned: Option<bool>,
pub is_fabric_provisioned: Option<bool>,
pub is_service_provisioned: Option<bool>,
}
#[derive(Deserialize, PartialEq, Copy, Clone, Debug)]
pub struct ResetConfig {
pub network_config: Option<bool>,
pub fabric_config: Option<bool>,
pub service_config: Option<bool>,
pub operational_credentials: Option<bool>,
}
impl From<PairingState> for fidl_fuchsia_weave::PairingState {
fn from(item: PairingState) -> Self {
fidl_fuchsia_weave::PairingState {
is_weave_fully_provisioned: item.is_weave_fully_provisioned,
is_wlan_provisioned: item.is_wlan_provisioned,
is_thread_provisioned: item.is_thread_provisioned,
is_fabric_provisioned: item.is_fabric_provisioned,
is_service_provisioned: item.is_service_provisioned,
..Default::default()
}
}
}
impl From<fidl_fuchsia_weave::PairingState> for PairingState {
fn from(item: fidl_fuchsia_weave::PairingState) -> Self {
PairingState {
is_weave_fully_provisioned: item.is_weave_fully_provisioned,
is_wlan_provisioned: item.is_wlan_provisioned,
is_thread_provisioned: item.is_thread_provisioned,
is_fabric_provisioned: item.is_fabric_provisioned,
is_service_provisioned: item.is_service_provisioned,
}
}
}
impl From<ResetConfig> for fidl_fuchsia_weave::ResetConfigFlags {
fn from(item: ResetConfig) -> Self {
let mut flags: fidl_fuchsia_weave::ResetConfigFlags =
fidl_fuchsia_weave::ResetConfigFlags::empty();
flags.set(
fidl_fuchsia_weave::ResetConfigFlags::NETWORK_CONFIG,
item.network_config.unwrap_or(false),
);
flags.set(
fidl_fuchsia_weave::ResetConfigFlags::FABRIC_CONFIG,
item.fabric_config.unwrap_or(false),
);
flags.set(
fidl_fuchsia_weave::ResetConfigFlags::SERVICE_CONFIG,
item.service_config.unwrap_or(false),
);
flags.set(
fidl_fuchsia_weave::ResetConfigFlags::OPERATIONAL_CREDENTIALS,
item.operational_credentials.unwrap_or(false),
);
flags
}
}