Closed claha closed 4 years ago
I think the most approperiate name for the new optional configuration variable should be 'conversion_rate'. Note that there should also be an optional 'currency' configuration, but it should be mandatory if conversion_rate is defined, and the other way around
vol.Inclusive seems like the thing to use for data validation
Example of how to get another sensor into a integration https://github.com/home-assistant/core/blob/dc52b858a40905c129684a8e964ce182c4ff00df/homeassistant/components/spaceapi/__init__.py (hass.states.get)
The current solution does not convert amount per share for dividends
For currency conversion, what about adding an optional "conversion_currency" attribute for each stock? For USDSEK the value would be 19000 taken from this url: https://www.avanza.se/index/om-indexet.html/19000/usd-sek. This in turn can, together with numberOfShares, be used to calculate total value in SEK. If you want, I can help test this as I own AAPL stocks ;-)
That would probably be the cleanest way of doing this. I hope you bought your Apple stocks a long time ago :)
@imist I've updated to component to support a conversion_currency attribute. It seems to work fine for me but would be happy if you could also test it out before I release it. If you use hacs you can select to install master or just copy the files manually.
It would be useful to be able to specify the currency, i.e. to automatically convert from usd to sek. I see two possible solutions.
Option 1 seems like the best one, since it could use a constant (template sensor, input slider, ...) or another avanza_stock sensor, the only requirement would be that the sensor state is a number