lol
This commit is contained in:
11
src/main.rs
11
src/main.rs
@@ -14,6 +14,7 @@ enum Error {
|
||||
JSONError(serde_json::Error),
|
||||
MQTTError(mqtt::Error),
|
||||
IoError(std::io::Error),
|
||||
MyError,
|
||||
}
|
||||
|
||||
impl From<ureq::Error> for Error {
|
||||
@@ -140,6 +141,11 @@ impl TryFrom<SolaxResponse> for MQTTData {
|
||||
type Error = Error;
|
||||
|
||||
fn try_from(s: SolaxResponse) -> Result<Self, Error> {
|
||||
// On my inverter it's always exactly 100 entries, but avoid panics
|
||||
if s.data.len() < 56 {
|
||||
return Err(Error::MyError);
|
||||
}
|
||||
|
||||
let status = s.data[10];
|
||||
|
||||
let inverter_data = InverterData {
|
||||
@@ -209,6 +215,11 @@ fn mqtt_connect(uri: String, client_id: String) -> Result<mqtt::Client, mqtt::Er
|
||||
fn gather(uri: &str, password: &str) -> Result<MQTTData, Error> {
|
||||
let body = format!("optType=ReadRealTimeData&pwd={}", password);
|
||||
let response = ureq::post(uri).send_string(&body)?;
|
||||
|
||||
if response.status() < 200 || response.status() > 299 {
|
||||
return Err(Error::MyError);
|
||||
}
|
||||
|
||||
let solax_response: SolaxResponse = response.into_json()?;
|
||||
|
||||
solax_response.try_into()
|
||||
|
Reference in New Issue
Block a user