Skip to main content

cimstructs/
OperationalLimit.rs

1/// A value and normal value associated with a specific kind of limit. The sub class value and normalValue attributes vary inversely to the associated OperationalLimitType.acceptableDuration (acceptableDuration for short). If a particular piece of equipment has multiple operational limits of the same kind (apparent power, current, etc.), the limit with the greatest acceptableDuration shall have the smallest limit value and the limit with the smallest acceptableDuration shall have the largest limit value. Note: A large current can only be allowed to flow through a piece of equipment for a short duration without causing damage, but a lesser current can be allowed to flow for a longer duration.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct OperationalLimit {
4    #[serde(flatten)]
5    pub base: super::IdentifiedObject,
6    /// The limit set to which the limit values belong.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub operational_limit_set: Option<super::base::MridRef>,
9    /// The limit type associated with this limit.
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub operational_limit_type: Option<super::base::MridRef>,
12}
13impl crate::base::CimElement for OperationalLimit {
14    fn mrid(&self) -> &str { &self.base.id }
15    fn type_name(&self) -> &'static str { "OperationalLimit" }
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 = "OperationalLimit".to_string();
23        if let Some(ref v) = self.operational_limit_set {
24            block.fields.insert("OperationalLimit.OperationalLimitSet".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
25        }
26        if let Some(ref v) = self.operational_limit_type {
27            block.fields.insert("OperationalLimit.OperationalLimitType".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
28        }
29        block
30    }
31}
32
33impl OperationalLimit {
34    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
35        let mut obj = Self::default();
36        obj.base.id.clone_from(&b.mrid);
37        for (key, val) in &b.fields {
38            match key.as_str() {
39                "OperationalLimit.OperationalLimitSet" => {
40                    if let crate::base::FieldValue::Resource(sv) = val {
41                        obj.operational_limit_set = Some(crate::base::MridRef { mrid: sv.clone() });
42                    }
43                }
44                "OperationalLimit.OperationalLimitType" => {
45                    if let crate::base::FieldValue::Resource(sv) = val {
46                        obj.operational_limit_type = Some(crate::base::MridRef { mrid: sv.clone() });
47                    }
48                }
49                "IdentifiedObject.description" => {
50                    match val {
51                        crate::base::FieldValue::Text(sv) => { obj.base.description = sv.clone(); }
52                        crate::base::FieldValue::TextList(svs) => {
53                            if let Some(sv) = svs.last() { obj.base.description = sv.clone(); }
54                        }
55                        _ => {}
56                    }
57                }
58                "IdentifiedObject.energyIdentCodeEic" => {
59                    match val {
60                        crate::base::FieldValue::Text(sv) => { obj.base.energy_ident_code_eic = sv.clone(); }
61                        crate::base::FieldValue::TextList(svs) => {
62                            if let Some(sv) = svs.last() { obj.base.energy_ident_code_eic = sv.clone(); }
63                        }
64                        _ => {}
65                    }
66                }
67                "IdentifiedObject.mRID" => {
68                    match val {
69                        crate::base::FieldValue::Text(sv) => { obj.base.m_rid = sv.clone(); }
70                        crate::base::FieldValue::TextList(svs) => {
71                            if let Some(sv) = svs.last() { obj.base.m_rid = sv.clone(); }
72                        }
73                        _ => {}
74                    }
75                }
76                "IdentifiedObject.name" => {
77                    match val {
78                        crate::base::FieldValue::Text(sv) => { obj.base.name = sv.clone(); }
79                        crate::base::FieldValue::TextList(svs) => {
80                            if let Some(sv) = svs.last() { obj.base.name = sv.clone(); }
81                        }
82                        _ => {}
83                    }
84                }
85                "IdentifiedObject.shortName" => {
86                    match val {
87                        crate::base::FieldValue::Text(sv) => { obj.base.short_name = sv.clone(); }
88                        crate::base::FieldValue::TextList(svs) => {
89                            if let Some(sv) = svs.last() { obj.base.short_name = sv.clone(); }
90                        }
91                        _ => {}
92                    }
93                }
94                _ => {}
95            }
96        }
97        obj
98    }
99}