iprak / yahoofinance

Home Assistant component which allows you to get stock updates from Yahoo finance.
MIT License
81 stars 11 forks source link

Converted market times sensor to ISO Date Time format & added AUD Currency #130

Closed cabberley closed 6 months ago

cabberley commented 6 months ago

This update provides 2 enhancements to your code

  1. Added AUD currency code so currency attribute will now correctly identify and display Australian stocks currencies. Previously it was displaying unknown.
  2. The regularMarketTime & postMarketTime attributes were being displayed in Epoch, added code to convert these to a full DateTime with TimeZone aware value.
iprak commented 6 months ago

You would need to adjust test_sensor.py as well. You can add a check like done for DATA_REGULAR_MARKET_PRICE or some other way to confirm the null return value for the 2 atributes.

    # All numeric values besides DATA_REGULAR_MARKET_PRICE should be 0
    for data_group in NUMERIC_DATA_GROUPS.values():
        for value in data_group:
            key = value[0]
            if (key != DATA_REGULAR_MARKET_PRICE) and (key != DATA_DIVIDEND_DATE):   # noqa: PLR1714
                assert attributes[key] == 0
cabberley commented 6 months ago

@iprak Thanks for the feedback. I have refactored the timestamp conversion and consolidated the two into a single one. The refactored also facilitates that Dividend Date is just a date no time. Market times, the date and time are relevant.

Also added the tests as requested.

iprak commented 6 months ago

The combined function now returns 0 for missing (None) input. We should keep previous behavior of None. In cases where data might be missing, the result None can be treated differently than 0.

iprak commented 6 months ago

Sorry but now a few different tests are failing. The tests are in test_sensor.py (test_parse_dividend_date) which is failing because it is using the older function.

cabberley commented 6 months ago

reverted return value to be date_timestamp value to support the None and 0 use case. If 0 gets through and converted it would result in a 1970 date. Rewrote the tests for the renamed function and added the extra testing to it to reflect the changes in the function. **Sorry been a little while since I have done all of this. Hopefully this fixes it all up.