Skip to main content

frequenz_microgrid/client/proto/
electrical_component.rs

1// License: MIT
2// Copyright © 2026 Frequenz Energy-as-a-Service GmbH
3
4//! Extensions to the generated protobuf code for electrical components.
5
6use crate::{
7    client::{ElectricalComponent, ElectricalComponentCategory},
8    proto::common::microgrid::electrical_components::{
9        InverterType, electrical_component_category_specific_info::Kind,
10    },
11};
12
13impl 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            && let Some(Kind::Inverter(inverter_info)) = &info.kind
26        {
27            return matches!(
28                InverterType::try_from(inverter_info.r#type),
29                Ok(InverterType::Pv)
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            && let Some(Kind::Inverter(inverter_info)) = &info.kind
39        {
40            return matches!(
41                InverterType::try_from(inverter_info.r#type),
42                Ok(InverterType::Battery)
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            && let Some(Kind::Inverter(inverter_info)) = &info.kind
52        {
53            return matches!(
54                InverterType::try_from(inverter_info.r#type),
55                Ok(InverterType::Hybrid)
56            );
57        }
58        false
59    }
60}