@@ -18,19 +18,35 @@ struct ComponentClasses<'py> {
1818
1919impl < ' 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