audiconnect / audi_connect_ha

Adds an audi connect integration to home assistant
MIT License
224 stars 98 forks source link

Stack trace on unknown model type #416

Closed chrisjschultz closed 4 months ago

chrisjschultz commented 4 months ago

Describe the bug When Vehicle Model is unknown, the Audi Entity silently fails with a Stack Trace

This started for me recently. It did not happen when I initially set up this integration, about 2 months ago.

To Reproduce Steps to reproduce the behavior:

Have a weird car with no model?

Expected behavior All sesnors are correctly detected and loaded. Only the cars position sensor is loaded.

Screenshots None.

Logfile

AttributeError: 'NoneType' object has no attribute 'replace'
2024-04-28 19:56:47.275 ERROR (MainThread) [homeassistant.components.sensor] Error adding entity None for domain sensor with platform audiconnect
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 748, in _async_add_entity
    if self.config_entry and (device_info := entity.device_info):
                                             ^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/audiconnect/audi_entity.py", line 77, in device_info
    model_only = self._instrument.vehicle_model.replace("Audi ", "")
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Your Vehicle Details Model: etron Year: 2019 Type (ICE/PHEV/BEV): BEV

The code below resolves the issue and allows the integation to load...

custom_components/audiconnect/audi_entity.py

    @property
    def device_info(self):
        if self._instrument.vehicle_model is None:
          model_only = "eTron"
        else:
          model_only = self._instrument.vehicle_model.replace("Audi ", "")
coreywillwhat commented 4 months ago

Thanks for reporting @chrisjschultz ! See #417 . Let me know if you have any concerns.