From 2e538b66c30d315453ff27da99d83c42a146eabf Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Tue, 5 Mar 2024 14:52:54 +0100 Subject: [PATCH] pybricks.hubs: Change button to buttons. Fixes https://github.com/pybricks/support/issues/1254 --- CHANGELOG.md | 2 ++ doc/main/hubs/cityhub.rst | 2 +- doc/main/hubs/essentialhub.rst | 2 +- doc/main/hubs/movehub.rst | 2 +- doc/main/hubs/technichub.rst | 2 +- examples/pup/hub_common/button_single.py | 2 +- jedi/tests/test_complete_city_hub.py | 4 ++-- jedi/tests/test_complete_essential_hub.py | 4 ++-- jedi/tests/test_complete_move_hub.py | 4 ++-- jedi/tests/test_complete_technic_hub.py | 4 ++-- jedi/tests/test_get_signature.py | 8 ++++---- src/pybricks/hubs.py | 8 ++++---- 12 files changed, 23 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4186a2b..4ae93b2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ ## Changed - Updates for v3.4.0b3 firmware. +- Changed `hub.button` to `hub.buttons` on single button hubs. Access via + `hub.button` will keep working in the firmware for backwards compatibility. ## 3.4.0b4 - 2024-02-14 diff --git a/doc/main/hubs/cityhub.rst b/doc/main/hubs/cityhub.rst index 1be1f178..981a2e81 100644 --- a/doc/main/hubs/cityhub.rst +++ b/doc/main/hubs/cityhub.rst @@ -55,7 +55,7 @@ City Hub .. blockimg:: pybricks_blockButtonIsPressed_CityHub - .. automethod:: pybricks.hubs::CityHub.button.pressed + .. automethod:: pybricks.hubs::CityHub.buttons.pressed .. automethod:: pybricks.hubs::CityHub.system.set_stop_button diff --git a/doc/main/hubs/essentialhub.rst b/doc/main/hubs/essentialhub.rst index 891c65a9..0b18a5b5 100644 --- a/doc/main/hubs/essentialhub.rst +++ b/doc/main/hubs/essentialhub.rst @@ -32,7 +32,7 @@ Essential Hub .. blockimg:: pybricks_blockButtonIsPressed_EssentialHub - .. automethod:: pybricks.hubs::EssentialHub.button.pressed + .. automethod:: pybricks.hubs::EssentialHub.buttons.pressed .. automethod:: pybricks.hubs::EssentialHub.system.set_stop_button diff --git a/doc/main/hubs/movehub.rst b/doc/main/hubs/movehub.rst index ca889237..5e7ef7ec 100644 --- a/doc/main/hubs/movehub.rst +++ b/doc/main/hubs/movehub.rst @@ -77,7 +77,7 @@ Move Hub .. blockimg:: pybricks_blockButtonIsPressed_PrimeHub - .. automethod:: pybricks.hubs::MoveHub.button.pressed + .. automethod:: pybricks.hubs::MoveHub.buttons.pressed .. automethod:: pybricks.hubs::MoveHub.system.set_stop_button diff --git a/doc/main/hubs/technichub.rst b/doc/main/hubs/technichub.rst index b0d69e93..5f253ebd 100644 --- a/doc/main/hubs/technichub.rst +++ b/doc/main/hubs/technichub.rst @@ -95,7 +95,7 @@ Technic Hub .. blockimg:: pybricks_blockButtonIsPressed_TechnicHub - .. automethod:: pybricks.hubs::TechnicHub.button.pressed + .. automethod:: pybricks.hubs::TechnicHub.buttons.pressed .. automethod:: pybricks.hubs::TechnicHub.system.set_stop_button diff --git a/examples/pup/hub_common/button_single.py b/examples/pup/hub_common/button_single.py index 24c40a25..5e75f970 100644 --- a/examples/pup/hub_common/button_single.py +++ b/examples/pup/hub_common/button_single.py @@ -14,7 +14,7 @@ while watch.time() < 5000: # Set light to green if pressed, else red. - if hub.button.pressed(): + if hub.buttons.pressed(): hub.light.on(Color.GREEN) else: hub.light.on(Color.RED) diff --git a/jedi/tests/test_complete_city_hub.py b/jedi/tests/test_complete_city_hub.py index 47eb45be..7f7f0d2a 100644 --- a/jedi/tests/test_complete_city_hub.py +++ b/jedi/tests/test_complete_city_hub.py @@ -34,7 +34,7 @@ def test_hub_dot(): assert [c["insertText"] for c in completions] == [ "battery", "ble", - "button", + "buttons", "light", "system", ] @@ -51,7 +51,7 @@ def test_hub_dot_battery_dot(): def test_hub_dot_button_dot(): - line = "hub.button." + line = "hub.buttons." code = _create_snippet(line) completions: list[CompletionItem] = json.loads(complete(code, 3, len(line) + 1)) assert [c["insertText"] for c in completions] == [ diff --git a/jedi/tests/test_complete_essential_hub.py b/jedi/tests/test_complete_essential_hub.py index 544a51ab..d66f9eed 100644 --- a/jedi/tests/test_complete_essential_hub.py +++ b/jedi/tests/test_complete_essential_hub.py @@ -34,7 +34,7 @@ def test_hub_dot(): assert [c["insertText"] for c in completions] == [ "battery", "ble", - "button", + "buttons", "charger", "imu", "light", @@ -53,7 +53,7 @@ def test_hub_dot_battery_dot(): def test_hub_dot_buttons_dot(): - line = "hub.button." + line = "hub.buttons." code = _create_snippet(line) completions: list[CompletionItem] = json.loads(complete(code, 3, len(line) + 1)) assert [c["insertText"] for c in completions] == [ diff --git a/jedi/tests/test_complete_move_hub.py b/jedi/tests/test_complete_move_hub.py index 9c099dca..e295b584 100644 --- a/jedi/tests/test_complete_move_hub.py +++ b/jedi/tests/test_complete_move_hub.py @@ -34,7 +34,7 @@ def test_hub_dot(): assert [c["insertText"] for c in completions] == [ "battery", "ble", - "button", + "buttons", "imu", "light", "system", @@ -52,7 +52,7 @@ def test_hub_dot_battery_dot(): def test_hub_dot_button_dot(): - line = "hub.button." + line = "hub.buttons." code = _create_snippet(line) completions: list[CompletionItem] = json.loads(complete(code, 3, len(line) + 1)) assert [c["insertText"] for c in completions] == [ diff --git a/jedi/tests/test_complete_technic_hub.py b/jedi/tests/test_complete_technic_hub.py index e9ddc9ca..0188853f 100644 --- a/jedi/tests/test_complete_technic_hub.py +++ b/jedi/tests/test_complete_technic_hub.py @@ -34,7 +34,7 @@ def test_hub_dot(): assert [c["insertText"] for c in completions] == [ "battery", "ble", - "button", + "buttons", "imu", "light", "system", @@ -52,7 +52,7 @@ def test_hub_dot_battery_dot(): def test_hub_dot_button_dot(): - line = "hub.button." + line = "hub.buttons." code = _create_snippet(line) completions: list[CompletionItem] = json.loads(complete(code, 3, len(line) + 1)) assert [c["insertText"] for c in completions] == [ diff --git a/jedi/tests/test_get_signature.py b/jedi/tests/test_get_signature.py index 39e38965..d6c24ee8 100644 --- a/jedi/tests/test_get_signature.py +++ b/jedi/tests/test_get_signature.py @@ -253,7 +253,7 @@ def _get_method_signature(module: str, type: str, method: str) -> SignatureHelp: ), pytest.param("pybricks.hubs", "MoveHub", "battery.voltage", [([], "int")]), pytest.param("pybricks.hubs", "MoveHub", "battery.current", [([], "int")]), - pytest.param("pybricks.hubs", "MoveHub", "button.pressed", [([], "Set[Button]")]), + pytest.param("pybricks.hubs", "MoveHub", "buttons.pressed", [([], "Set[Button]")]), pytest.param( "pybricks.hubs", "MoveHub", @@ -288,7 +288,7 @@ def _get_method_signature(module: str, type: str, method: str) -> SignatureHelp: ), pytest.param("pybricks.hubs", "CityHub", "battery.voltage", [([], "int")]), pytest.param("pybricks.hubs", "CityHub", "battery.current", [([], "int")]), - pytest.param("pybricks.hubs", "CityHub", "button.pressed", [([], "Set[Button]")]), + pytest.param("pybricks.hubs", "CityHub", "buttons.pressed", [([], "Set[Button]")]), pytest.param( "pybricks.hubs", "CityHub", @@ -354,7 +354,7 @@ def _get_method_signature(module: str, type: str, method: str) -> SignatureHelp: pytest.param("pybricks.hubs", "TechnicHub", "battery.voltage", [([], "int")]), pytest.param("pybricks.hubs", "TechnicHub", "battery.current", [([], "int")]), pytest.param( - "pybricks.hubs", "TechnicHub", "button.pressed", [([], "Set[Button]")] + "pybricks.hubs", "TechnicHub", "buttons.pressed", [([], "Set[Button]")] ), pytest.param( "pybricks.hubs", @@ -506,7 +506,7 @@ def _get_method_signature(module: str, type: str, method: str) -> SignatureHelp: [(["colors: Collection[Color]", "interval: Number"], "None")], ), pytest.param( - "pybricks.hubs", "EssentialHub", "button.pressed", [([], "Set[Button]")] + "pybricks.hubs", "EssentialHub", "buttons.pressed", [([], "Set[Button]")] ), pytest.param("pybricks.hubs", "EssentialHub", "imu.up", [([], "Side")]), pytest.param( diff --git a/src/pybricks/hubs.py b/src/pybricks/hubs.py index 8ba1e8b7..347ec04e 100644 --- a/src/pybricks/hubs.py +++ b/src/pybricks/hubs.py @@ -40,7 +40,7 @@ class MoveHub: light = _common.ColorLight() imu = _common.SimpleAccelerometer() system = _common.System() - button = _common.Keypad([_Button.CENTER]) + buttons = _common.Keypad([_Button.CENTER]) ble = _common.BLE() def __init__( @@ -74,7 +74,7 @@ class CityHub: battery = _common.Battery() light = _common.ColorLight() system = _common.System() - button = _common.Keypad([_Button.CENTER]) + buttons = _common.Keypad([_Button.CENTER]) ble = _common.BLE() def __init__( @@ -105,7 +105,7 @@ class TechnicHub: light = _common.ColorLight() imu = _common.IMU() system = _common.System() - button = _common.Keypad([_Button.CENTER]) + buttons = _common.Keypad([_Button.CENTER]) ble = _common.BLE() def __init__( @@ -146,7 +146,7 @@ class EssentialHub: # These class attributes are here for auto-documentation only. # In reality, they are instance attributes created by __init__. battery = _common.Battery() - button = _common.Keypad([_Button.CENTER]) + buttons = _common.Keypad([_Button.CENTER]) charger = _common.Charger() light = _common.ColorLight() imu = _common.IMU()