Closed cabberley closed 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
@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.
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.
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.
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.
This update provides 2 enhancements to your code