Compare commits
5 commits
2f0822ff4a
...
1a4694bad5
Author | SHA1 | Date | |
---|---|---|---|
1a4694bad5 | |||
5ec9079456 | |||
7d42a56199 | |||
1da05e29e1 | |||
375377f56a |
1 changed files with 9 additions and 16 deletions
|
@ -4,17 +4,6 @@ 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}")]
|
||||
|
@ -87,7 +76,7 @@ impl Fronius {
|
|||
pub fn get_inverter_realtime_data_device<C: DataCollection>(
|
||||
&self,
|
||||
device_id: DeviceId,
|
||||
) -> Result<CumulationInverterData, Error> {
|
||||
) -> Result<C, Error> {
|
||||
let device_id = u8::from(device_id).to_string();
|
||||
|
||||
let response: CommonResponseBody<_> = self.make_request(
|
||||
|
@ -178,14 +167,18 @@ struct ApiVersion {
|
|||
|
||||
pub struct DeviceId(u8);
|
||||
|
||||
impl TryFrom<u8> for DeviceId {
|
||||
type Error = ValueError;
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
|
||||
#[error("invalid device ID, must be less than 100: {0}")]
|
||||
pub struct InvalidDeviceId(u8);
|
||||
|
||||
fn try_from(device_id: u8) -> Result<Self, ValueError> {
|
||||
impl TryFrom<u8> for DeviceId {
|
||||
type Error = InvalidDeviceId;
|
||||
|
||||
fn try_from(device_id: u8) -> Result<Self, InvalidDeviceId> {
|
||||
if device_id <= 99 {
|
||||
Ok(Self(device_id))
|
||||
} else {
|
||||
Err(ValueError("device id not in range!".into()))
|
||||
Err(InvalidDeviceId(device_id))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue