Skip to content

Commit bf9bdfc

Browse files
committed
Fix bug in GridFrequency quantity conversion
The sample value can also be `None`, in which case we can't access to `sample.value.base_value`. In that case we just cast the existing sample as it doesn't matter which type the value has when it is `None`, avoiding the extra copying. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent e4f8356 commit bf9bdfc

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/frequenz/sdk/timeseries/_grid_frequency.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import asyncio
99
import logging
10-
from typing import TYPE_CHECKING
10+
from typing import TYPE_CHECKING, cast
1111

1212
from frequenz.channels import Receiver, Sender
1313

@@ -105,9 +105,9 @@ def new_receiver(self) -> Receiver[Sample[Frequency]]:
105105
)
106106

107107
return receiver.map(
108-
lambda sample: Sample(
109-
sample.timestamp, Frequency.from_hertz(sample.value.base_value)
110-
)
108+
lambda sample: cast(Sample[Frequency], sample)
109+
if sample.value is None
110+
else Sample(sample.timestamp, Frequency.from_hertz(sample.value.base_value))
111111
)
112112

113113
async def _send_request(self) -> None:

0 commit comments

Comments
 (0)