jippi / hass-nordnet

Home Assistant + Nordnet API = awesome sensors with for your investments & holdings
https://github.com/jippi/hass-nordnet
7 stars 0 forks source link

Addon fails to start when portfolio contains asset with GAK = 0 #8

Open janchrillesen opened 1 year ago

janchrillesen commented 1 year ago

I recently received "tegningsretter" for a stock (Green Hydrogen Systems). This has an acquisition price (GAK) of 0, and it causes the addon to fail to start

2023-06-27 21:05:23.350 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up nordnet platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 320, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/nordnet/sensor.py", line 24, in async_setup_entry
    sensor = NordnetStock(dict(holding), coordinator)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nordnet/sensor.py", line 37, in __init__
    self._attributes = self._remap(holding)
                       ^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nordnet/sensor.py", line 139, in _remap
    input['account_roi_percent'] = (input['position_market_price'] - input['position_acquisition_price']) / input['position_acquisition_price'] * 100
                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ZeroDivisionError: float division by zero
Skærmbillede 2023-06-27 kl  21 04 16

The simple solution would be to ignore these assets.