|
14 | 14 | from ._fallback_formula_metric_fetcher import FallbackFormulaMetricFetcher
|
15 | 15 | from ._formula_generator import (
|
16 | 16 | NON_EXISTING_COMPONENT_ID,
|
17 |
| - ComponentNotFound, |
18 | 17 | FormulaGenerator,
|
19 | 18 | FormulaGeneratorConfig,
|
20 | 19 | )
|
| 20 | +from ._simple_power_formula import SimplePowerFormula |
21 | 21 |
|
22 | 22 | _logger = logging.getLogger(__name__)
|
23 | 23 |
|
@@ -50,39 +50,27 @@ def generate( # noqa: DOC502
|
50 | 50 | )
|
51 | 51 |
|
52 | 52 | component_graph = connection_manager.get().component_graph
|
53 |
| - if self._config.component_ids is None: |
54 |
| - # if in the future we support additional producers, we need to add them to the lambda |
55 |
| - producer_components = component_graph.dfs( |
56 |
| - self._get_grid_component(), |
57 |
| - set(), |
58 |
| - lambda component: component_graph.is_pv_chain(component) |
59 |
| - or component_graph.is_chp_chain(component), |
60 |
| - ) |
61 |
| - |
62 |
| - if not producer_components: |
63 |
| - _logger.warning( |
64 |
| - "Unable to find any producer components in the component graph. " |
65 |
| - "Subscribing to the resampling actor with a non-existing " |
66 |
| - "component id, so that `0` values are sent from the formula." |
67 |
| - ) |
68 |
| - # If there are no producer components, we have to send 0 values at the same |
69 |
| - # frequency as the other streams. So we subscribe with a non-existing |
70 |
| - # component id, just to get a `None` message at the resampling interval. |
71 |
| - builder.push_component_metric( |
72 |
| - NON_EXISTING_COMPONENT_ID, nones_are_zeros=True |
73 |
| - ) |
74 |
| - return builder.build() |
| 53 | + # if in the future we support additional producers, we need to add them to the lambda |
| 54 | + producer_components = component_graph.dfs( |
| 55 | + self._get_grid_component(), |
| 56 | + set(), |
| 57 | + lambda component: component_graph.is_pv_chain(component) |
| 58 | + or component_graph.is_chp_chain(component), |
| 59 | + ) |
75 | 60 |
|
76 |
| - else: |
77 |
| - producer_components = component_graph.components( |
78 |
| - component_ids=set(self._config.component_ids) |
| 61 | + if not producer_components: |
| 62 | + _logger.warning( |
| 63 | + "Unable to find any producer components in the component graph. " |
| 64 | + "Subscribing to the resampling actor with a non-existing " |
| 65 | + "component id, so that `0` values are sent from the formula." |
79 | 66 | )
|
80 |
| - if len(producer_components) != len(self._config.component_ids): |
81 |
| - raise ComponentNotFound( |
82 |
| - "Unable to find all requested producer components." |
83 |
| - f"Requested {self._config.component_ids}, " |
84 |
| - f" found {producer_components}." |
85 |
| - ) |
| 67 | + # If there are no producer components, we have to send 0 values at the same |
| 68 | + # frequency as the other streams. So we subscribe with a non-existing |
| 69 | + # component id, just to get a `None` message at the resampling interval. |
| 70 | + builder.push_component_metric( |
| 71 | + NON_EXISTING_COMPONENT_ID, nones_are_zeros=True |
| 72 | + ) |
| 73 | + return builder.build() |
86 | 74 |
|
87 | 75 | is_not_meter: Callable[[Component], bool] = (
|
88 | 76 | lambda component: component.category != ComponentCategory.METER
|
@@ -143,7 +131,7 @@ def _get_fallback_formulas(
|
143 | 131 | continue
|
144 | 132 |
|
145 | 133 | fallback_ids = [c.component_id for c in fallback_components]
|
146 |
| - generator = ProducerPowerFormula( |
| 134 | + generator = SimplePowerFormula( |
147 | 135 | f"{self._namespace}_fallback_{fallback_ids}",
|
148 | 136 | self._channel_registry,
|
149 | 137 | self._resampler_subscription_sender,
|
|
0 commit comments