custom-components / sensor.avanza_stock

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

unique id #136

Closed oli737 closed 11 months ago

oli737 commented 2 years ago

Unique id is ignoring the same stock I have in different depots of differen prices. I need track them individual which is not working anymore because it is ignoring the other ID now. Please fix that problem.

claha commented 2 years ago

Could you please provide an example configuration where you get this problem? A quick fix is to just install the previous version for now.

oli737 commented 2 years ago

Logger: homeassistant.components.sensor Source: helpers/entity_platform.py:593 Integration: Sensor (documentation, issues) First occurred: 00:32:48 (4 occurrences) Last logged: 00:32:48

Platform avanza_stock does not generate unique IDs. ID 365295_stock already exists - ignoring sensor........

  - id: 365295
    name: depot1_avanza_stock FTSE All-World DIS
    shares: 10
    purchase_price: 100.19

  - id: 365295
    name: depot2_avanza_stock FTSE All-World DIS
    shares: 10
    purchase_price:  99.93
damien67 commented 2 years ago

I am observing the same issue... Got multiple stocks bought multiple times at different prices. Used to work fine, but doesn't anymore. Thx!

claha commented 2 years ago

I did a small change to the unique id, but the result was then that I've got duplicates of each sensor and would have to manually remove the old ones (since the unique id changed). This is not something I would want to force upon every user of the component, so I will need to see if there is some way to migrate the old unique id. If you are comfortable you can always change this function yourself for now to generate a better id and remove your duplicates. https://github.com/custom-components/sensor.avanza_stock/blob/ff6053ccb91c65bf9a5ba2b843e7057c456470b8/custom_components/avanza_stock/sensor.py#L201

oli737 commented 2 years ago

The double sensor I have too without updating to this last version. No idea why is this. I found no way to remove duplicate sensors even when removed from config (and rebooted) and removed the integration too. They still can't be removed.

claha commented 2 years ago

Very strange, when you click on the entity it should be a button to remove it somewhere. Migration (of unique id) only seems to be possible if using config flow, I may have to dig into that... or just do the update to unique id, maybe most people haven't updated to version 1.0.12 yet

oli737 commented 2 years ago

After 2 more reboots i could delete the restored enitiys. All have now the name and "_2".

claha commented 2 years ago

That is what i've got as well, so to get back the original ids I gues one would have to delete/rename all of the _2

damien67 commented 2 years ago

Downgrading to 1.0.11 restored the original behavior. I will keep an eye on this thread before I further update this component!

dogmatic69 commented 1 year ago

Had to revert to 1.0.11 as this is also broken for me. I'd say it should be reverted as there is even an example in the readme for using the same id again so there is for sure the intention of having multiple instances of a specific stock.

claha commented 1 year ago

True, I have an example of that. I will try to get at it ASAP.

P.S. Pull requests are welcome :)

oli737 commented 1 year ago

Same problem as before.

Only one sensor show up. I need to separte those two even if its the same stock. Downgarde does not help anymore. Can you please help?

claha commented 1 year ago

Downgrading to before unique_id was introduced should help, otherwise you could alter the code yourself to make it even more unique by considering purchase_price etc. I don't want to push such a change since it will give new ids for all sensor and you will be left with a lot of unused ones and probably loose your history

dogmatic69 commented 1 year ago

Already lost all the history with the 0.11 change that completely broke everything. One entry per stock is not usable at all, most people do not buy stock once.

claha commented 1 year ago

True but your bank/broker probably calculates your average purchase price for you

oli737 commented 11 months ago

True but your bank/broker probably calculates your average purchase price for you

What is I have multiple broker or owners I track?

claha commented 11 months ago

You can now use the same id in multiple instances

oli737 commented 11 months ago

Oh cool thanks.