Compare commits
5 commits
1a4694bad5
...
2f0822ff4a
Author | SHA1 | Date | |
---|---|---|---|
2f0822ff4a | |||
227c9fef43 | |||
42d2f29bfc | |||
057b952d11 | |||
15d9d21c9b |
1 changed files with 15 additions and 8 deletions
|
@ -4,6 +4,17 @@ use serde_repr::{Deserialize_repr, Serialize_repr};
|
|||
use std::{borrow::Borrow, collections::HashMap, net::IpAddr};
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ValueError(String);
|
||||
|
||||
impl std::fmt::Display for ValueError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(f, "Invalid value given! Reason: {}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for ValueError {}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum Error {
|
||||
#[error("unsupported API version {0}")]
|
||||
|
@ -76,7 +87,7 @@ impl Fronius {
|
|||
pub fn get_inverter_realtime_data_device<C: DataCollection>(
|
||||
&self,
|
||||
device_id: DeviceId,
|
||||
) -> Result<C, Error> {
|
||||
) -> Result<CumulationInverterData, Error> {
|
||||
let device_id = u8::from(device_id).to_string();
|
||||
|
||||
let response: CommonResponseBody<_> = self.make_request(
|
||||
|
@ -167,18 +178,14 @@ struct ApiVersion {
|
|||
|
||||
pub struct DeviceId(u8);
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
|
||||
#[error("invalid device ID, must be less than 100: {0}")]
|
||||
pub struct InvalidDeviceId(u8);
|
||||
|
||||
impl TryFrom<u8> for DeviceId {
|
||||
type Error = InvalidDeviceId;
|
||||
type Error = ValueError;
|
||||
|
||||
fn try_from(device_id: u8) -> Result<Self, InvalidDeviceId> {
|
||||
fn try_from(device_id: u8) -> Result<Self, ValueError> {
|
||||
if device_id <= 99 {
|
||||
Ok(Self(device_id))
|
||||
} else {
|
||||
Err(InvalidDeviceId(device_id))
|
||||
Err(ValueError("device id not in range!".into()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue