Skip to content

Commit 4a1e248

Browse files
committed
Make convert function internal
Signed-off-by: Mathias L. Baumann <[email protected]>
1 parent 456570c commit 4a1e248

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

src/frequenz/client/dispatch/_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
ComponentSelector,
4646
Dispatch,
4747
DispatchEvent,
48-
component_selector_to_protobuf,
48+
_component_selector_to_protobuf,
4949
)
5050

5151
# pylint: enable=no-name-in-module
@@ -166,7 +166,7 @@ def to_interval(
166166
# Setup parameters
167167
start_time_interval = to_interval(start_from, start_to)
168168
end_time_interval = to_interval(end_from, end_to)
169-
selectors = list(map(component_selector_to_protobuf, component_selectors))
169+
selectors = list(map(_component_selector_to_protobuf, component_selectors))
170170
filters = DispatchFilter(
171171
selectors=selectors,
172172
start_time_interval=start_time_interval,
@@ -354,7 +354,7 @@ async def update(
354354
else:
355355
msg.update.duration = round(val.total_seconds())
356356
case "selector":
357-
msg.update.selector.CopyFrom(component_selector_to_protobuf(val))
357+
msg.update.selector.CopyFrom(_component_selector_to_protobuf(val))
358358
case "is_active":
359359
msg.update.is_active = val
360360
case "payload":

src/frequenz/client/dispatch/_internal_types.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
from .recurrence import RecurrenceRule
2222
from .types import (
2323
ComponentSelector,
24-
component_selector_from_protobuf,
25-
component_selector_to_protobuf,
24+
_component_selector_from_protobuf,
25+
_component_selector_to_protobuf,
2626
)
2727

2828
# pylint: enable=no-name-in-module
@@ -97,7 +97,9 @@ def from_protobuf(
9797
to_datetime(pb_object.dispatch_data.start_time)
9898
),
9999
duration=duration,
100-
selector=component_selector_from_protobuf(pb_object.dispatch_data.selector),
100+
selector=_component_selector_from_protobuf(
101+
pb_object.dispatch_data.selector
102+
),
101103
active=pb_object.dispatch_data.is_active,
102104
dry_run=pb_object.dispatch_data.is_dry_run,
103105
payload=MessageToDict(pb_object.dispatch_data.payload),
@@ -121,7 +123,7 @@ def to_protobuf(self) -> PBDispatchCreateRequest:
121123
duration=(
122124
round(self.duration.total_seconds()) if self.duration else None
123125
),
124-
selector=component_selector_to_protobuf(self.selector),
126+
selector=_component_selector_to_protobuf(self.selector),
125127
is_active=self.active,
126128
is_dry_run=self.dry_run,
127129
payload=payload,

src/frequenz/client/dispatch/types.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"""
3737

3838

39-
def component_selector_from_protobuf(
39+
def _component_selector_from_protobuf(
4040
pb_selector: PBComponentSelector,
4141
) -> ComponentSelector:
4242
"""Convert a protobuf component selector to a component selector.
@@ -66,7 +66,7 @@ def component_selector_from_protobuf(
6666
raise ValueError("Invalid component selector")
6767

6868

69-
def component_selector_to_protobuf(
69+
def _component_selector_to_protobuf(
7070
selector: ComponentSelector,
7171
) -> PBComponentSelector:
7272
"""Convert a component selector to a protobuf component selector.
@@ -181,7 +181,7 @@ def from_protobuf(cls, pb_object: PBDispatch) -> "Dispatch":
181181
if pb_object.data.duration
182182
else None
183183
),
184-
selector=component_selector_from_protobuf(pb_object.data.selector),
184+
selector=_component_selector_from_protobuf(pb_object.data.selector),
185185
active=pb_object.data.is_active,
186186
dry_run=pb_object.data.is_dry_run,
187187
payload=MessageToDict(pb_object.data.payload),
@@ -209,7 +209,7 @@ def to_protobuf(self) -> PBDispatch:
209209
duration=(
210210
round(self.duration.total_seconds()) if self.duration else None
211211
),
212-
selector=component_selector_to_protobuf(self.selector),
212+
selector=_component_selector_to_protobuf(self.selector),
213213
is_active=self.active,
214214
is_dry_run=self.dry_run,
215215
payload=payload,

tests/test_dispatch_types.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
)
1616
from frequenz.client.dispatch.types import (
1717
Dispatch,
18-
component_selector_from_protobuf,
19-
component_selector_to_protobuf,
18+
_component_selector_from_protobuf,
19+
_component_selector_to_protobuf,
2020
)
2121

2222

@@ -30,8 +30,8 @@ def test_component_selector() -> None:
3030
[ComponentCategory.METER],
3131
[ComponentCategory.EV_CHARGER, ComponentCategory.BATTERY],
3232
):
33-
protobuf = component_selector_to_protobuf(selector)
34-
assert component_selector_from_protobuf(protobuf) == selector
33+
protobuf = _component_selector_to_protobuf(selector)
34+
assert _component_selector_from_protobuf(protobuf) == selector
3535

3636

3737
def test_end_criteria() -> None:

0 commit comments

Comments
 (0)