extern crate alloc;
use std::{env, fs};
use std::path::PathBuf;
use thiserror::Error;
use foxess::Fox;
#[cfg(feature = "async")]
#[tokio::test]
async fn it_works() {
let api_key = read_credential("fox_ess_api_key").unwrap_or_else(|e| {
panic!("fox_ess_api_key not found in credstore: {e}");
});
let sn = read_credential("fox_ess_inverter_sn").unwrap_or_else(|e| {
panic!("fox_ess_inverter_sn not found in credstore: {e}");
});
let fox = Fox::new(&api_key, &sn, 30).unwrap_or_else(|e| {
panic!("Failed to create Fox instance: {e}");
});
let x = fox.get_error_code_information().await.unwrap_or_else(|e| {
panic!("Failed to get error code information: {e}");
});
let mut codes = x.keys().collect::<Vec<&u32>>();
codes.sort();
for c in codes {
println!("{} - {}", c, x.get(c).unwrap_or(&"Unknown".to_string()) );
}
}
#[cfg(feature = "blocking")]
#[test]
fn it_works() {
let api_key = read_credential("fox_ess_api_key").unwrap_or_else(|e| {
panic!("fox_ess_api_key not found in credstore: {e}");
});
let sn = read_credential("fox_ess_inverter_sn").unwrap_or_else(|e| {
panic!("fox_ess_inverter_sn not found in credstore: {e}");
});
let fox = Fox::new(&api_key, &sn, 30).unwrap_or_else(|e| {
panic!("Failed to create Fox instance: {e}");
});
let x = fox.get_error_code_information().unwrap_or_else(|e| {
panic!("Failed to get error code information: {e}");
});
let mut codes = x.keys().collect::<Vec<&u32>>();
codes.sort();
for c in codes {
println!("{} - {}", c, x.get(c).unwrap_or(&"Unknown".to_string()) );
}
}
fn read_credential(name: &str) -> Result<String, ConfigError> {
let dir = env::var("CREDENTIALS_DIRECTORY")?;
let mut p = PathBuf::from(dir);
p.push(name);
let bytes = fs::read(p)?;
Ok(String::from_utf8(bytes)?.trim_end().to_string())
}
#[derive(Debug, Error)]
enum ConfigError {
#[error("IoError: {0}")]
IoError(#[from] std::io::Error),
#[error("StringConversionError: {0}")]
StringConversionError(#[from] alloc::string::FromUtf8Error),
#[error("EnvVarError: {0}")]
EnvVarError(#[from] env::VarError),
}