Skip to content

Commit 2d915c4

Browse files
committed
Replace LatestValueCache.latest_value property with a get method
The previous commit has introduced the possibility for exceptions to be raised from the implementation of `latest_value` property. Properties should ideally not raise, so we replace it with the `get` method. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 4cb8a3d commit 2d915c4

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

src/frequenz/sdk/_internal/_channels.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ def __init__(self, receiver: Receiver[T]) -> None:
4444
self._latest_value: T | _Sentinel = _Sentinel()
4545
self._task = asyncio.create_task(self._run())
4646

47-
@property
48-
def latest_value(self) -> T:
49-
"""The latest value that has been received.
47+
def get(self) -> T:
48+
"""Return the latest value that has been received.
5049
5150
This raises a `ValueError` if no value has been received yet. Use `has_value` to
5251
check whether a value has been received yet, before trying to access the value,

src/frequenz/sdk/actor/power_distributing/_component_managers/_battery_manager.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,10 @@ def _get_battery_inverter_data(
435435
return None
436436

437437
battery_data = [
438-
self._battery_caches[battery_id].latest_value for battery_id in battery_ids
438+
self._battery_caches[battery_id].get() for battery_id in battery_ids
439439
]
440440
inverter_data = [
441-
self._inverter_caches[inverter_id].latest_value
442-
for inverter_id in inverter_ids
441+
self._inverter_caches[inverter_id].get() for inverter_id in inverter_ids
443442
]
444443

445444
DataType = typing.TypeVar("DataType", BatteryData, InverterData)

src/frequenz/sdk/timeseries/ev_charger_pool/_set_current_bounds.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ async def _run(self) -> None:
103103
timer = Timer.timeout(timedelta(self._repeat_interval.total_seconds()))
104104

105105
async for selected in select(bound_chan, timer):
106-
meter = meter_data.latest_value
106+
meter = meter_data.get()
107107
if meter is None:
108108
raise ValueError("Meter channel closed.")
109109

0 commit comments

Comments
 (0)