myTselection / Carbu_com

Actual fuel prices (super, diesel, lpg) per gasstation supported for Belgium, France, Luxembourg, Spain, Netherlands, Germany, Italy and US! Home Assistant custom component HACS integration for BE/FR/LU based on carbu.com and mazout.com site to compare and save on your actual fuel oil/heating oil (mazout) and fuel (diesel, super and lpg) purchases.
MIT License
23 stars 6 forks source link

Integration sometimes fails to setup #49

Closed FRvanderVeen closed 2 months ago

FRvanderVeen commented 3 months ago

Sometimes the integration fails to setup. The following error occurs in the logs in that case:

Error while setting up carbu_com platform for sensor
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/requests/models.py", line 974, in json
    return complexjson.loads(self.text, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/simplejson/__init__.py", line 514, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/simplejson/decoder.py", line 386, in decode
    obj, end = self.raw_decode(s)
               ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/simplejson/decoder.py", line 416, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 364, in _async_setup_platform
    await asyncio.shield(awaitable)
  File "/config/custom_components/carbu_com/sensor.py", line 193, in async_setup_entry
    await dry_setup(hass, config, async_add_devices)
  File "/config/custom_components/carbu_com/sensor.py", line 72, in dry_setup
    await componentData._forced_update()
  File "/config/custom_components/carbu_com/sensor.py", line 322, in _forced_update
    boundingboxLocationInfo = await self._hass.async_add_executor_job(lambda: self._session.convertLocationBoundingBox(self._postalcode, self._country, self._town))
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/carbu_com/sensor.py", line 322, in <lambda>
    boundingboxLocationInfo = await self._hass.async_add_executor_job(lambda: self._session.convertLocationBoundingBox(self._postalcode, self._country, self._town))
                                                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/ratelimit/decorators.py", line 113, in wrapper
    return func(*args, **kargs)
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/ratelimit/decorators.py", line 80, in wrapper
    return func(*args, **kargs)
           ^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/carbu_com/utils.py", line 166, in convertLocationBoundingBox
    orig_location = self.searchGeocodeOSM(postalcode, town, country_name)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/ratelimit/decorators.py", line 113, in wrapper
    return func(*args, **kargs)
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/ratelimit/decorators.py", line 80, in wrapper
    return func(*args, **kargs)
           ^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/carbu_com/utils.py", line 1225, in searchGeocodeOSM
    nominatim_data = nominatim_response.json()
                     ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/requests/models.py", line 978, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

It results in the sensor not being present. I tried enabling debug logging to see if I could see what's going on, but then stuff magicly started working again. From the stacktrace to me it looks like something going wrong with geocoding the postal code. But I may be wrong.

myTselection commented 2 months ago

I fixed several bugs in R11 related to the geocoding, could you try again? If still failing, please open a new ticket and indicate some example location so I can try to reproduce it.

thibmaek commented 2 months ago

This actually prevented my Home Assistant from starting. After the HAOS 13.1 upgrade my HA core would go into a crash loop. I had to restart HA in safe mode which showed that the issue was with a custom integration. I started deleting integrations installed with HACS one by one, and after deleting Carbu everything worked normally.

This was on latest HA stable, latest HAOS (in Proxmox 8), latest supervisor, HACS 2.0.0 as of writing

myTselection commented 2 months ago

thanks for reporting! I noticed some strange behavior too, but I tought it was caused by the new HACS 2.0 I just upgraded to. I'll look into it

myTselection commented 2 months ago

I'm not able to reproduce it in my local test env with latest HA and HACS 2.0. Did you see any exception that could give a direction on what's causing the crash loop?

myTselection commented 2 months ago

Which location or country did you use? For some countries the API_KEY is mandatory and if the configuration is not updated this may result in many failed initiations that could lead to a crash loop

myTselection commented 2 months ago

closing this ticket as #55 is outstanding