use crate::traits::{
SEAbstractDevice, SEList, SEResource, SESubscribableList, SESubscribableResource, Validate,
};
use sep2_common_derive::{
SEAbstractDevice, SEList, SEResource, SESubscribableList, SESubscribableResource,
};
use yaserde::{YaDeserialize, YaSerialize};
#[cfg(test)]
use crate::serialize;
#[cfg(feature = "csip_aus")]
use super::conn_point::ConnectionPointLink;
use super::{
links::{
ConfigurationLink, DERListLink, DeviceInformationLink, DeviceStatusLink, FileStatusLink,
FlowReservationRequestListLink, FlowReservationResponseListLink,
FunctionSetAssignmentsListLink, IPInterfaceListLink, LoadShedAvailabilityListLink,
LogEventListLink, PowerStatusLink, RegistrationLink, SubscriptionListLink, TimeLink,
},
primitives::{HexBinary160, Int16, Uint16, Uint32, Uint8},
types::{
DeviceCategoryType, PINType, PowerOfTenMultiplierType, SFDIType, SubscribableType, TimeType,
},
};
#[derive(
Default,
PartialEq,
Eq,
Debug,
Clone,
YaSerialize,
YaDeserialize,
SESubscribableResource,
SEResource,
SEAbstractDevice,
)]
#[yaserde(rename = "AbstractDevice")]
#[yaserde(namespace = "urn:ieee:std:2030.5:ns")]
pub struct AbstractDevice {
#[yaserde(rename = "ConfigurationLink")]
pub configuration_link: Option<ConfigurationLink>,
#[yaserde(rename = "DERListLink")]
pub der_list_link: Option<DERListLink>,
#[yaserde(rename = "deviceCategory")]
pub device_category: Option<DeviceCategoryType>,
#[yaserde(rename = "DeviceInformationLink")]
pub device_information_link: Option<DeviceInformationLink>,
#[yaserde(rename = "DeviceStatusLink")]
pub device_status_link: Option<DeviceStatusLink>,
#[yaserde(rename = "FileStatusLink")]
pub file_status_link: Option<FileStatusLink>,
#[yaserde(rename = "IPInterfaceListLink")]
pub ip_interface_list_link: Option<IPInterfaceListLink>,
#[yaserde(rename = "lFDI")]
pub lfdi: Option<HexBinary160>,
#[yaserde(rename = "LoadShedAvailabilityListLink")]
pub load_shed_availability_list_link: Option<LoadShedAvailabilityListLink>,
#[yaserde(rename = "LogEventListLink")]
pub log_event_list_link: Option<LogEventListLink>,
#[yaserde(rename = "PowerStatusLink")]
pub power_status_link: Option<PowerStatusLink>,
#[yaserde(rename = "sFDI")]
pub sfdi: SFDIType,
#[yaserde(attribute, rename = "subscribable")]
pub subscribable: Option<SubscribableType>,
#[yaserde(attribute, rename = "href")]
pub href: Option<String>,
}
impl Validate for AbstractDevice {}
#[derive(Default, PartialEq, Eq, Debug, Clone, YaSerialize, YaDeserialize, SEResource)]
#[yaserde(rename = "DeviceStatus")]
#[yaserde(namespace = "urn:ieee:std:2030.5:ns")]
pub struct DeviceStatus {
#[yaserde(rename = "changedTime")]
pub changed_time: TimeType,
#[yaserde(rename = "onCount")]
pub on_count: Option<Uint16>,
#[yaserde(rename = "opState")]
pub op_state: Option<OpState>,
#[yaserde(rename = "opTime")]
pub op_time: Option<Uint32>,
#[yaserde(rename = "Temperature")]
pub temperature: Vec<Temperature>,
#[yaserde(rename = "TimeLink")]
pub time_link: Option<TimeLink>,
#[yaserde(attribute, rename = "pollRate")]
pub poll_rate: Option<Uint32>,
#[yaserde(attribute, rename = "href")]
pub href: Option<String>,
}
impl Validate for DeviceStatus {}
#[allow(non_camel_case_types)]
#[derive(
Default, PartialEq, PartialOrd, Eq, Ord, Debug, Clone, Copy, YaSerialize, YaDeserialize,
)]
#[yaserde(namespace = "urn:ieee:std:2030.5:ns")]
#[repr(u8)]
pub enum OpState {
#[default]
NotApplicable = 0,
NotOperating = 1,
Operating = 2,
StartingUp = 3,
ShuttingDown = 4,
AtDisconnectLevel = 5,
kWRamping = 6,
kVarRamping = 7,
}
#[derive(
Default,
PartialEq,
Eq,
Debug,
Clone,
YaSerialize,
YaDeserialize,
SEAbstractDevice,
SESubscribableResource,
SEResource,
)]
#[yaserde(rename = "EndDevice")]
#[yaserde(namespace = "urn:ieee:std:2030.5:ns")]
#[cfg_attr(
feature = "csip_aus",
yaserde(namespace = "csipaus: https://csipaus.org/ns")
)]
pub struct EndDevice {
#[yaserde(rename = "changedTime")]
pub changed_time: TimeType,
#[yaserde(rename = "enabled")]
pub enabled: Option<bool>,
#[yaserde(rename = "FlowReservationRequestListLink")]
pub flow_reservation_request_list_link: Option<FlowReservationRequestListLink>,
#[yaserde(rename = "FlowReservationResponseListLink")]
pub flow_reservation_response_list_link: Option<FlowReservationResponseListLink>,
#[yaserde(rename = "FunctionSetAssignmentsListLink")]
pub function_set_assignments_list_link: Option<FunctionSetAssignmentsListLink>,
#[yaserde(rename = "postRate")]
pub post_rate: Option<Uint32>,
#[yaserde(rename = "RegistrationLink")]
pub registration_link: Option<RegistrationLink>,
#[yaserde(rename = "SubscriptionListLink")]
pub subscription_list_link: Option<SubscriptionListLink>,
#[yaserde(rename = "ConfigurationLink")]
pub configuration_link: Option<ConfigurationLink>,
#[yaserde(rename = "DERListLink")]
pub der_list_link: Option<DERListLink>,
#[yaserde(rename = "deviceCategory")]
pub device_category: Option<DeviceCategoryType>,
#[yaserde(rename = "DeviceInformationLink")]
pub device_information_link: Option<DeviceInformationLink>,
#[yaserde(rename = "DeviceStatusLink")]
pub device_status_link: Option<DeviceStatusLink>,
#[yaserde(rename = "FileStatusLink")]
pub file_status_link: Option<FileStatusLink>,
#[yaserde(rename = "IPInterfaceListLink")]
pub ip_interface_list_link: Option<IPInterfaceListLink>,
#[yaserde(rename = "lFDI")]
pub lfdi: Option<HexBinary160>,
#[yaserde(rename = "LoadShedAvailabilityListLink")]
pub load_shed_availability_list_link: Option<LoadShedAvailabilityListLink>,
#[yaserde(rename = "LogEventListLink")]
pub log_event_list_link: Option<LogEventListLink>,
#[yaserde(rename = "PowerStatusLink")]
pub power_status_link: Option<PowerStatusLink>,
#[cfg(feature = "csip_aus")]
#[yaserde(prefix = "csipaus", namespace = "csipaus: https://csipaus.org/ns")]
#[yaserde(rename = "ConnectionPointLink ")]
pub connection_point_link: Option<ConnectionPointLink>,
#[yaserde(rename = "sFDI")]
pub sfdi: SFDIType,
#[yaserde(attribute, rename = "subscribable")]
pub subscribable: Option<SubscribableType>,
#[yaserde(attribute, rename = "href")]
pub href: Option<String>,
}
impl PartialOrd for EndDevice {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl Ord for EndDevice {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
match self.changed_time.cmp(&other.changed_time).reverse() {
core::cmp::Ordering::Equal => {}
ord => return ord,
}
match self.sfdi.cmp(&other.sfdi) {
core::cmp::Ordering::Equal => {}
ord => return ord,
}
self.href.cmp(&other.href)
}
}
impl Validate for EndDevice {}
#[derive(
Default,
PartialEq,
Eq,
Debug,
Clone,
YaSerialize,
YaDeserialize,
SESubscribableList,
SEList,
SESubscribableResource,
SEResource,
)]
#[yaserde(rename = "EndDeviceList")]
#[yaserde(namespace = "urn:ieee:std:2030.5:ns")]
#[cfg_attr(
feature = "csip_aus",
yaserde(namespace = "csipaus: https://csipaus.org/ns")
)]
pub struct EndDeviceList {
#[yaserde(rename = "EndDevice")]
pub end_device: Vec<EndDevice>,
#[yaserde(attribute, rename = "pollRate")]
pub poll_rate: Option<Uint32>,
#[yaserde(attribute, rename = "all")]
pub all: Uint32,
#[yaserde(attribute, rename = "results")]
pub results: Uint32,
#[yaserde(attribute, rename = "subscribable")]
pub subscribable: Option<SubscribableType>,
#[yaserde(attribute, rename = "href")]
pub href: Option<String>,
}
impl Validate for EndDeviceList {}
#[derive(Default, PartialEq, Eq, Debug, Clone, YaSerialize, YaDeserialize, SEResource)]
#[yaserde(rename = "Registration")]
#[yaserde(namespace = "urn:ieee:std:2030.5:ns")]
pub struct Registration {
#[yaserde(rename = "dateTimeRegistered")]
pub date_time_registered: TimeType,
#[yaserde(rename = "pIN")]
pub pin: PINType,
#[yaserde(attribute, rename = "pollRate")]
pub poll_rate: Option<Uint32>,
#[yaserde(attribute, rename = "href")]
pub href: Option<String>,
}
impl Validate for Registration {}
#[derive(
Default,
PartialEq,
Eq,
Debug,
Clone,
YaSerialize,
YaDeserialize,
SEAbstractDevice,
SESubscribableResource,
SEResource,
)]
#[yaserde(rename = "SelfDevice")]
#[yaserde(namespace = "urn:ieee:std:2030.5:ns")]
pub struct SelfDevice {
#[yaserde(attribute, rename = "pollRate")]
pub poll_rate: Option<Uint32>,
#[yaserde(rename = "ConfigurationLink")]
pub configuration_link: Option<ConfigurationLink>,
#[yaserde(rename = "DERListLink")]
pub der_list_link: Option<DERListLink>,
#[yaserde(rename = "deviceCategory")]
pub device_category: Option<DeviceCategoryType>,
#[yaserde(rename = "DeviceInformationLink")]
pub device_information_link: Option<DeviceInformationLink>,
#[yaserde(rename = "DeviceStatusLink")]
pub device_status_link: Option<DeviceStatusLink>,
#[yaserde(rename = "FileStatusLink")]
pub file_status_link: Option<FileStatusLink>,
#[yaserde(rename = "IPInterfaceListLink")]
pub ip_interface_list_link: Option<IPInterfaceListLink>,
#[yaserde(rename = "lFDI")]
pub lfdi: Option<HexBinary160>,
#[yaserde(rename = "LoadShedAvailabilityListLink")]
pub load_shed_availability_list_link: Option<LoadShedAvailabilityListLink>,
#[yaserde(rename = "LogEventListLink")]
pub log_event_list_link: Option<LogEventListLink>,
#[yaserde(rename = "PowerStatusLink")]
pub power_status_link: Option<PowerStatusLink>,
#[yaserde(rename = "sFDI")]
pub sfdi: SFDIType,
#[yaserde(attribute, rename = "subscribable")]
pub subscribable: Option<SubscribableType>,
#[yaserde(attribute, rename = "href")]
pub href: Option<String>,
}
impl Validate for SelfDevice {}
#[derive(Default, PartialEq, Eq, Debug, Clone, YaSerialize, YaDeserialize)]
#[yaserde(rename = "Temperature")]
#[yaserde(namespace = "urn:ieee:std:2030.5:ns")]
pub struct Temperature {
#[yaserde(rename = "multiplier")]
pub multiplier: PowerOfTenMultiplierType,
#[yaserde(rename = "subject")]
pub subject: Uint8,
#[yaserde(rename = "value")]
pub value: Int16,
}
impl Validate for Temperature {}
#[cfg(not(feature = "csip_aus"))]
#[test]
fn csip_aus_edev_no_namespace() {
let expected = r#"<EndDevice xmlns="urn:ieee:std:2030.5:ns">
<changedTime>0</changedTime>
<sFDI>0</sFDI>
</EndDevice>"#;
let edev = EndDevice::default();
let out = serialize(&edev).unwrap();
assert_eq!(expected, out);
}
#[cfg(feature = "csip_aus")]
#[test]
fn csip_aus_edev_namespace() {
let expected = r#"<EndDevice xmlns="urn:ieee:std:2030.5:ns" xmlns:csipaus="https://csipaus.org/ns">
<changedTime>0</changedTime>
<sFDI>0</sFDI>
</EndDevice>"#;
let edev = EndDevice::default();
let out = serialize(&edev).unwrap();
assert_eq!(expected, out);
}