Skip to main content

cimstructs/
SvStatus.rs

1/// State variable for status.
2#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct SvStatus {
4    pub id: String,
5    /// The conducting equipment associated with the status state variable.
6    #[serde(skip_serializing_if = "Option::is_none")]
7    pub conducting_equipment: Option<super::base::MridRef>,
8    /// The in service status as a result of topology processing. It indicates if the equipment is considered as energized by the power flow. It reflects if the equipment is connected within a solvable island. It does not necessarily reflect whether or not the island was solved by the power flow.
9    #[serde(skip_serializing_if = "Option::is_none")]
10    pub in_service: Option<bool>,
11}
12impl crate::base::CimElement for SvStatus {
13    fn mrid(&self) -> &str { &self.id }
14    fn type_name(&self) -> &'static str { "SvStatus" }
15    fn as_any(&self) -> &dyn std::any::Any { self }
16    fn to_json_value(&self) -> serde_json::Value {
17        serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
18    }
19    fn to_block(&self) -> crate::base::RdfBlock {
20        let mut block = crate::base::RdfBlock {
21            type_name: "SvStatus".to_string(),
22            mrid: self.id.clone(),
23            fields: std::collections::HashMap::new(),
24            duplicate_fields: std::collections::HashSet::new(),
25        };
26        if let Some(ref v) = self.conducting_equipment {
27            block.fields.insert("SvStatus.ConductingEquipment".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
28        }
29        if let Some(v) = self.in_service {
30            block.fields.insert("SvStatus.inService".into(), crate::base::FieldValue::Text(v.to_string()));
31        }
32        block
33    }
34}
35
36impl SvStatus {
37    pub fn from_block(b: &crate::base::RdfBlock) -> Self {
38        let mut obj = Self::default();
39        obj.id.clone_from(&b.mrid);
40        for (key, val) in &b.fields {
41            match key.as_str() {
42                "SvStatus.ConductingEquipment" => {
43                    if let crate::base::FieldValue::Resource(sv) = val {
44                        obj.conducting_equipment = Some(crate::base::MridRef { mrid: sv.clone() });
45                    }
46                }
47                "SvStatus.inService" => {
48                    match val {
49                        crate::base::FieldValue::Text(sv) => { obj.in_service = Some(sv.trim() == "true"); }
50                        crate::base::FieldValue::TextList(svs) => {
51                            if let Some(sv) = svs.last() { obj.in_service = Some(sv.trim() == "true"); }
52                        }
53                        _ => {}
54                    }
55                }
56                _ => {}
57            }
58        }
59        obj
60    }
61}