|
| 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