datapoint-python
datapoint-python copied to clipboard
Question: Can the Forecast.now() method return False?
The Home Assistant project uses datapoint in its metoffice integration component. It has been using v0.4.3 of datapoint, which included the issue 19 (https://github.com/EJEP/datapoint-python/issues/19) causing the Forecast.now() method to return False shortly after midnight. This had a knock on effect to my Home Assistant metoffice component (https://github.com/home-assistant/home-assistant/issues/30114). The proposal for Home Assistant is to upgraded to datapoint v0.9.5 and are hopeful that this will resolve my issue with metoffice component...
... Except that in reading the documentation for the Forecast.now() method it states that it "returns: Timestep (or False)". If this is correct, then arguably the metoffice component should handle the False result gracefully. However, from inspecting the code, I can't see a condition under which Forecast.now() can return False. So to my question:
What is the design contract for the Forecast.now() method? Do you still want to allow it to return False or should the documentation be updated to say that the Forecast.now() will always return a Timestep object?
Thanks.
The documentation is inaccurate. The current design of Forecast.now() is to either return a Timestep or raise an exception if there are no Timesteps within 1.5 hours (for a 3 hourly forecast) or 6 hours (for a daily forecast).
@EJEP Thanks for that clarification. (For what it is worth, the behaviour your describe seems right to me :-)