1use alloc::string::String;
9use alloc::vec::Vec;
10
11use bon::Builder;
12use serde::{Deserialize, Serialize};
13
14use super::{Duration, Id, ProtocolVersion, Timestamp};
15
16#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
24#[serde(rename_all = "UPPERCASE")]
25#[non_exhaustive]
26pub enum Commodity {
27 Gas,
29 Heat,
31 Electricity,
33 Oil,
35}
36
37#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
45#[non_exhaustive]
46pub enum CommodityQuantity {
47 #[serde(rename = "ELECTRIC.POWER.L1")]
49 ElectricPowerL1,
50 #[serde(rename = "ELECTRIC.POWER.L2")]
52 ElectricPowerL2,
53 #[serde(rename = "ELECTRIC.POWER.L3")]
55 ElectricPowerL3,
56 #[serde(rename = "ELECTRIC.POWER.3_PHASE_SYMMETRIC")]
58 ElectricPower3PhaseSymmetric,
59 #[serde(rename = "NATURAL_GAS.FLOW_RATE")]
61 NaturalGasFlowRate,
62 #[serde(rename = "HYDROGEN.FLOW_RATE")]
64 HydrogenFlowRate,
65 #[serde(rename = "HEAT.TEMPERATURE")]
67 HeatTemperature,
68 #[serde(rename = "HEAT.FLOW_RATE")]
70 HeatFlowRate,
71 #[serde(rename = "HEAT.THERMAL_POWER")]
73 HeatThermalPower,
74 #[serde(rename = "OIL.FLOW_RATE")]
76 OilFlowRate,
77}
78
79impl CommodityQuantity {
80 #[must_use]
82 pub const fn commodity(self) -> Commodity {
83 match self {
84 Self::ElectricPowerL1
85 | Self::ElectricPowerL2
86 | Self::ElectricPowerL3
87 | Self::ElectricPower3PhaseSymmetric => Commodity::Electricity,
88 Self::NaturalGasFlowRate | Self::HydrogenFlowRate => Commodity::Gas,
89 Self::HeatTemperature | Self::HeatFlowRate | Self::HeatThermalPower => Commodity::Heat,
90 Self::OilFlowRate => Commodity::Oil,
91 }
92 }
93
94 #[must_use]
96 pub const fn is_per_phase_electric(self) -> bool {
97 matches!(
98 self,
99 Self::ElectricPowerL1 | Self::ElectricPowerL2 | Self::ElectricPowerL3
100 )
101 }
102
103 #[must_use]
108 pub const fn is_power(self) -> bool {
109 !matches!(self, Self::HeatTemperature)
110 }
111
112 #[must_use]
127 pub const fn unit(self) -> &'static str {
128 match self {
129 Self::ElectricPowerL1
130 | Self::ElectricPowerL2
131 | Self::ElectricPowerL3
132 | Self::ElectricPower3PhaseSymmetric
133 | Self::HeatThermalPower => "W",
134 Self::NaturalGasFlowRate | Self::HeatFlowRate => "l/s",
135 Self::HydrogenFlowRate => "g/s",
136 Self::HeatTemperature => "°C",
137 Self::OilFlowRate => "l/h",
138 }
139 }
140
141 #[must_use]
143 pub const fn as_str(self) -> &'static str {
144 match self {
145 Self::ElectricPowerL1 => "ELECTRIC.POWER.L1",
146 Self::ElectricPowerL2 => "ELECTRIC.POWER.L2",
147 Self::ElectricPowerL3 => "ELECTRIC.POWER.L3",
148 Self::ElectricPower3PhaseSymmetric => "ELECTRIC.POWER.3_PHASE_SYMMETRIC",
149 Self::NaturalGasFlowRate => "NATURAL_GAS.FLOW_RATE",
150 Self::HydrogenFlowRate => "HYDROGEN.FLOW_RATE",
151 Self::HeatTemperature => "HEAT.TEMPERATURE",
152 Self::HeatFlowRate => "HEAT.FLOW_RATE",
153 Self::HeatThermalPower => "HEAT.THERMAL_POWER",
154 Self::OilFlowRate => "OIL.FLOW_RATE",
155 }
156 }
157}
158
159#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
166#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
167#[non_exhaustive]
168pub enum ControlType {
169 PowerEnvelopeBasedControl,
172 PowerProfileBasedControl,
175 OperationModeBasedControl,
178 FillRateBasedControl,
181 DemandDrivenBasedControl,
184 #[serde(rename = "NOT_CONTROLABLE")]
189 NotControllable,
190 NoSelection,
192}
193
194impl ControlType {
195 #[must_use]
198 pub const fn is_controllable(self) -> bool {
199 matches!(
200 self,
201 Self::PowerEnvelopeBasedControl
202 | Self::PowerProfileBasedControl
203 | Self::OperationModeBasedControl
204 | Self::FillRateBasedControl
205 | Self::DemandDrivenBasedControl
206 )
207 }
208
209 #[must_use]
214 pub const fn uses_operation_modes(self) -> bool {
215 matches!(
216 self,
217 Self::OperationModeBasedControl
218 | Self::FillRateBasedControl
219 | Self::DemandDrivenBasedControl
220 )
221 }
222
223 #[must_use]
225 pub const fn abbreviation(self) -> Option<&'static str> {
226 match self {
227 Self::PowerEnvelopeBasedControl => Some("PEBC"),
228 Self::PowerProfileBasedControl => Some("PPBC"),
229 Self::OperationModeBasedControl => Some("OMBC"),
230 Self::FillRateBasedControl => Some("FRBC"),
231 Self::DemandDrivenBasedControl => Some("DDBC"),
232 Self::NotControllable | Self::NoSelection => None,
233 }
234 }
235}
236
237#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
243#[serde(rename_all = "UPPERCASE")]
244#[non_exhaustive]
245#[allow(missing_docs)] pub enum Currency {
247 Aed,
248 Ang,
249 Aud,
250 Che,
251 Chf,
252 Chw,
253 Eur,
254 Gbp,
255 Lbp,
256 Lkr,
257 Lrd,
258 Lsl,
259 Lyd,
260 Mad,
261 Mdl,
262 Mga,
263 Mkd,
264 Mmk,
265 Mnt,
266 Mop,
267 Mro,
268 Mur,
269 Mvr,
270 Mwk,
271 Mxn,
272 Mxv,
273 Myr,
274 Mzn,
275 Nad,
276 Ngn,
277 Nio,
278 Nok,
279 Npr,
280 Nzd,
281 Omr,
282 Pab,
283 Pen,
284 Pgk,
285 Php,
286 Pkr,
287 Pln,
288 Pyg,
289 Qar,
290 Ron,
291 Rsd,
292 Rub,
293 Rwf,
294 Sar,
295 Sbd,
296 Scr,
297 Sdg,
298 Sek,
299 Sgd,
300 Shp,
301 Sll,
302 Sos,
303 Srd,
304 Ssp,
305 Std,
306 Syp,
307 Szl,
308 Thb,
309 Tjs,
310 Tmt,
311 Tnd,
312 Top,
313 Try,
314 Ttd,
315 Twd,
316 Tzs,
317 Uah,
318 Ugx,
319 Usd,
320 Usn,
321 Uyi,
322 Uyu,
323 Uzs,
324 Vef,
325 Vnd,
326 Vuv,
327 Wst,
328 Xag,
329 Xau,
330 Xba,
331 Xbb,
332 Xbc,
333 Xbd,
334 Xcd,
335 Xof,
336 Xpd,
337 Xpf,
338 Xpt,
339 Xsu,
340 Xts,
341 Xua,
342 Xxx,
343 Yer,
344 Zar,
345 Zmw,
346 Zwl,
347}
348
349#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
351#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
352pub enum EnergyManagementRole {
353 Cem,
355 Rm,
357}
358
359impl EnergyManagementRole {
360 #[must_use]
362 pub const fn peer(self) -> Self {
363 match self {
364 Self::Cem => Self::Rm,
365 Self::Rm => Self::Cem,
366 }
367 }
368}
369
370#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
376#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
377#[non_exhaustive]
378pub enum InstructionStatus {
379 New,
381 Accepted,
383 Rejected,
385 Revoked,
387 Started,
389 Succeeded,
391 Aborted,
393}
394
395impl InstructionStatus {
396 #[must_use]
398 pub const fn is_terminal(self) -> bool {
399 matches!(
400 self,
401 Self::Rejected | Self::Revoked | Self::Succeeded | Self::Aborted
402 )
403 }
404
405 #[must_use]
407 pub const fn progress_rank(self) -> u8 {
408 match self {
409 Self::New => 0,
410 Self::Accepted => 1,
411 Self::Started => 2,
412 Self::Succeeded | Self::Rejected | Self::Revoked | Self::Aborted => 3,
413 }
414 }
415}
416
417#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
422#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
423#[non_exhaustive]
424pub enum ReceptionStatusValues {
425 InvalidData,
427 InvalidMessage,
429 InvalidContent,
432 TemporaryError,
434 PermanentError,
436 Ok,
438}
439
440#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
442pub enum Consequence {
443 Proceed,
445 Ignored,
447 Retry,
449 Disconnect,
451}
452
453impl ReceptionStatusValues {
454 #[must_use]
456 pub const fn consequence(self) -> Consequence {
457 match self {
458 Self::Ok => Consequence::Proceed,
459 Self::InvalidData | Self::InvalidMessage | Self::InvalidContent => Consequence::Ignored,
460 Self::TemporaryError => Consequence::Retry,
461 Self::PermanentError => Consequence::Disconnect,
462 }
463 }
464
465 #[must_use]
467 pub const fn is_error(self) -> bool {
468 !matches!(self, Self::Ok)
469 }
470}
471
472#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
474#[non_exhaustive]
475pub enum RevokableObjects {
476 #[serde(rename = "PEBC.PowerConstraints")]
478 PebcPowerConstraints,
479 #[serde(rename = "PEBC.EnergyConstraint")]
481 PebcEnergyConstraint,
482 #[serde(rename = "PEBC.Instruction")]
484 PebcInstruction,
485 #[serde(rename = "PPBC.PowerProfileDefinition")]
487 PpbcPowerProfileDefinition,
488 #[serde(rename = "PPBC.ScheduleInstruction")]
490 PpbcScheduleInstruction,
491 #[serde(rename = "PPBC.StartInterruptionInstruction")]
493 PpbcStartInterruptionInstruction,
494 #[serde(rename = "PPBC.EndInterruptionInstruction")]
496 PpbcEndInterruptionInstruction,
497 #[serde(rename = "OMBC.SystemDescription")]
499 OmbcSystemDescription,
500 #[serde(rename = "OMBC.Instruction")]
502 OmbcInstruction,
503 #[serde(rename = "FRBC.SystemDescription")]
505 FrbcSystemDescription,
506 #[serde(rename = "FRBC.Instruction")]
508 FrbcInstruction,
509 #[serde(rename = "DDBC.SystemDescription")]
511 DdbcSystemDescription,
512 #[serde(rename = "DDBC.Instruction")]
514 DdbcInstruction,
515}
516
517impl RevokableObjects {
518 #[must_use]
524 pub const fn owner(self) -> EnergyManagementRole {
525 match self {
526 Self::PebcInstruction
527 | Self::PpbcScheduleInstruction
528 | Self::PpbcStartInterruptionInstruction
529 | Self::PpbcEndInterruptionInstruction
530 | Self::OmbcInstruction
531 | Self::FrbcInstruction
532 | Self::DdbcInstruction => EnergyManagementRole::Cem,
533 Self::PebcPowerConstraints
534 | Self::PebcEnergyConstraint
535 | Self::PpbcPowerProfileDefinition
536 | Self::OmbcSystemDescription
537 | Self::FrbcSystemDescription
538 | Self::DdbcSystemDescription => EnergyManagementRole::Rm,
539 }
540 }
541
542 #[must_use]
544 pub const fn control_type(self) -> ControlType {
545 match self {
546 Self::PebcPowerConstraints | Self::PebcEnergyConstraint | Self::PebcInstruction => {
547 ControlType::PowerEnvelopeBasedControl
548 }
549 Self::PpbcPowerProfileDefinition
550 | Self::PpbcScheduleInstruction
551 | Self::PpbcStartInterruptionInstruction
552 | Self::PpbcEndInterruptionInstruction => ControlType::PowerProfileBasedControl,
553 Self::OmbcSystemDescription | Self::OmbcInstruction => {
554 ControlType::OperationModeBasedControl
555 }
556 Self::FrbcSystemDescription | Self::FrbcInstruction => {
557 ControlType::FillRateBasedControl
558 }
559 Self::DdbcSystemDescription | Self::DdbcInstruction => {
560 ControlType::DemandDrivenBasedControl
561 }
562 }
563 }
564}
565
566#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
568#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
569pub enum RoleType {
570 EnergyProducer,
572 EnergyConsumer,
574 EnergyStorage,
576}
577
578#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
580#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
581pub enum SessionRequestType {
582 Reconnect,
585 Terminate,
588}
589
590#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
601#[serde(deny_unknown_fields)]
602pub struct NumberRange {
603 pub start_of_range: f64,
605 pub end_of_range: f64,
607}
608
609impl NumberRange {
610 #[must_use]
612 pub const fn new(start: f64, end: f64) -> Self {
613 Self {
614 start_of_range: start,
615 end_of_range: end,
616 }
617 }
618
619 #[must_use]
621 pub const fn exactly(value: f64) -> Self {
622 Self::new(value, value)
623 }
624
625 #[must_use]
627 pub fn contains(self, value: f64) -> bool {
628 let (lo, hi) = self.ordered();
629 value >= lo && value <= hi
630 }
631
632 #[must_use]
634 pub fn ordered(self) -> (f64, f64) {
635 if self.start_of_range <= self.end_of_range {
636 (self.start_of_range, self.end_of_range)
637 } else {
638 (self.end_of_range, self.start_of_range)
639 }
640 }
641
642 #[must_use]
644 pub fn span(self) -> f64 {
645 self.end_of_range - self.start_of_range
646 }
647
648 #[must_use]
656 #[allow(
657 clippy::float_cmp,
658 reason = "0 and 1 are the endpoints, not approximations"
659 )]
660 pub fn at_factor(self, factor: f64) -> f64 {
661 if factor == 0.0 {
662 self.start_of_range
663 } else if factor == 1.0 {
664 self.end_of_range
665 } else {
666 self.start_of_range + self.span() * factor
667 }
668 }
669
670 #[must_use]
675 pub fn factor_of(self, value: f64) -> Option<f64> {
676 let span = self.span();
677 if span == 0.0 {
678 None
679 } else {
680 Some((value - self.start_of_range) / span)
681 }
682 }
683
684 #[must_use]
686 pub fn is_finite(self) -> bool {
687 self.start_of_range.is_finite() && self.end_of_range.is_finite()
688 }
689
690 #[must_use]
692 pub fn overlaps(self, other: Self) -> bool {
693 let (a_lo, a_hi) = self.ordered();
694 let (b_lo, b_hi) = other.ordered();
695 a_lo < b_hi && b_lo < a_hi
696 }
697}
698
699impl From<core::ops::Range<f64>> for NumberRange {
700 fn from(r: core::ops::Range<f64>) -> Self {
701 Self::new(r.start, r.end)
702 }
703}
704
705impl From<NumberRange> for core::ops::Range<f64> {
706 fn from(r: NumberRange) -> Self {
707 r.start_of_range..r.end_of_range
708 }
709}
710
711#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
716#[serde(deny_unknown_fields)]
717pub struct PowerRange {
718 pub start_of_range: f64,
720 pub end_of_range: f64,
722 pub commodity_quantity: CommodityQuantity,
724}
725
726impl PowerRange {
727 #[must_use]
729 pub const fn new(start: f64, end: f64, commodity_quantity: CommodityQuantity) -> Self {
730 Self {
731 start_of_range: start,
732 end_of_range: end,
733 commodity_quantity,
734 }
735 }
736
737 #[must_use]
739 pub const fn exactly(value: f64, commodity_quantity: CommodityQuantity) -> Self {
740 Self::new(value, value, commodity_quantity)
741 }
742
743 #[must_use]
745 pub const fn range(self) -> NumberRange {
746 NumberRange::new(self.start_of_range, self.end_of_range)
747 }
748
749 #[must_use]
751 pub fn at_factor(self, factor: f64) -> f64 {
752 self.range().at_factor(factor)
753 }
754}
755
756#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
758#[serde(deny_unknown_fields)]
759pub struct PowerValue {
760 pub commodity_quantity: CommodityQuantity,
762 pub value: f64,
764}
765
766impl PowerValue {
767 #[must_use]
769 pub const fn new(commodity_quantity: CommodityQuantity, value: f64) -> Self {
770 Self {
771 commodity_quantity,
772 value,
773 }
774 }
775}
776
777#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Builder)]
783#[serde(deny_unknown_fields)]
784pub struct PowerForecastValue {
785 #[serde(skip_serializing_if = "Option::is_none")]
787 pub value_upper_limit: Option<f64>,
788 #[serde(rename = "value_upper_95PPR", skip_serializing_if = "Option::is_none")]
790 pub value_upper_95ppr: Option<f64>,
791 #[serde(rename = "value_upper_68PPR", skip_serializing_if = "Option::is_none")]
793 pub value_upper_68ppr: Option<f64>,
794 pub value_expected: f64,
796 #[serde(rename = "value_lower_68PPR", skip_serializing_if = "Option::is_none")]
798 pub value_lower_68ppr: Option<f64>,
799 #[serde(rename = "value_lower_95PPR", skip_serializing_if = "Option::is_none")]
801 pub value_lower_95ppr: Option<f64>,
802 #[serde(skip_serializing_if = "Option::is_none")]
804 pub value_lower_limit: Option<f64>,
805 pub commodity_quantity: CommodityQuantity,
807}
808
809impl PowerForecastValue {
810 #[must_use]
812 pub const fn expected(value: f64, commodity_quantity: CommodityQuantity) -> Self {
813 Self {
814 value_upper_limit: None,
815 value_upper_95ppr: None,
816 value_upper_68ppr: None,
817 value_expected: value,
818 value_lower_68ppr: None,
819 value_lower_95ppr: None,
820 value_lower_limit: None,
821 commodity_quantity,
822 }
823 }
824
825 #[must_use]
829 pub fn bands_ascending(&self) -> [(&'static str, Option<f64>); 7] {
830 [
831 ("value_lower_limit", self.value_lower_limit),
832 ("value_lower_95PPR", self.value_lower_95ppr),
833 ("value_lower_68PPR", self.value_lower_68ppr),
834 ("value_expected", Some(self.value_expected)),
835 ("value_upper_68PPR", self.value_upper_68ppr),
836 ("value_upper_95PPR", self.value_upper_95ppr),
837 ("value_upper_limit", self.value_upper_limit),
838 ]
839 }
840}
841
842#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
844#[serde(deny_unknown_fields)]
845pub struct PowerForecastElement {
846 pub duration: Duration,
848 pub power_values: Vec<PowerForecastValue>,
850}
851
852#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
854#[serde(deny_unknown_fields)]
855pub struct Role {
856 pub role: RoleType,
858 pub commodity: Commodity,
860}
861
862impl Role {
863 #[must_use]
865 pub const fn new(role: RoleType, commodity: Commodity) -> Self {
866 Self { role, commodity }
867 }
868}
869
870#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Builder)]
872#[serde(deny_unknown_fields)]
873#[builder(on(String, into))]
874pub struct Timer {
875 pub id: Id,
877 #[serde(skip_serializing_if = "Option::is_none")]
879 pub diagnostic_label: Option<String>,
880 pub duration: Duration,
882}
883
884#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Builder)]
886#[serde(deny_unknown_fields)]
887pub struct Transition {
888 pub id: Id,
890 pub from: Id,
892 pub to: Id,
894 pub start_timers: Vec<Id>,
896 pub blocking_timers: Vec<Id>,
898 #[serde(skip_serializing_if = "Option::is_none")]
900 pub transition_costs: Option<f64>,
901 #[serde(skip_serializing_if = "Option::is_none")]
904 pub transition_duration: Option<Duration>,
905 pub abnormal_condition_only: bool,
907}
908
909impl Transition {
910 #[must_use]
912 pub fn simple(id: Id, from: Id, to: Id) -> Self {
913 Self {
914 id,
915 from,
916 to,
917 start_timers: Vec::new(),
918 blocking_timers: Vec::new(),
919 transition_costs: None,
920 transition_duration: None,
921 abnormal_condition_only: false,
922 }
923 }
924}
925
926#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Builder)]
936#[serde(deny_unknown_fields)]
937pub struct Handshake {
938 #[cfg_attr(feature = "uuid", builder(default = Id::generate()))]
940 pub message_id: Id,
941 pub role: EnergyManagementRole,
943 #[serde(skip_serializing_if = "Option::is_none")]
946 pub supported_protocol_versions: Option<Vec<ProtocolVersion>>,
947}
948
949#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Builder)]
951#[serde(deny_unknown_fields)]
952pub struct HandshakeResponse {
953 #[cfg_attr(feature = "uuid", builder(default = Id::generate()))]
955 pub message_id: Id,
956 pub selected_protocol_version: ProtocolVersion,
958}
959
960#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Builder)]
962#[serde(deny_unknown_fields)]
963#[builder(on(String, into))]
964pub struct ResourceManagerDetails {
965 #[cfg_attr(feature = "uuid", builder(default = Id::generate()))]
967 pub message_id: Id,
968 pub resource_id: Id,
970 #[serde(skip_serializing_if = "Option::is_none")]
972 pub name: Option<String>,
973 pub roles: Vec<Role>,
975 #[serde(skip_serializing_if = "Option::is_none")]
977 pub manufacturer: Option<String>,
978 #[serde(skip_serializing_if = "Option::is_none")]
980 pub model: Option<String>,
981 #[serde(skip_serializing_if = "Option::is_none")]
983 pub serial_number: Option<String>,
984 #[serde(skip_serializing_if = "Option::is_none")]
986 pub firmware_version: Option<String>,
987 pub instruction_processing_delay: Duration,
989 pub available_control_types: Vec<ControlType>,
991 #[serde(skip_serializing_if = "Option::is_none")]
993 pub currency: Option<Currency>,
994 pub provides_forecast: bool,
996 pub provides_power_measurement_types: Vec<CommodityQuantity>,
998}
999
1000#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Builder)]
1002#[serde(deny_unknown_fields)]
1003pub struct SelectControlType {
1004 #[cfg_attr(feature = "uuid", builder(default = Id::generate()))]
1006 pub message_id: Id,
1007 pub control_type: ControlType,
1009}
1010
1011#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Builder)]
1013#[serde(deny_unknown_fields)]
1014#[builder(on(String, into))]
1015pub struct SessionRequest {
1016 #[cfg_attr(feature = "uuid", builder(default = Id::generate()))]
1018 pub message_id: Id,
1019 pub request: SessionRequestType,
1021 #[serde(skip_serializing_if = "Option::is_none")]
1023 pub diagnostic_label: Option<String>,
1024}
1025
1026#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Builder)]
1031#[serde(deny_unknown_fields)]
1032#[builder(on(String, into))]
1033pub struct ReceptionStatus {
1034 pub subject_message_id: Id,
1036 pub status: ReceptionStatusValues,
1038 #[serde(skip_serializing_if = "Option::is_none")]
1042 pub diagnostic_label: Option<String>,
1043}
1044
1045impl ReceptionStatus {
1046 #[must_use]
1048 pub fn ok(subject: Id) -> Self {
1049 Self {
1050 subject_message_id: subject,
1051 status: ReceptionStatusValues::Ok,
1052 diagnostic_label: None,
1053 }
1054 }
1055
1056 #[must_use]
1058 pub fn error(
1059 subject: Id,
1060 status: ReceptionStatusValues,
1061 diagnostic: impl Into<String>,
1062 ) -> Self {
1063 Self {
1064 subject_message_id: subject,
1065 status,
1066 diagnostic_label: Some(diagnostic.into()),
1067 }
1068 }
1069}
1070
1071#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Builder)]
1076#[serde(deny_unknown_fields)]
1077pub struct InstructionStatusUpdate {
1078 #[cfg_attr(feature = "uuid", builder(default = Id::generate()))]
1080 pub message_id: Id,
1081 pub instruction_id: Id,
1083 pub status_type: InstructionStatus,
1085 pub timestamp: Timestamp,
1087}
1088
1089#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Builder)]
1091#[serde(deny_unknown_fields)]
1092pub struct PowerMeasurement {
1093 #[cfg_attr(feature = "uuid", builder(default = Id::generate()))]
1095 pub message_id: Id,
1096 pub measurement_timestamp: Timestamp,
1098 pub values: Vec<PowerValue>,
1100}
1101
1102#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Builder)]
1104#[serde(deny_unknown_fields)]
1105pub struct PowerForecast {
1106 #[cfg_attr(feature = "uuid", builder(default = Id::generate()))]
1108 pub message_id: Id,
1109 pub start_time: Timestamp,
1111 pub elements: Vec<PowerForecastElement>,
1113}
1114
1115#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Builder)]
1117#[serde(deny_unknown_fields)]
1118pub struct RevokeObject {
1119 #[cfg_attr(feature = "uuid", builder(default = Id::generate()))]
1121 pub message_id: Id,
1122 pub object_type: RevokableObjects,
1124 pub object_id: Id,
1126}
1127
1128#[cfg(test)]
1129mod tests {
1130 use super::*;
1131
1132 #[test]
1133 fn control_type_wire_spellings_are_the_standards_own() {
1134 for (value, wire) in [
1136 (
1137 ControlType::PowerEnvelopeBasedControl,
1138 "\"POWER_ENVELOPE_BASED_CONTROL\"",
1139 ),
1140 (
1141 ControlType::PowerProfileBasedControl,
1142 "\"POWER_PROFILE_BASED_CONTROL\"",
1143 ),
1144 (
1145 ControlType::OperationModeBasedControl,
1146 "\"OPERATION_MODE_BASED_CONTROL\"",
1147 ),
1148 (
1149 ControlType::FillRateBasedControl,
1150 "\"FILL_RATE_BASED_CONTROL\"",
1151 ),
1152 (
1153 ControlType::DemandDrivenBasedControl,
1154 "\"DEMAND_DRIVEN_BASED_CONTROL\"",
1155 ),
1156 (ControlType::NotControllable, "\"NOT_CONTROLABLE\""),
1157 (ControlType::NoSelection, "\"NO_SELECTION\""),
1158 ] {
1159 assert_eq!(serde_json::to_string(&value).unwrap(), wire);
1160 assert_eq!(serde_json::from_str::<ControlType>(wire).unwrap(), value);
1161 }
1162 assert!(serde_json::from_str::<ControlType>("\"NOT_CONTROLLABLE\"").is_err());
1164 }
1165
1166 #[test]
1167 fn commodity_quantity_wire_spellings() {
1168 for (value, wire) in [
1169 (CommodityQuantity::ElectricPowerL1, "\"ELECTRIC.POWER.L1\""),
1170 (
1171 CommodityQuantity::ElectricPower3PhaseSymmetric,
1172 "\"ELECTRIC.POWER.3_PHASE_SYMMETRIC\"",
1173 ),
1174 (
1175 CommodityQuantity::NaturalGasFlowRate,
1176 "\"NATURAL_GAS.FLOW_RATE\"",
1177 ),
1178 (
1179 CommodityQuantity::HeatThermalPower,
1180 "\"HEAT.THERMAL_POWER\"",
1181 ),
1182 (CommodityQuantity::OilFlowRate, "\"OIL.FLOW_RATE\""),
1183 ] {
1184 assert_eq!(serde_json::to_string(&value).unwrap(), wire);
1185 assert_eq!(
1186 serde_json::from_str::<CommodityQuantity>(wire).unwrap(),
1187 value
1188 );
1189 }
1190 }
1191
1192 #[test]
1193 fn revokable_objects_keep_their_dots() {
1194 assert_eq!(
1195 serde_json::to_string(&RevokableObjects::FrbcInstruction).unwrap(),
1196 "\"FRBC.Instruction\""
1197 );
1198 assert_eq!(
1200 RevokableObjects::FrbcInstruction.owner(),
1201 EnergyManagementRole::Cem
1202 );
1203 assert_eq!(
1204 RevokableObjects::FrbcSystemDescription.owner(),
1205 EnergyManagementRole::Rm
1206 );
1207 }
1208
1209 #[test]
1210 fn currency_codes_are_uppercase() {
1211 assert_eq!(serde_json::to_string(&Currency::Eur).unwrap(), "\"EUR\"");
1212 assert_eq!(
1213 serde_json::from_str::<Currency>("\"XXX\"").unwrap(),
1214 Currency::Xxx
1215 );
1216 }
1217
1218 #[test]
1219 fn reception_status_consequences_are_the_normative_ones() {
1220 use Consequence as C;
1221 use ReceptionStatusValues as R;
1222 assert_eq!(R::Ok.consequence(), C::Proceed);
1223 assert_eq!(R::InvalidData.consequence(), C::Ignored);
1224 assert_eq!(R::InvalidMessage.consequence(), C::Ignored);
1225 assert_eq!(R::InvalidContent.consequence(), C::Ignored);
1226 assert_eq!(R::TemporaryError.consequence(), C::Retry);
1227 assert_eq!(R::PermanentError.consequence(), C::Disconnect);
1228 }
1229
1230 #[test]
1231 fn factor_interpolation_matches_the_documented_formula() {
1232 let r = NumberRange::new(1000.0, 2500.0);
1235 assert!((r.at_factor(0.5) - 1750.0).abs() < 1e-9);
1236 assert!((r.at_factor(0.0) - 1000.0).abs() < 1e-9);
1237 assert!((r.at_factor(1.0) - 2500.0).abs() < 1e-9);
1238 assert!((r.factor_of(1750.0).unwrap() - 0.5).abs() < 1e-9);
1239 assert_eq!(NumberRange::exactly(0.0).factor_of(0.0), None);
1242 assert!((NumberRange::exactly(7.0).at_factor(0.3) - 7.0).abs() < 1e-12);
1243 }
1244
1245 #[test]
1246 fn unknown_fields_are_refused() {
1247 let json = r#"{"start_of_range":0,"end_of_range":1,"extra":true}"#;
1248 assert!(serde_json::from_str::<NumberRange>(json).is_err());
1249 }
1250
1251 #[test]
1252 fn absent_optionals_are_absent_rather_than_null() {
1253 let v = PowerForecastValue::expected(-3450.1, CommodityQuantity::ElectricPowerL1);
1254 let json = serde_json::to_string(&v).unwrap();
1255 assert_eq!(
1256 json,
1257 r#"{"value_expected":-3450.1,"commodity_quantity":"ELECTRIC.POWER.L1"}"#
1258 );
1259 }
1260
1261 #[test]
1262 fn percentile_bands_keep_their_capitalised_wire_names() {
1263 let json = r#"{
1264 "value_upper_limit": -3400.0, "value_upper_95PPR": -3440.0,
1265 "value_upper_68PPR": -3445.0, "value_expected": -3450.1,
1266 "value_lower_68PPR": -3455.0, "value_lower_95PPR": -3460.0,
1267 "value_lower_limit": -3500.0, "commodity_quantity": "ELECTRIC.POWER.L1"
1268 }"#;
1269 let v: PowerForecastValue = serde_json::from_str(json).unwrap();
1270 assert_eq!(v.value_upper_95ppr, Some(-3440.0));
1271 assert_eq!(v.value_lower_68ppr, Some(-3455.0));
1272 let back = serde_json::to_string(&v).unwrap();
1273 assert!(back.contains("\"value_upper_95PPR\":-3440.0"));
1274 }
1275}