Skip to content

Commit abbfdff

Browse files
committed
Add methods to identify the type of an inverter
Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
1 parent 6a06637 commit abbfdff

3 files changed

Lines changed: 64 additions & 1 deletion

File tree

src/client.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ mod microgrid_client_handle;
1414
pub use microgrid_client_handle::MicrogridClientHandle;
1515

1616
pub(crate) mod proto;
17-
pub use proto::common::microgrid::electrical_components::ElectricalComponentCategory;
17+
pub use proto::common::microgrid::electrical_components::{
18+
ElectricalComponent, ElectricalComponentCategory,
19+
};
1820

1921
#[cfg(test)]
2022
pub(crate) mod test_utils;

src/client/proto.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ pub use pb::frequenz::api::microgrid::v1alpha18 as microgrid;
2020
#[cfg(test)]
2121
pub use pb::google;
2222

23+
mod electrical_component;
2324
mod graph;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// License: MIT
2+
// Copyright © 2026 Frequenz Energy-as-a-Service GmbH
3+
4+
//! Extensions to the generated protobuf code for electrical components.
5+
6+
use crate::{
7+
client::{ElectricalComponent, ElectricalComponentCategory},
8+
proto::common::microgrid::electrical_components::{
9+
InverterType, electrical_component_category_specific_info::Kind,
10+
},
11+
};
12+
13+
impl ElectricalComponent {
14+
/// Returns true if the component is an inverter, false otherwise.
15+
pub fn is_inverter(&self) -> bool {
16+
matches!(
17+
ElectricalComponentCategory::try_from(self.category),
18+
Ok(ElectricalComponentCategory::Inverter)
19+
)
20+
}
21+
22+
/// Returns true if the component is a PV inverter, false otherwise.
23+
pub fn is_pv_inverter(&self) -> bool {
24+
if let Some(info) = &self.category_specific_info {
25+
if let Some(Kind::Inverter(inverter_info)) = &info.kind {
26+
return matches!(
27+
InverterType::try_from(inverter_info.r#type),
28+
Ok(InverterType::Pv)
29+
);
30+
}
31+
}
32+
false
33+
}
34+
35+
/// Returns true if the component is a battery inverter, false otherwise.
36+
pub fn is_battery_inverter(&self) -> bool {
37+
if let Some(info) = &self.category_specific_info {
38+
if let Some(Kind::Inverter(inverter_info)) = &info.kind {
39+
return matches!(
40+
InverterType::try_from(inverter_info.r#type),
41+
Ok(InverterType::Battery)
42+
);
43+
}
44+
}
45+
false
46+
}
47+
48+
/// Returns true if the component is a hybrid inverter, false otherwise.
49+
pub fn is_hybrid_inverter(&self) -> bool {
50+
if let Some(info) = &self.category_specific_info {
51+
if let Some(Kind::Inverter(inverter_info)) = &info.kind {
52+
return matches!(
53+
InverterType::try_from(inverter_info.r#type),
54+
Ok(InverterType::Hybrid)
55+
);
56+
}
57+
}
58+
false
59+
}
60+
}

0 commit comments

Comments
 (0)