Skip to content

Commit

Permalink
Update fingerprints_in_homeassistant.rst
Browse files Browse the repository at this point in the history
  • Loading branch information
rikroe committed Feb 11, 2024
1 parent f59746b commit b5567e6
Showing 1 changed file with 19 additions and 40 deletions.
59 changes: 19 additions & 40 deletions docs/source/development/fingerprints_in_homeassistant.rst
Original file line number Diff line number Diff line change
@@ -1,52 +1,31 @@
Using fingerprints in Home Assistant
====================================
Sometimes it can be useful to load the **fingerprints** used for our **pytest suite** in the development of the Home Assistant component.
Sometimes it can be useful to load the **fingerprints** used for our **pytest suite** in the development of the Home Assistant component.
This enables debugging of the UI in Home Assistant which is not possible from pytest alone.

Set up bimmer_connected
-----------------------
Clone the repository to ``~/bimmer_connected``:
.. warning::
If not already done, `set up the Home Assistant development environment <https://developers.home-assistant.io/docs/development_environment>`_.

.. code-block:: bash
Now start Home Assistant at least once and let all python packages install (``hass -c ./config``).
If not already done, set up the **BMW Connected Drive Integration** in Home Assistant.
Shut down Homeassistant afterwards.

git clone https://github.com/bimmerconnected/bimmer_connected.git ~/bimmer_connected
Now, we have to "hack" our mocked backend calls into Home Assistant.

.. note::

Make sure that you can access this path from inside your Home Assistant virtual environment!
Doing so will remove your own account!

Edit the ``_get_vehicles()`` function in `account.py#L370-L392 <https://github.com/bimmerconnected/bimmer_connected/blob/master/bimmer_connected/account.py#L370-L392>`_
and add the following code between ``self._get_oauth_token()`` and ``for brand in CarBrand:``:
Edit ``homeassistant/components/bmw_connected_drive/coordinator.py`` and locate the function ``_async_update_data``. We now have to replace ``await self.account.get_vehicles()``. The ``try .. except`` block should look like this:

.. code-block:: python
from pathlib import Path
files = (Path().home() / "bimmer_connected" / "test" / "responses").rglob("vehicles_v2_*_0.json")
for file in files:
for vehicle_dict in json.load(open(file, 'r')):
# If vehicle already exists, just update it's state
existing_vehicle = self.get_vehicle(vehicle_dict["vin"])
if existing_vehicle:
existing_vehicle.update_state(vehicle_dict)
else:
self._vehicles.append(MyBMWVehicle(self, vehicle_dict))
Set up Home Assistant
---------------------
If not already done, `set up the Home Assistant development environment <https://developers.home-assistant.io/docs/development_environment>`_.

Now start Home Assistant at least once and let all python packages install (``hass -c ./config``).
If not already done, set up the **BMW Connected Drive Integration** in Home Assistant.
Shut down Homeassistant afterwards.

In the Home Assistant virtual environment, install the freshly adjusted version of ``bimmer_connected``:

.. code-block:: bash
pip3 install -e ~/bimmer_connected
Start Home Assistant using ``hass -c ./config --skip-pip`` and see all cars we have fingerprints of + your own cars.

.. warning::
If ``--skip-pip`` is omitted when starting Home Assistant, the version of ``bimmer_connected`` defined in
``homeassistant/components/bmw_connected_drive/manifest.json`` will be loaded and the Home Assistant last two steps have to be executed again.
...
try:
from bimmer_connected.tests.conftest import MyBMWMockRouter, ALL_STATES, ALL_CHARGING_SETTINGS
with MyBMWMockRouter(["WBY00000000REXI01"], ALL_STATES, ALL_CHARGING_SETTINGS):
await self.account.get_vehicles()
except:
...
.. note::
As the first parameter, you can specify a list of VINs for debugging or leave it empty (``None`` or ``[]``) to load all vehicles of our test suite.

0 comments on commit b5567e6

Please sign in to comment.