From 0ceabe84978dc2926a870afb2afd792889fb20de Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Fri, 14 Jan 2022 15:12:39 +0100 Subject: [PATCH] pybricks.common.Charger: Document it. --- doc/main/hubs/primehub.rst | 8 ++++++++ src/pybricks/_common.py | 34 ++++++++++++++++++++++++++++++++++ src/pybricks/hubs.py | 3 ++- 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/doc/main/hubs/primehub.rst b/doc/main/hubs/primehub.rst index a194296..39be2eb 100644 --- a/doc/main/hubs/primehub.rst +++ b/doc/main/hubs/primehub.rst @@ -83,6 +83,14 @@ Prime Hub / Inventor Hub .. automethod:: pybricks.hubs::PrimeHub.battery.current + .. rubric:: Getting the charger status + + .. automethod:: pybricks.hubs::PrimeHub.charger.connected + + .. automethod:: pybricks.hubs::PrimeHub.charger.current + + .. automethod:: pybricks.hubs::PrimeHub.charger.status + .. rubric:: System control .. automethod:: pybricks.hubs::PrimeHub.system.set_stop_button diff --git a/src/pybricks/_common.py b/src/pybricks/_common.py index 534d907..2ef202d 100644 --- a/src/pybricks/_common.py +++ b/src/pybricks/_common.py @@ -708,6 +708,40 @@ class Battery: pass +class Charger: + """Get the status of a battery charger.""" + + def connected(self): + """Checks whether a charger is connected via USB. + + Returns: + bool: ``True`` if a charger is connected, ``False`` if not. + """ + + def status(self): + """Gets the status of the battery charger, represented by one of the + following values. This corresponds to the battery light indicator + right next to the USB port. + + 0. Not charging (off). + 1. Charging (red). + 2. Charging is complete (green). + 3. There is a problem with the charger (yellow). + + Returns: + int: Status value. + """ + pass + + def current(self): + """Gets the charging current. + + Returns: + :ref:`current`: Charging current. + """ + pass + + class SimpleAccelerometer: """Get measurements from an accelerometer.""" diff --git a/src/pybricks/hubs.py b/src/pybricks/hubs.py index 1fbfefe..80ff5ef 100644 --- a/src/pybricks/hubs.py +++ b/src/pybricks/hubs.py @@ -5,7 +5,7 @@ from ._common import (Speaker as _Speaker, Battery as _Battery, ColorLight as _ColorLight, Keypad as _Keypad, LightMatrix as _LightMatrix, IMU as _IMU, - System as _System, + Charger as _Charger, System as _System, SimpleAccelerometer as _SimpleAccelerometer) from .ev3dev._speaker import Speaker as _EV3Speaker from .geometry import Axis as _Axis @@ -94,6 +94,7 @@ class PrimeHub: _Button.CENTER, _Button.BLUETOOTH, )) + charger = _Charger() light = _ColorLight() display = _LightMatrix(5, 5) speaker = _Speaker()