Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions jedi/tests/test_complete_city_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,16 @@ def test_hub_dot_system_dot():
"shutdown",
"storage",
]


def test_hub_dot_ble_dot():
line = "hub.ble."
code = _create_snippet(line)
completions: list[CompletionItem] = json.loads(complete(code, 3, len(line) + 1))
assert [c["insertText"] for c in completions] == [
"broadcast",
"observe",
"observe_enable",
"signal_strength",
"version",
]
13 changes: 13 additions & 0 deletions jedi/tests/test_complete_essential_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,16 @@ def test_hub_dot_system_dot():
"shutdown",
"storage",
]


def test_hub_dot_ble_dot():
line = "hub.ble."
code = _create_snippet(line)
completions: list[CompletionItem] = json.loads(complete(code, 3, len(line) + 1))
assert [c["insertText"] for c in completions] == [
"broadcast",
"observe",
"observe_enable",
"signal_strength",
"version",
]
1 change: 1 addition & 0 deletions jedi/tests/test_complete_inventor_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ def _create_snippet(line: str) -> str:
test_hub_dot_light_dot,
test_hub_dot_speaker_dot,
test_hub_dot_system_dot,
test_hub_dot_ble_dot,
)
13 changes: 13 additions & 0 deletions jedi/tests/test_complete_move_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,16 @@ def test_hub_dot_system_dot():
"shutdown",
"storage",
]


def test_hub_dot_ble_dot():
line = "hub.ble."
code = _create_snippet(line)
completions: list[CompletionItem] = json.loads(complete(code, 3, len(line) + 1))
assert [c["insertText"] for c in completions] == [
"broadcast",
"observe",
"observe_enable",
"signal_strength",
"version",
]
13 changes: 13 additions & 0 deletions jedi/tests/test_complete_prime_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,16 @@ def test_hub_dot_system_dot():
"shutdown",
"storage",
]


def test_hub_dot_ble_dot():
line = "hub.ble."
code = _create_snippet(line)
completions: list[CompletionItem] = json.loads(complete(code, 3, len(line) + 1))
assert [c["insertText"] for c in completions] == [
"broadcast",
"observe",
"observe_enable",
"signal_strength",
"version",
]
13 changes: 13 additions & 0 deletions jedi/tests/test_complete_technic_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,16 @@ def test_hub_dot_system_dot():
"shutdown",
"storage",
]


def test_hub_dot_ble_dot():
line = "hub.ble."
code = _create_snippet(line)
completions: list[CompletionItem] = json.loads(complete(code, 3, len(line) + 1))
assert [c["insertText"] for c in completions] == [
"broadcast",
"observe",
"observe_enable",
"signal_strength",
"version",
]
20 changes: 15 additions & 5 deletions jedi/tests/test_get_signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,22 @@ def _get_constructor_signature(module: str, type: str) -> SignatureHelp:
pytest.param(
"pybricks.hubs",
"MoveHub",
[["broadcast_channel: int=None", "observe_channels: Sequence[int]=[]"]],
[
[
"broadcast_channel: Optional[int]=None",
"observe_channels: Sequence[int]=[]",
]
],
),
pytest.param(
"pybricks.hubs",
"CityHub",
[["broadcast_channel: int=None", "observe_channels: Sequence[int]=[]"]],
[
[
"broadcast_channel: Optional[int]=None",
"observe_channels: Sequence[int]=[]",
]
],
),
pytest.param(
"pybricks.hubs",
Expand All @@ -100,7 +110,7 @@ def _get_constructor_signature(module: str, type: str) -> SignatureHelp:
[
"top_side: Axis=Axis.Z",
"front_side: Axis=Axis.X",
"broadcast_channel: int=None",
"broadcast_channel: Optional[int]=None",
"observe_channels: Sequence[int]=[]",
]
],
Expand All @@ -112,7 +122,7 @@ def _get_constructor_signature(module: str, type: str) -> SignatureHelp:
[
"top_side: Axis=Axis.Z",
"front_side: Axis=Axis.X",
"broadcast_channel: int=None",
"broadcast_channel: Optional[int]=None",
"observe_channels: Sequence[int]=[]",
]
],
Expand All @@ -124,7 +134,7 @@ def _get_constructor_signature(module: str, type: str) -> SignatureHelp:
[
"top_side: Axis=Axis.Z",
"front_side: Axis=Axis.X",
"broadcast_channel: int=None",
"broadcast_channel: Optional[int]=None",
"observe_channels: Sequence[int]=[]",
]
],
Expand Down
22 changes: 21 additions & 1 deletion src/pybricks/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,22 @@ class BLE:
.. versionadded:: 3.3
"""

@overload
def broadcast(
self, data: Iterable[Union[bool, int, float, str, bytes]]
) -> MaybeAwaitable:
...

@overload
def broadcast(self, data: Union[bool, int, float, str, bytes]) -> MaybeAwaitable:
...

def broadcast(
self,
data: Union[
Iterable[Union[bool, int, float, str, bytes]], bool, int, float, str, bytes
],
) -> MaybeAwaitable:
"""broadcast(data)

