custom-components / sensor.avanza_stock

Custom component to get stock data from Avanza for Home Assistant
MIT License
46 stars 10 forks source link

Stock sensor stopped updating #186

Open divirg opened 2 weeks ago

divirg commented 2 weeks ago

Sensor updating stopped working, apparently for no reason. No change in configuration for was applied. It looks like the connection is forcibly corded

Logger: homeassistant.helpers.entity
Source: helpers/entity.py:942
First occurred: November 3, 2024 at 10:11:21 AM (295 occurrences)
Last logged: 8:11:21 PM

Update for sensor.alphabet fails
Update for sensor.apple fails
Update for sensor.robo_global fails
Update for sensor.health fails
Update for sensor.world_it fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 942, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1300, in async_device_update
    await self.async_update()
  File "/config/custom_components/avanza_stock/sensor.py", line 250, in async_update
    data = await pyavanza.get_stock_async(self._session, self._stock)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyavanza/__init__.py", line 87, in get_stock_async
    return await request_url_async(session, url)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pyavanza/__init__.py", line 67, in request_url_async
    async with session.get(url, raise_for_status=True) as resp:
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client.py", line 1355, in __aenter__
    self._resp: _RetType = await self._coro
                           ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client.py", line 492, in _request
    raise RuntimeError("Session is closed")
RuntimeError: Session is closed
divirg commented 2 weeks ago

I decided to restart home assistant and that fixed the issue. Before I close the issue is there anything I could test and report in future just in case the issue pops up again?

claha commented 2 weeks ago

One thing to check is if the api is down, you can do that by visiting this url in your browser:

https://www.avanza.se/_api/market-guide/stock/{orderbook_id}

Change "{orderbook_id}" to the id you have for your stock.

I dont think that was the issue here, did any other cloud-based sensors of yours fail too?

Thanks for reporting :)

divirg commented 2 weeks ago

No other web sensor failed in the whole HA. I'll check if it will ever happen again. Of course I can say that restarting HA fixed it immediately... Though I never like "restarting" as a solution, but since everything else was up, that was the last thing to try.

Closing the issue and thanks for the feedback.

divirg commented 2 weeks ago

It did happen again and API was correctly responding from the browser. If you suggest anything I could check or debug I would be happy to help. Restarting made an immediate sensor update. To be clear the stock price was frozen to the day before during opening hours, no update at all, I am not talking about delays. Happy to help if I can.

claha commented 2 weeks ago

I guess the error is the same as before, I'll try and find out why/when "Session is closed" happens and how to handle that

divirg commented 2 weeks ago

Happy to help, if you need anything just let me know.

RalfEs73 commented 4 days ago

That's right for me. I installed the addin for the first time yesterday. No update since then.

claha commented 4 days ago

That's right for me. I installed the addin for the first time yesterday. No update since then.

Any errors? What is your config?