Compare commits

..

No commits in common. "21cb416f41c2f38cf016e2395b14ac13fb433e14" and "0a5891b5be6db0a366d8f38bbf3c3b939e104b97" have entirely different histories.

2 changed files with 12 additions and 19 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "easee" name = "easee"
version = "0.1.1" version = "0.1.0"
edition = "2021" edition = "2021"
authors = ["Maxime Augier <max@xolus.net>"] authors = ["Maxime Augier <max@xolus.net>"]
description = "Rust bindings for the Easee cloud API for EV charging devices" description = "Rust bindings for the Easee cloud API for EV charging devices"
@ -22,6 +22,3 @@ thiserror = "1.0.63"
tracing = "0.1.40" tracing = "0.1.40"
tungstenite = { version = "0.23.0", optional = true, features = ["rustls-tls-native-roots"] } tungstenite = { version = "0.23.0", optional = true, features = ["rustls-tls-native-roots"] }
ureq = { version = "2.10.0", features = ["json"] } ureq = { version = "2.10.0", features = ["json"] }
[features]
default = ["tungstenite"]

View File

@ -1,7 +1,4 @@
use serde::{ use serde::{de::{DeserializeOwned, IntoDeserializer}, Deserialize};
de::{DeserializeOwned, IntoDeserializer},
Deserialize,
};
use serde_repr::Deserialize_repr; use serde_repr::Deserialize_repr;
use std::num::{ParseFloatError, ParseIntError}; use std::num::{ParseFloatError, ParseIntError};
use thiserror::Error; use thiserror::Error;
@ -86,16 +83,16 @@ pub enum ParseError {
impl ObservationData { impl ObservationData {
fn from_dynamic(value: String, data_type: DataType) -> Result<ObservationData, ParseError> { fn from_dynamic(value: String, data_type: DataType) -> Result<ObservationData, ParseError> {
Ok(match data_type { Ok(match data_type {
DataType::Boolean => ObservationData::Boolean(match &*value { DataType::Boolean => ObservationData::Boolean(
"False" | "false" => false, match &*value {
"True" | "true" => true, "False"|"false" => { false },
other => { "True"|"true" => { true }
other other => other
.parse::<i64>() .parse::<i64>()
.map_err(move |e| ParseError::Integer(value, e))? .map_err(move |e| ParseError::Integer(value, e))?
!= 0 != 0,
} }
}), ),
DataType::Double => ObservationData::Double( DataType::Double => ObservationData::Double(
value value
.parse() .parse()
@ -229,8 +226,7 @@ fn op_mode_from_int(mode: i64) -> ChargerOpMode {
} }
fn deserialize_i64<T: DeserializeOwned>(value: i64) -> Option<T> { fn deserialize_i64<T: DeserializeOwned>(value: i64) -> Option<T> {
T::deserialize(<i64 as IntoDeserializer<serde::de::value::Error>>::into_deserializer(value)) T::deserialize(<i64 as IntoDeserializer<serde::de::value::Error>>::into_deserializer(value)).ok()
.ok()
} }
impl Observation { impl Observation {