Starts broadcasting the given data on
Expand Down Expand Up @@ -1479,7 +1494,12 @@ def broadcast(self, data: Union[bool, int, float, str, bytes]) -> MaybeAwaitable

def observe(
self, channel: int
) -> Optional[Tuple[Union[bool, int, float, str, bytes], ...]]:
) -> Optional[
Union[
Tuple[Union[bool, int, float, str, bytes], ...],
Union[bool, int, float, str, bytes],
]
]:
"""observe(channel) -> bool | int | float | str | bytes | tuple | None

Retrieves the last observed data for a given channel.
Expand Down
14 changes: 8 additions & 6 deletions src/pybricks/hubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"""LEGO® Programmable Hubs."""

from typing import Sequence
from typing import Sequence, Optional

from . import _common
from .ev3dev import _speaker
Expand Down Expand Up @@ -44,7 +44,9 @@ class MoveHub:
ble = _common.BLE()

def __init__(
self, broadcast_channel: int = None, observe_channels: Sequence[int] = []
self,
broadcast_channel: Optional[int] = None,
observe_channels: Sequence[int] = [],
):
"""MoveHub(top_side=Axis.Z, front_side=Axis.X, broadcast_channel=None, observe_channels=[])

Expand Down Expand Up @@ -78,7 +80,7 @@ class CityHub:
ble = _common.BLE()

def __init__(
self, broadcast_channel: int = None, observe_channels: Sequence[int] = []
self, broadcast_channel: Optional[int] = None, observe_channels: Sequence[int] = []
):
"""CityHub(broadcast_channel=None, observe_channels=[])

Expand Down Expand Up @@ -112,7 +114,7 @@ def __init__(
self,
top_side: Axis = Axis.Z,
front_side: Axis = Axis.X,
broadcast_channel: int = None,
broadcast_channel: Optional[int] = None,
observe_channels: Sequence[int] = [],
):
"""TechnicHub(top_side=Axis.Z, front_side=Axis.X, broadcast_channel=None, observe_channels=[])
Expand Down Expand Up @@ -157,7 +159,7 @@ def __init__(
self,
top_side: Axis = Axis.Z,
front_side: Axis = Axis.X,
broadcast_channel: int = None,
broadcast_channel: Optional[int] = None,
observe_channels: Sequence[int] = [],
):
"""EssentialHub(top_side=Axis.Z, front_side=Axis.X, broadcast_channel=None, observe_channels=[])
Expand Down Expand Up @@ -212,7 +214,7 @@ def __init__(
self,
top_side: Axis = Axis.Z,
front_side: Axis = Axis.X,
broadcast_channel: int = None,
broadcast_channel: Optional[int] = None,
observe_channels: Sequence[int] = [],
):
"""PrimeHub(top_side=Axis.Z, front_side=Axis.X, broadcast_channel=None, observe_channels=[])
Expand Down
Loading