Skip to main content

cimstructs/
PowerElectronicsUnit.rs

1/// A generating unit or battery or aggregation that connects to the AC network using power electronics rather than rotating machines.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct PowerElectronicsUnit {
4    #[serde(flatten)]
5    pub base: super::Equipment,
6    /// Maximum active power limit. This is the maximum (nameplate) limit for the unit.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub max_p: Option<f64>,
9    /// Minimum active power limit. This is the minimum (nameplate) limit for the unit.
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub min_p: Option<f64>,
12}
13impl crate::base::CimElement for PowerElectronicsUnit {
14    fn mrid(&self) -> &str { &self.base.base.base.id }
15    fn type_name(&self) -> &'static str { "PowerElectronicsUnit" }
16    fn as_any(&self) -> &dyn std::any::Any { self }
17    fn to_json_value(&self) -> serde_json::Value {
18        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
19    }
20    fn to_block(&self) -> crate::base::RdfBlock {
21        let mut block = self.base.to_block();
22        block.type_name = "PowerElectronicsUnit".to_string();
23        if let Some(v) = self.max_p {
24            block.fields.insert("PowerElectronicsUnit.maxP".into(), crate::base::FieldValue::Text(v.to_string()));
25        }
26        if let Some(v) = self.min_p {
27            block.fields.insert("PowerElectronicsUnit.minP".into(), crate::base::FieldValue::Text(v.to_string()));
28        }
29        block
30    }
31}
32
33impl PowerElectronicsUnit {
34    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
35        let mut obj = Self::default();
36        obj.base.base.base.id.clone_from(&b.mrid);
37        for (key, val) in &b.fields {
38            match key.as_str() {
39                "PowerElectronicsUnit.maxP" => {
40                    match val {
41                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.max_p = Some(v); } }
42                        crate::base::FieldValue::TextList(svs) => {
43                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.max_p = Some(v); } }
44                        }
45                        _ => {}
46                    }
47                }
48                "PowerElectronicsUnit.minP" => {
49                    match val {
50                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.min_p = Some(v); } }
51                        crate::base::FieldValue::TextList(svs) => {
52                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.min_p = Some(v); } }
53                        }
54                        _ => {}
55                    }
56                }
57                "Equipment.EquipmentContainer" => {
58                    if let crate::base::FieldValue::Resource(sv) = val {
59                        obj.base.equipment_container = Some(crate::base::MridRef { mrid: sv.clone() });
60                    }
61                }
62                "Equipment.aggregate" => {
63                    match val {
64                        crate::base::FieldValue::Text(sv) => { obj.base.aggregate = Some(sv.trim() == "true"); }
65                        crate::base::FieldValue::TextList(svs) => {
66                            if let Some(sv) = svs.last() { obj.base.aggregate = Some(sv.trim() == "true"); }
67                        }
68                        _ => {}
69                    }
70                }
71                "Equipment.inService" => {
72                    match val {
73                        crate::base::FieldValue::Text(sv) => { obj.base.in_service = Some(sv.trim() == "true"); }
74                        crate::base::FieldValue::TextList(svs) => {
75                            if let Some(sv) = svs.last() { obj.base.in_service = Some(sv.trim() == "true"); }
76                        }
77                        _ => {}
78                    }
79                }
80                "Equipment.normallyInService" => {
81                    match val {
82                        crate::base::FieldValue::Text(sv) => { obj.base.normally_in_service = Some(sv.trim() == "true"); }
83                        crate::base::FieldValue::TextList(svs) => {
84                            if let Some(sv) = svs.last() { obj.base.normally_in_service = Some(sv.trim() == "true"); }
85                        }
86                        _ => {}
87                    }
88                }
89                "IdentifiedObject.description" => {
90                    match val {
91                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.description = sv.clone(); }
92                        crate::base::FieldValue::TextList(svs) => {
93                            if let Some(sv) = svs.last() { obj.base.base.base.description = sv.clone(); }
94                        }
95                        _ => {}
96                    }
97                }
98                "IdentifiedObject.energyIdentCodeEic" => {
99                    match val {
100                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.energy_ident_code_eic = sv.clone(); }
101                        crate::base::FieldValue::TextList(svs) => {
102                            if let Some(sv) = svs.last() { obj.base.base.base.energy_ident_code_eic = sv.clone(); }
103                        }
104                        _ => {}
105                    }
106                }
107                "IdentifiedObject.mRID" => {
108                    match val {
109                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.m_rid = sv.clone(); }
110                        crate::base::FieldValue::TextList(svs) => {
111                            if let Some(sv) = svs.last() { obj.base.base.base.m_rid = sv.clone(); }
112                        }
113                        _ => {}
114                    }
115                }
116                "IdentifiedObject.name" => {
117                    match val {
118                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.name = sv.clone(); }
119                        crate::base::FieldValue::TextList(svs) => {
120                            if let Some(sv) = svs.last() { obj.base.base.base.name = sv.clone(); }
121                        }
122                        _ => {}
123                    }
124                }
125                "IdentifiedObject.shortName" => {
126                    match val {
127                        crate::base::FieldValue::Text(sv) => { obj.base.base.base.short_name = sv.clone(); }
128                        crate::base::FieldValue::TextList(svs) => {
129                            if let Some(sv) = svs.last() { obj.base.base.base.short_name = sv.clone(); }
130                        }
131                        _ => {}
132                    }
133                }
134                _ => {}
135            }
136        }
137        obj
138    }
139}