Skip to main content

cimstructs/
OperationalLimitSet.rs

1/// A set of limits associated with equipment. Sets of limits might apply to a specific temperature, or season for example. A set of limits may contain different severities of limit levels that would apply to the same equipment. The set may contain limits of different types such as apparent power and current limits or high and low voltage limits that are logically applied together as a set.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct OperationalLimitSet {
4    #[serde(flatten)]
5    pub base: super::IdentifiedObject,
6    /// The equipment to which the limit set applies.
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub equipment: Option<super::base::MridRef>,
9    /// The terminal where the operational limit set apply.
10    #[serde(skip_serializing_if = "Option::is_none")]
11    pub terminal: Option<super::base::MridRef>,
12}
13impl crate::base::CimElement for OperationalLimitSet {
14    fn mrid(&self) -> &str { &self.base.id }
15    fn type_name(&self) -> &'static str { "OperationalLimitSet" }
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 = "OperationalLimitSet".to_string();
23        if let Some(ref v) = self.equipment {
24            block.fields.insert("OperationalLimitSet.Equipment".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
25        }
26        if let Some(ref v) = self.terminal {
27            block.fields.insert("OperationalLimitSet.Terminal".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
28        }
29        block
30    }
31}
32
33impl OperationalLimitSet {
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                "OperationalLimitSet.Equipment" => {
40                    if let crate::base::FieldValue::Resource(sv) = val {
41                        obj.equipment = Some(crate::base::MridRef { mrid: sv.clone() });
42                    }
43                }
44                "OperationalLimitSet.Terminal" => {
45                    if let crate::base::FieldValue::Resource(sv) = val {
46                        obj.terminal = 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}