use std::future::Future;
use crate::{Capabilities, Error};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct DeviceInfo {
pub firmware: String,
pub version: String,
pub hardware: String,
pub device_name: String,
pub os_name: Option<String>,
pub os_version: Option<String>,
}
impl DeviceInfo {
pub fn into_strings(self) -> Vec<String> {
let mut out = vec![self.firmware, self.version, self.hardware, self.device_name];
if let Some(os) = self.os_name {
out.push(os);
out.push(self.os_version.unwrap_or_default());
}
out
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Network {
pub ssid: String,
pub rssi: i16,
pub auth: String,
}
pub trait WifiConfigurator: Send + Sync + 'static {
fn capabilities(&self) -> Capabilities;
fn identify(&self) -> impl Future<Output = Result<(), Error>> + Send {
async { Ok(()) }
}
fn device_info(&self) -> impl Future<Output = Result<DeviceInfo, Error>> + Send;
fn scan(&self) -> impl Future<Output = Result<Vec<Network>, Error>> + Send;
fn get_hostname(&self) -> impl Future<Output = Result<String, Error>> + Send;
fn set_hostname(&self, name: String) -> impl Future<Output = Result<(), Error>> + Send;
fn get_device_name(&self) -> impl Future<Output = Result<String, Error>> + Send {
async { self.device_info().await.map(|i| i.device_name) }
}
fn set_device_name(&self, _name: String) -> impl Future<Output = Result<(), Error>> + Send {
async { Err(Error::Unknown) }
}
fn provision(
&self,
ssid: String,
password: String,
) -> impl Future<Output = Result<Vec<String>, Error>> + Send;
}