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

Several accounts #6

Open chairman2s opened 2 years ago

chairman2s commented 2 years ago

It worked great with my Norwegian Nordnet account. My question is that I have several accounts on nordnet so I added the integration two times. The most important problem is that I own stock of the same kind on both of the accounts. So they come on the same sensor. The problem is that I get only one number of stocks correctly.

The other smaller problem is that the integration appears with the username on the integration page. It should be changeable or use the account name.

gforschi commented 1 year ago

Have the same issue with the same stock in different accounts

Blakout007 commented 1 year ago

Great solution, thanks. Same issue as above, as I am administrator for other users. Hope for a solution soon.

jippi commented 7 months ago

Hey, I only have a single account myself, so not something I plan to implement at this time - but would happily take contributions for it if someone else wants to take a stab at it :)

edgein666 commented 3 months ago

Same issue here, I have a pension account and a regular stock account with the same stocks in both, only one is shown.

A possible solution is to add the account number after the stock-name. I'm no developer but will have a look.

edgein666 commented 3 months ago

Got it to work!

image

I changed the code in sensor.py by adding the line:

account_number = holding['accno']

and modifying:

self._name = f"Stock price for {holding['instrument']['name']} ({holding['instrument']['symbol']})_{account_number}"
self._unique_id = f"nordnet_stock_{holding['instrument']['symbol'].replace(' ', '_').lower()}_{account_number}"

From sensor.py:

class NordnetStock(CoordinatorEntity, SensorEntity):

    def __init__(self, holding, coordinator):
        super().__init__(coordinator)

        self._state = "unavailable"
        self._attributes = self._remap(holding)
        account_number = holding['accno']
        self._name = f"Stock price for {holding['instrument']['name']} ({holding['instrument']['symbol']})_{account_number}"
        self._unique_id = f"nordnet_stock_{holding['instrument']['symbol'].replace(' ', '_').lower()}_{account_number}"
        self._symbol = holding['instrument']['symbol']

Sorry but I'm not so savvy to create a pull request etc., also this should be a setting I think, so it needs more code.

Good luck and thanks for a great Integration @jippi!