diff --git a/docs/source/development/fingerprints_in_homeassistant.rst b/docs/source/development/fingerprints_in_homeassistant.rst index 68202c16..da3e66eb 100644 --- a/docs/source/development/fingerprints_in_homeassistant.rst +++ b/docs/source/development/fingerprints_in_homeassistant.rst @@ -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 `_. -.. 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 `_ -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 `_. - -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.