Skip to content

Commit

Permalink
Merge pull request #4
Browse files Browse the repository at this point in the history
* Use more explicit event type

* Make targets more strongly typed

* Use more strongly typed resource name

* Use ReadingType correctly also in Descriptor

* Split Interval in two types as they describe two different things

* Move enums into matching modules
  • Loading branch information
tdittr committed Jun 3, 2024
1 parent ede48f4 commit 148dc60
Show file tree
Hide file tree
Showing 9 changed files with 377 additions and 292 deletions.
3 changes: 2 additions & 1 deletion src/generated/models/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
* Generated by: https://openapi-generator.tech
*/

use crate::wire::values_map::ValuesMap;
use serde::{Deserialize, Serialize};

use crate::wire::values_map::ValuesMap;

/// Resource : A resource is an energy device or system subject to control by a VEN.

#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
Expand Down
3 changes: 2 additions & 1 deletion src/generated/models/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
* Generated by: https://openapi-generator.tech
*/

use serde::{Deserialize, Serialize};

use crate::generated::models::SubscriptionObjectOperationsInner;
use crate::wire::values_map::ValuesMap;
use serde::{Deserialize, Serialize};

/// Subscription : An object created by a client to receive notification of operations on objects. Clients may subscribe to be notified when a type of object is created, updated, or deleted.

Expand Down
6 changes: 4 additions & 2 deletions src/generated/models/ven.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
* Generated by: https://openapi-generator.tech
*/

use super::Resource;
use crate::wire::values_map::ValuesMap;
use serde::{Deserialize, Serialize};

use crate::wire::values_map::ValuesMap;

use super::Resource;

/// Ven : Ven represents a client with the ven role.

#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
Expand Down
237 changes: 3 additions & 234 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,96 +3,6 @@ use serde::{Deserialize, Serialize};
pub mod generated;
pub mod wire;

#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum Event {
Simple,
Price,
ChargeStateSetpoint,
DispatchSetpoint,
DispatchSetpointRelative,
ControlSetpoint,
ExportPrice,
#[serde(rename = "GHG")]
GHG,
Curve,
#[serde(rename = "OLS")]
OLS,
ImportCapacitySubscription,
ImportCapacityReservation,
ImportCapacityReservationFee,
ImportCapacityAvailable,
ImportCapacityAvailablePrice,
ExportCapacitySubscription,
ExportCapacityReservation,
ExportCapacityReservationFee,
ExportCapacityAvailable,
ExportCapacityAvailablePrice,
ImportCapacityLimit,
ExportCapacityLimit,
AlertGridEmergency,
AlertBlackStart,
AlertPossibleOutage,
AlertFlexAlert,
AlertFire,
AlertFreezing,
AlertWind,
AlertTsunami,
AlertAirQuality,
AlertOther,
#[serde(rename = "CTA2045_REBOOT")]
CTA2045Reboot,
#[serde(rename = "CTA2045_SET_OVERRIDE_STATUS")]
CTA2045SetOverrideStatus,
#[serde(untagged)]
Private(String),
}

#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ReportType {
Reading,
Usage,
Demand,
Setpoint,
DeltaUsage,
Baseline,
OperatingState,
UpRegulationAvailable,
DownRegulationAvailable,
RegulationSetpoint,
StorageUsableCapacity,
StorageChargeLevel,
StorageMaxDischargePower,
StorageMaxChargePower,
SimpleLevel,
UsageForecast,
StorageDispatchForecast,
LoadShedDeltaAvailable,
GenerationDeltaAvailable,
DataQuality,
ImportReservationCapacity,
ImportReservationFee,
ExportReservationCapacity,
ExportReservationFee,
#[serde(untagged)]
Private(String),
}

#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ReadingType {
DirectRead,
Estimated,
Summed,
Mean,
Peak,
Forecast,
Average,
#[serde(untagged)]
Private(String),
}

#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum OperatingState {
Expand All @@ -112,15 +22,7 @@ pub enum OperatingState {
Private(String),
}

#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ResourceName {
AggregatedReport,
#[serde(untagged)]
Private(String),
}

#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Debug)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum DataQuality {
/// No known reasons to doubt the data.
Expand All @@ -136,32 +38,7 @@ pub enum DataQuality {
Private(String),
}

