Skip to content

Commit 4cb8a3d

Browse files
committed
Update uses of the LatestValueCache to follow its new API
Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 06a1b65 commit 4cb8a3d

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -419,27 +419,28 @@ def _get_battery_inverter_data(
419419
Data for the battery and adjacent inverter without NaN values.
420420
Return None if we could not replace NaN values.
421421
"""
422-
battery_data_none = [
423-
self._battery_caches[battery_id].latest_value for battery_id in battery_ids
424-
]
425-
inverter_data_none = [
426-
self._inverter_caches[inverter_id].latest_value
427-
for inverter_id in inverter_ids
428-
]
429-
430-
# It means that nothing has been send on this channels, yet.
422+
# It means that nothing has been send on these channels, yet.
431423
# This should be handled by BatteryStatus. BatteryStatus should not return
432424
# this batteries as working.
433-
if not all(battery_data_none) or not all(inverter_data_none):
425+
if not all(
426+
self._battery_caches[bat_id].has_value for bat_id in battery_ids
427+
) or not all(
428+
self._inverter_caches[inv_id].has_value for inv_id in inverter_ids
429+
):
434430
_logger.error(
435431
"Battery %s or inverter %s send no data, yet. They should be not used.",
436432
battery_ids,
437433
inverter_ids,
438434
)
439435
return None
440436

441-
battery_data = typing.cast(list[BatteryData], battery_data_none)
442-
inverter_data = typing.cast(list[InverterData], inverter_data_none)
437+
battery_data = [
438+
self._battery_caches[battery_id].latest_value for battery_id in battery_ids
439+
]
440+
inverter_data = [
441+
self._inverter_caches[inverter_id].latest_value
442+
for inverter_id in inverter_ids
443+
]
443444

444445
DataType = typing.TypeVar("DataType", BatteryData, InverterData)
445446

0 commit comments

Comments
 (0)