Skip to main content

cimstructs/
ApparentPowerLimit.rs

1/// Apparent power limit.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct ApparentPowerLimit {
4    #[serde(flatten)]
5    pub base: super::OperationalLimit,
6    /// The normal apparent power limit. The attribute shall be a positive value or zero.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub normal_value: Option<f64>,
9    /// The apparent power limit. The attribute shall be a positive value or zero.
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub value: Option<f64>,
12}
13impl crate::base::CimElement for ApparentPowerLimit {
14    fn mrid(&self) -> &str { &self.base.base.id }
15    fn type_name(&self) -> &'static str { "ApparentPowerLimit" }
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 = "ApparentPowerLimit".to_string();
23        if let Some(v) = self.normal_value {
24            block.fields.insert("ApparentPowerLimit.normalValue".into(), crate::base::FieldValue::Text(v.to_string()));
25        }
26        if let Some(v) = self.value {
27            block.fields.insert("ApparentPowerLimit.value".into(), crate::base::FieldValue::Text(v.to_string()));
28        }
29        block
30    }
31}
32
33impl ApparentPowerLimit {
34    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
35        let mut obj = Self::default();
36        obj.base.base.id.clone_from(&b.mrid);
37        for (key, val) in &b.fields {
38            match key.as_str() {
39                "ApparentPowerLimit.normalValue" => {
40                    match val {
41                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.normal_value = Some(v); } }
42                        crate::base::FieldValue::TextList(svs) => {
43                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.normal_value = Some(v); } }
44                        }
45                        _ => {}
46                    }
47                }
48                "ApparentPowerLimit.value" => {
49                    match val {
50                        crate::base::FieldValue::Text(sv) => { if let Ok(v) = sv.trim().parse() { obj.value = Some(v); } }
51                        crate::base::FieldValue::TextList(svs) => {
52                            if let Some(sv) = svs.last() { if let Ok(v) = sv.trim().parse() { obj.value = Some(v); } }
53                        }
54                        _ => {}
55                    }
56                }
57                "OperationalLimit.OperationalLimitSet" => {
58                    if let crate::base::FieldValue::Resource(sv) = val {
59                        obj.base.operational_limit_set = Some(crate::base::MridRef { mrid: sv.clone() });
60                    }
61                }
62                "OperationalLimit.OperationalLimitType" => {
63                    if let crate::base::FieldValue::Resource(sv) = val {
64                        obj.base.operational_limit_type = Some(crate::base::MridRef { mrid: sv.clone() });
65                    }
66                }
67                "IdentifiedObject.description" => {
68                    match val {
69                        crate::base::FieldValue::Text(sv) => { obj.base.base.description = sv.clone(); }
70                        crate::base::FieldValue::TextList(svs) => {
71                            if let Some(sv) = svs.last() { obj.base.base.description = sv.clone(); }
72                        }
73                        _ => {}
74                    }
75                }
76                "IdentifiedObject.energyIdentCodeEic" => {
77                    match val {
78                        crate::base::FieldValue::Text(sv) => { obj.base.base.energy_ident_code_eic = sv.clone(); }
79                        crate::base::FieldValue::TextList(svs) => {
80                            if let Some(sv) = svs.last() { obj.base.base.energy_ident_code_eic = sv.clone(); }
81                        }
82                        _ => {}
83                    }
84                }
85                "IdentifiedObject.mRID" => {
86                    match val {
87                        crate::base::FieldValue::Text(sv) => { obj.base.base.m_rid = sv.clone(); }
88                        crate::base::FieldValue::TextList(svs) => {
89                            if let Some(sv) = svs.last() { obj.base.base.m_rid = sv.clone(); }
90                        }
91                        _ => {}
92                    }
93                }
94                "IdentifiedObject.name" => {
95                    match val {
96                        crate::base::FieldValue::Text(sv) => { obj.base.base.name = sv.clone(); }
97                        crate::base::FieldValue::TextList(svs) => {
98                            if let Some(sv) = svs.last() { obj.base.base.name = sv.clone(); }
99                        }
100                        _ => {}
101                    }
102                }
103                "IdentifiedObject.shortName" => {
104                    match val {
105                        crate::base::FieldValue::Text(sv) => { obj.base.base.short_name = sv.clone(); }
106                        crate::base::FieldValue::TextList(svs) => {
107                            if let Some(sv) = svs.last() { obj.base.base.short_name = sv.clone(); }
108                        }
109                        _ => {}
110                    }
111                }
112                _ => {}
113            }
114        }
115        obj
116    }
117}