#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum Target {
/// A Power Service Location is a utility named specific location in
/// geography or the distribution system, usually the point of service to a
/// customer site.
PowerServiceLocation,
/// A Service Area is a utility named geographic region.
ServiceArea,
/// Targeting a specific group (string).
Group,
/// Targeting a specific resource (string).
ResourceName,
/// Targeting a specific VEN (string).
#[serde(rename = "VEN_NAME")]
VENName,
/// Targeting a specific event (string).
EventName,
/// Targeting a specific program (string).
ProgramName,
/// An application specific privately defined target.
#[serde(untagged)]
Private(String),
}

#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Debug)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum Attribute {
/// Describes a single geographic point. Values contains 2 floats, generally
Expand All @@ -183,7 +60,7 @@ pub enum Attribute {
Private(String),
}

#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Debug)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum Unit {
/// Kilowatt-hours (kWh)
Expand Down Expand Up @@ -248,74 +125,6 @@ impl Client {
mod tests {
use super::*;

#[test]
fn test_event_serialization() {
assert_eq!(
serde_json::to_string(&Event::Simple).unwrap(),
r#""SIMPLE""#
);
assert_eq!(
serde_json::to_string(&Event::CTA2045Reboot).unwrap(),
r#""CTA2045_REBOOT""#
);
assert_eq!(
serde_json::from_str::<Event>(r#""GHG""#).unwrap(),
Event::GHG
);
assert_eq!(
serde_json::from_str::<Event>(r#""something else""#).unwrap(),
Event::Private(String::from("something else"))
);
}

#[test]
fn test_report_type_serialization() {
assert_eq!(
serde_json::to_string(&ReportType::Baseline).unwrap(),
r#""BASELINE""#
);
assert_eq!(
serde_json::to_string(&ReportType::RegulationSetpoint).unwrap(),
r#""REGULATION_SETPOINT""#
);
assert_eq!(
serde_json::to_string(&ReportType::Private(String::from("something else"))).unwrap(),
r#""something else""#
);
assert_eq!(
serde_json::from_str::<ReportType>(r#""DEMAND""#).unwrap(),
ReportType::Demand
);
assert_eq!(
serde_json::from_str::<ReportType>(r#""EXPORT_RESERVATION_FEE""#).unwrap(),
ReportType::ExportReservationFee
);
assert_eq!(
serde_json::from_str::<ReportType>(r#""something else""#).unwrap(),
ReportType::Private(String::from("something else"))
);
}

#[test]
fn test_reading_type_serialization() {
assert_eq!(
serde_json::to_string(&ReadingType::DirectRead).unwrap(),
r#""DIRECT_READ""#
);
assert_eq!(
serde_json::to_string(&ReadingType::Private(String::from("something else"))).unwrap(),
r#""something else""#
);
assert_eq!(
serde_json::from_str::<ReadingType>(r#""AVERAGE""#).unwrap(),
ReadingType::Average
);
assert_eq!(
serde_json::from_str::<ReadingType>(r#""something else""#).unwrap(),
ReadingType::Private(String::from("something else"))
);
}

#[test]
fn test_operating_state_serialization() {
assert_eq!(
Expand All @@ -341,26 +150,6 @@ mod tests {
);
}

#[test]
fn test_resource_name_serialization() {
assert_eq!(
serde_json::to_string(&ResourceName::AggregatedReport).unwrap(),
r#""AGGREGATED_REPORT""#
);
assert_eq!(
serde_json::to_string(&ResourceName::Private(String::from("something else"))).unwrap(),
r#""something else""#
);
assert_eq!(
serde_json::from_str::<ResourceName>(r#""AGGREGATED_REPORT""#).unwrap(),
ResourceName::AggregatedReport
);
assert_eq!(
serde_json::from_str::<ResourceName>(r#""something else""#).unwrap(),
ResourceName::Private(String::from("something else"))
);
}

#[test]
fn test_data_quality_serialization() {
assert_eq!(serde_json::to_string(&DataQuality::Ok).unwrap(), r#""OK""#);
Expand All @@ -378,26 +167,6 @@ mod tests {
);
}

#[test]
fn test_target_serialization() {
assert_eq!(
serde_json::to_string(&Target::EventName).unwrap(),
r#""EVENT_NAME""#
);
assert_eq!(
serde_json::to_string(&Target::Private(String::from("something else"))).unwrap(),
r#""something else""#
);
assert_eq!(
serde_json::from_str::<Target>(r#""VEN_NAME""#).unwrap(),
Target::VENName
);
assert_eq!(
serde_json::from_str::<Target>(r#""something else""#).unwrap(),
Target::Private(String::from("something else"))
);
}

#[test]
fn test_attribute_serialization() {
assert_eq!(
Expand Down
Loading

0 comments on commit 148dc60

Please sign in to comment.