Compare commits
3 Commits
0a5891b5be
...
21cb416f41
Author | SHA1 | Date | |
---|---|---|---|
21cb416f41 | |||
3ccee9f897 | |||
2266d7ecef |
@ -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"]
|
||||||
|
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user