1#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
3pub struct Control {
4 #[serde(flatten)]
5 pub base: super::IOPoint,
6 #[serde(skip_serializing_if = "Option::is_none")]
8 pub power_system_resource: Option<super::base::MridRef>,
9 pub control_type: String,
11 #[serde(skip_serializing_if = "Option::is_none")]
13 pub operation_in_progress: Option<bool>,
14 pub time_stamp: String,
16 #[serde(skip_serializing_if = "Option::is_none")]
18 pub unit_multiplier: Option<super::base::UriRef>,
19 #[serde(skip_serializing_if = "Option::is_none")]
21 pub unit_symbol: Option<super::base::UriRef>,
22}
23impl crate::base::CimElement for Control {
24 fn mrid(&self) -> &str { &self.base.base.id }
25 fn type_name(&self) -> &'static str { "Control" }
26 fn as_any(&self) -> &dyn std::any::Any { self }
27 fn to_json_value(&self) -> serde_json::Value {
28 serde_json::to_value(self).unwrap_or(serde_json::Value::Null)
29 }
30 fn to_block(&self) -> crate::base::RdfBlock {
31 let mut block = self.base.to_block();
32 block.type_name = "Control".to_string();
33 if let Some(ref v) = self.power_system_resource {
34 block.fields.insert("Control.PowerSystemResource".into(), crate::base::FieldValue::Resource(v.mrid.clone()));
35 }
36 if !self.control_type.is_empty() {
37 block.fields.insert("Control.controlType".into(), crate::base::FieldValue::Text(self.control_type.clone()));
38 }
39 if let Some(v) = self.operation_in_progress {
40 block.fields.insert("Control.operationInProgress".into(), crate::base::FieldValue::Text(v.to_string()));
41 }
42 if !self.time_stamp.is_empty() {
43 block.fields.insert("Control.timeStamp".into(), crate::base::FieldValue::Text(self.time_stamp.clone()));
44 }
45 if let Some(ref v) = self.unit_multiplier {
46 block.fields.insert("Control.unitMultiplier".into(), crate::base::FieldValue::Resource(v.uri.clone()));
47 }
48 if let Some(ref v) = self.unit_symbol {
49 block.fields.insert("Control.unitSymbol".into(), crate::base::FieldValue::Resource(v.uri.clone()));
50 }
51 block
52 }
53}
54
55impl Control {
56 pub fn from_block(b: &crate::base::RdfBlock) -> Self {
57 let mut obj = Self::default();
58 obj.base.base.id.clone_from(&b.mrid);
59 for (key, val) in &b.fields {
60 match key.as_str() {
61 "Control.PowerSystemResource" => {
62 if let crate::base::FieldValue::Resource(sv) = val {
63 obj.power_system_resource = Some(crate::base::MridRef { mrid: sv.clone() });
64 }
65 }
66 "Control.controlType" => {
67 match val {
68 crate::base::FieldValue::Text(sv) => { obj.control_type = sv.clone(); }
69 crate::base::FieldValue::TextList(svs) => {
70 if let Some(sv) = svs.last() { obj.control_type = sv.clone(); }
71 }
72 _ => {}
73 }
74 }
75 "Control.operationInProgress" => {
76 match val {
77 crate::base::FieldValue::Text(sv) => { obj.operation_in_progress = Some(sv.trim() == "true"); }
78 crate::base::FieldValue::TextList(svs) => {
79 if let Some(sv) = svs.last() { obj.operation_in_progress = Some(sv.trim() == "true"); }
80 }
81 _ => {}
82 }
83 }
84 "Control.timeStamp" => {
85 match val {
86 crate::base::FieldValue::Text(sv) => { obj.time_stamp = sv.clone(); }
87 crate::base::FieldValue::TextList(svs) => {
88 if let Some(sv) = svs.last() { obj.time_stamp = sv.clone(); }
89 }
90 _ => {}
91 }
92 }
93 "Control.unitMultiplier" => {
94 if let crate::base::FieldValue::Resource(sv) = val {
95 obj.unit_multiplier = Some(crate::base::UriRef { uri: sv.clone() });
96 }
97 }
98 "Control.unitSymbol" => {
99 if let crate::base::FieldValue::Resource(sv) = val {
100 obj.unit_symbol = Some(crate::base::UriRef { uri: sv.clone() });
101 }
102 }
103 "IdentifiedObject.description" => {
104 match val {
105 crate::base::FieldValue::Text(sv) => { obj.base.base.description = sv.clone(); }
106 crate::base::FieldValue::TextList(svs) => {
107 if let Some(sv) = svs.last() { obj.base.base.description = sv.clone(); }
108 }
109 _ => {}
110 }
111 }
112 "IdentifiedObject.energyIdentCodeEic" => {
113 match val {
114 crate::base::FieldValue::Text(sv) => { obj.base.base.energy_ident_code_eic = sv.clone(); }
115 crate::base::FieldValue::TextList(svs) => {
116 if let Some(sv) = svs.last() { obj.base.base.energy_ident_code_eic = sv.clone(); }
117 }
118 _ => {}
119 }
120 }
121 "IdentifiedObject.mRID" => {
122 match val {
123 crate::base::FieldValue::Text(sv) => { obj.base.base.m_rid = sv.clone(); }
124 crate::base::FieldValue::TextList(svs) => {
125 if let Some(sv) = svs.last() { obj.base.base.m_rid = sv.clone(); }
126 }
127 _ => {}
128 }
129 }
130 "IdentifiedObject.name" => {
131 match val {
132 crate::base::FieldValue::Text(sv) => { obj.base.base.name = sv.clone(); }
133 crate::base::FieldValue::TextList(svs) => {
134 if let Some(sv) = svs.last() { obj.base.base.name = sv.clone(); }
135 }
136 _ => {}
137 }
138 }
139 "IdentifiedObject.shortName" => {
140 match val {
141 crate::base::FieldValue::Text(sv) => { obj.base.base.short_name = sv.clone(); }
142 crate::base::FieldValue::TextList(svs) => {
143 if let Some(sv) = svs.last() { obj.base.base.short_name = sv.clone(); }
144 }
145 _ => {}
146 }
147 }
148 _ => {}
149 }
150 }
151 obj
152 }
153}