Compare commits

..

3 Commits

Author SHA1 Message Date
21cb416f41 Enable tungstenite by default 2024-11-25 13:50:25 +01:00
3ccee9f897 Cargo version 0.1.1 2024-11-25 13:41:43 +01:00
2266d7ecef Cargo fmt 2024-11-25 13:37:32 +01:00
2 changed files with 19 additions and 12 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "easee" name = "easee"
version = "0.1.0" version = "0.1.1"
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,3 +22,6 @@ 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,4 +1,7 @@
use serde::{de::{DeserializeOwned, IntoDeserializer}, Deserialize}; use serde::{
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;
@ -83,16 +86,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( DataType::Boolean => ObservationData::Boolean(match &*value {
match &*value { "False" | "false" => false,
"False"|"false" => { false }, "True" | "true" => true,
"True"|"true" => { true } other => {
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()
@ -226,7 +229,8 @@ 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)).ok() T::deserialize(<i64 as IntoDeserializer<serde::de::value::Error>>::into_deserializer(value))
.ok()
} }
impl Observation { impl Observation {