Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stock sensor stopped updating #186

Open
divirg opened this issue Nov 5, 2024 · 14 comments
Open

Stock sensor stopped updating #186

divirg opened this issue Nov 5, 2024 · 14 comments

Comments

@divirg
Copy link

divirg commented Nov 5, 2024

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
Copy link
Author

divirg commented Nov 5, 2024

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
Copy link
Member

claha commented Nov 6, 2024

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
Copy link
Author

divirg commented Nov 6, 2024

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 divirg closed this as completed Nov 6, 2024
@divirg
Copy link
Author

divirg commented Nov 9, 2024

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.

@divirg divirg reopened this Nov 9, 2024
@claha
Copy link
Member

claha commented Nov 9, 2024

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
Copy link
Author

divirg commented Nov 9, 2024

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

@RalfEs73
Copy link

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

@claha
Copy link
Member

claha commented Nov 19, 2024

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

Any errors? What is your config?

@roelvandermade
Copy link

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

Any errors? What is your config?

Same here (trying to prevent the 'same here!' only reply ;-)
No config changes, only updates once after a HA restart and that's it. I turned on Debug logging which only shows one line after the restart and then goes silent:

2024-12-16 18:54:56.245 DEBUG (MainThread) [custom_components.avanza_stock.sensor] Tracking Tesla [238449] using Avanza

my config (in sensors.yaml):

- platform: avanza_stock
  stock: 238449
  name: Tesla

If I can help in providing more info or such, let me know.

cheers

@BlaXun
Copy link

BlaXun commented Jan 9, 2025

Same for me. Sensors didnt fetch new state for 21 Minutes now. I am tracking the last updated timesstamp (as the built-in attribute is never populated)

@claha
Copy link
Member

claha commented Jan 9, 2025

Same for me. Sensors didnt fetch new state for 21 Minutes now. I am tracking the last updated timesstamp (as the built-in attribute is never populated)

60minutes is the default update interval, unless you configured something else. I just checked my stocks and they updated 5min ago

@BlaXun
Copy link

BlaXun commented Jan 9, 2025

Same for me. Sensors didnt fetch new state for 21 Minutes now. I am tracking the last updated timesstamp (as the built-in attribute is never populated)

60minutes is the default update interval, unless you configured something else. I just checked my stocks and they updated 5min ago

Hold on, thats configurable? I thought it was fixed at 15 minute intervalls... how did I not see that!?

Okay, found the 60 minutes in the source code. Is there any limit they are enforcing? Whats the lowest I could go?

@claha
Copy link
Member

claha commented Jan 9, 2025

You can do

- platform: avanza_stock
  scan_interval: 60

I guess 1,1min is the lowest. This is builtin (somehow) since this is a yaml only integraton.

@claha
Copy link
Member

claha commented Jan 9, 2025

Not sure if avanza could ip block you though, bit never happened what Ive heard 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants