Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Documentation for captcha #680

Merged
merged 4 commits into from
Nov 24, 2024
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
14 changes: 8 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ While this library is mainly written to be included in `Home Assistant <https://
After installation, execute :code:`bimmerconnected` from command line for usage instruction
or see the full `CLI documentation <http://bimmer-connected.readthedocs.io/en/stable/#cli>`_.

.. warning::

Login to **north american** and **rest of world** accounts requires a captcha to be solved. See `Using Captchas <http://bimmer-connected.readthedocs.io/en/stable/captcha.html>`_ for more information.

Please be aware that :code:`bimmer_connected` is an :code:`async` library when using it in Python code.
The description of the :code:`modules` can be found in the `module documentation
<http://bimmer-connected.readthedocs.io/en/stable/#module>`_.

.. note::
Login to **north american** accounts requires a captcha to be solved. See `Captcha (North America) <http://bimmer-connected.readthedocs.io/en/stable/captcha.html>`_ for more information.

Example in an :code:`asyncio` event loop
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
::
Expand All @@ -55,7 +56,8 @@ Example in an :code:`asyncio` event loop
from bimmer_connected.api.regions import Regions

async def main():
account = MyBMWAccount(USERNAME, PASSWORD, Regions.REST_OF_WORLD)
# hcaptcha_token is only required for the first login, see the captcha documentation
account = MyBMWAccount(USERNAME, PASSWORD, Regions.REST_OF_WORLD, hcaptcha_token="P1_eY...")
await account.get_vehicles()
vehicle = account.get_vehicle(VIN)
print(vehicle.brand, vehicle.name, vehicle.vin)
Expand All @@ -75,8 +77,8 @@ Example in non-async code
from bimmer_connected.account import MyBMWAccount
from bimmer_connected.api.regions import Regions


account = MyBMWAccount(USERNAME, PASSWORD, Regions.REST_OF_WORLD)
# hcaptcha_token is only required for the first login, see the captcha documentation
account = MyBMWAccount(USERNAME, PASSWORD, Regions.REST_OF_WORLD, hcaptcha_token="P1_eY...")
asyncio.run(account.get_vehicles())
vehicle = account.get_vehicle(VIN)
print(vehicle.brand, vehicle.name, vehicle.vin)
Expand Down
44 changes: 29 additions & 15 deletions docs/source/captcha.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,27 @@ Using Captchas

The **first** login requires a captcha to be solved. Follow-up logins using refresh token do not require a captcha (if login data is persisted).

.. note::
The captcha token is only valid for a short time and can only be used once.
Getting a captcha token
------------------------

Depending on your region, you will need to solve a different captcha. Please select the appropriate region below.

- `North America <captcha/north_america.html>`_
- `Rest of World <captcha/rest_of_world.html>`_

Using the Python API
---------------------

When using the Python API, pass the token via the :code:`hcaptcha_token` argument when creating the account object.

.. warning::
The captcha token is only valid for a short time and can only be used once.

Ensure to save the current :code:`MyBMWAccount` instance (or at least, the :code:`refresh_token` and :code:`gcid` attributes) to avoid having to solve the captcha again.

::

account = MyBMWAccount(USERNAME, PASSWORD, REGION, hcaptcha_token=HCAPTCHA_TOKEN)
Using Home Assistant
--------------------

When using the Home Assistant integration, simply paste the token into the config flow when configuring the account.

Using the CLI
-------------
When using the CLI, pass the token via the :code:`--hcaptcha-token` argument (see `CLI documentation <cli.html#named-arguments>`_).

.. warning::

Please make sure to use the :code:`--oauth-store` (used by default) to avoid having to solve the captcha again.
When using the CLI, pass the token via the :code:`--captcha-token` argument (see `CLI documentation <cli.html#named-arguments>`_).

::

Expand All @@ -43,4 +35,26 @@ After a successful login, the :code:`--captcha-token` parameter can be omitted (

bimmerconnected status USERNAME PASSWORD REGION

.. note::

Please make sure to use the :code:`--oauth-store` (used by default) to avoid having to solve the captcha again.

Using the Python API
---------------------

When using the Python API, pass the token via the :code:`hcaptcha_token` argument when creating the account object.

::

account = MyBMWAccount(USERNAME, PASSWORD, REGION, hcaptcha_token=HCAPTCHA_TOKEN)

.. warning::

Ensure to keep the current :code:`MyBMWAccount` instance in memory to avoid having to solve the captcha again.

For storing the data across restarts, an example implementation can be found in
`bimmerconnected.main() <https://github.com/bimmerconnected/bimmer_connected/blob/40ba148579da6b45268ea8ed9eb252cbafbe9042/bimmer_connected/cli.py#L328>`_
(with :code:`args.oauth_store` being a :code:`pathlib.Path()` object).

If you are running this script inside another system (e.g. demoticz), you can also store and read the information using their native tools
- it does not have to be a JSON file, as long as the data is stored and read correctly.
2 changes: 1 addition & 1 deletion docs/source/captcha/north_america.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Captcha (North America)
=======================

Please see :doc:`../captcha` for general information on using captchas.
Please confirm that you are a human and submit the form. See :doc:`../captcha` for more information.

.. raw:: html
:file: north_america_form.html
2 changes: 1 addition & 1 deletion docs/source/captcha/rest_of_world.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Captcha (Rest of World)
=======================

Please see :doc:`../captcha` for general information on using captchas.
Please confirm that you are a human and submit the form. See :doc:`../captcha` for more information.

.. raw:: html
:file: rest_of_world_form.html
6 changes: 4 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import datetime

# Configuration file for the Sphinx documentation builder.
#
# This file does only contain a selection of the most common options. For a
Expand All @@ -17,8 +19,8 @@
# -- Project information -----------------------------------------------------

project = 'bimmer_connected'
copyright = '2018-2020, m1n3rva, gerard33'
author = 'rikroe'
copyright = f'2018-{datetime.datetime.now().year}, m1n3rva, gerard33, rikroe'
author = 'm1n3rva, gerard33, rikroe'

# The short X.Y version
# version = const.__version__
Expand Down
Loading