|
5 | 5 |
|
6 | 6 | from __future__ import annotations
|
7 | 7 |
|
| 8 | +import logging |
8 | 9 | from collections import abc
|
9 | 10 |
|
10 | 11 | from ....microgrid import connection_manager
|
11 | 12 | from ....microgrid.component import Component, ComponentCategory, ComponentMetricId
|
12 | 13 | from ..._quantities import Power
|
13 | 14 | from .._formula_engine import FormulaEngine
|
14 | 15 | from .._resampled_formula_builder import ResampledFormulaBuilder
|
15 |
| -from ._formula_generator import ComponentNotFound, FormulaGenerator |
| 16 | +from ._formula_generator import ( |
| 17 | + NON_EXISTING_COMPONENT_ID, |
| 18 | + ComponentNotFound, |
| 19 | + FormulaGenerator, |
| 20 | +) |
| 21 | + |
| 22 | +_logger = logging.getLogger(__name__) |
16 | 23 |
|
17 | 24 |
|
18 | 25 | class ConsumerPowerFormula(FormulaGenerator[Power]):
|
@@ -121,4 +128,17 @@ def _gen_without_grid_meter(
|
121 | 128 | is_first = False
|
122 | 129 | builder.push_component_metric(successor.component_id, nones_are_zeros=False)
|
123 | 130 |
|
| 131 | + if len(builder.finalize()[0]) == 0: |
| 132 | + # If there are no consumer components, we have to send 0 values at the same |
| 133 | + # frequency as the other streams. So we subscribe with a non-existing |
| 134 | + # component id, just to get a `None` message at the resampling interval. |
| 135 | + builder.push_component_metric( |
| 136 | + NON_EXISTING_COMPONENT_ID, nones_are_zeros=True |
| 137 | + ) |
| 138 | + _logger.warning( |
| 139 | + "Unable to find any consumers in the component graph. " |
| 140 | + "Subscribing to the resampling actor with a non-existing " |
| 141 | + "component id, so that `0` values are sent from the formula." |
| 142 | + ) |
| 143 | + |
124 | 144 | return builder.build()
|
0 commit comments