Skip to content

Commit c864519

Browse files
committed
Support assets
Signed-off-by: Sahas Subramanian <[email protected]>
1 parent ee1a0b4 commit c864519

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ classifiers = [
2222
]
2323
requires-python = ">= 3.11, < 4"
2424
dependencies = [
25-
"frequenz-client-microgrid @ git+https://github.com/frequenz-floss/frequenz-client-microgrid-python@refs/heads/v0.18.x",
2625
"typing-extensions >= 4.14.1, < 5",
2726
]
2827
dynamic = ["version"]
@@ -32,6 +31,12 @@ name = "Frequenz Energy-as-a-Service GmbH"
3231
3332

3433
[project.optional-dependencies]
34+
microgrid = [
35+
"frequenz-client-microgrid @ git+https://github.com/frequenz-floss/frequenz-client-microgrid-python@refs/heads/v0.18.x",
36+
]
37+
assets = [
38+
"frequenz-client-assets == 0.1.0"
39+
]
3540
dev-flake8 = [
3641
"flake8 == 7.3.0",
3742
"flake8-docstrings == 1.7.0",

src/category.rs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,35 @@ struct ComponentClasses<'py> {
1818

1919
impl<'py> ComponentClasses<'py> {
2020
fn try_new(py: Python<'py>) -> PyResult<Self> {
21-
let path = "frequenz.client.microgrid.component";
21+
let candidates = vec![
22+
"frequenz.client.microgrid.component".to_string(),
23+
"frequenz.client.assets.electrical_component".to_string(),
24+
];
2225

23-
Ok(Self {
24-
grid_connection_point: py.import(path)?.getattr("GridConnectionPoint")?,
25-
meter: py.import(path)?.getattr("Meter")?,
26-
battery: py.import(path)?.getattr("Battery")?,
27-
ev_charger: py.import(path)?.getattr("EvCharger")?,
28-
chp: py.import(path)?.getattr("Chp")?,
29-
battery_inverter: py.import(path)?.getattr("BatteryInverter")?,
30-
solar_inverter: py.import(path)?.getattr("SolarInverter")?,
31-
hybrid_inverter: py.import(path)?.getattr("HybridInverter")?,
32-
unspecified_component: py.import(path)?.getattr("UnspecifiedComponent")?,
33-
})
26+
let mut last_err: Option<PyErr> = None;
27+
for path in &candidates {
28+
match py.import(path) {
29+
Ok(module) => {
30+
return Ok(Self {
31+
grid_connection_point: module.getattr("GridConnectionPoint")?,
32+
meter: module.getattr("Meter")?,
33+
battery: module.getattr("Battery")?,
34+
ev_charger: module.getattr("EvCharger")?,
35+
chp: module.getattr("Chp")?,
36+
battery_inverter: module.getattr("BatteryInverter")?,
37+
solar_inverter: module.getattr("SolarInverter")?,
38+
hybrid_inverter: module.getattr("HybridInverter")?,
39+
unspecified_component: module.getattr("UnspecifiedComponent")?,
40+
});
41+
}
42+
Err(e) => last_err = Some(e),
43+
}
44+
}
45+
Err(pyo3::exceptions::PyImportError::new_err(format!(
46+
"Could not import a component provider. Tried: {candidates:?}. \
47+
Install one: pip install frequenz-component-graph[microgrid] or [assets]. \
48+
Last error: {last_err:?}"
49+
)))
3450
}
3551
}
3652

0 commit comments

Comments
 (0)