-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding OpenWeatherMap Minutely forecast action #128799
base: dev
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
Hey there @fabaff, @freekode, @nzapponi, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is Minutely a proper word?
Better to use the OpenWeatherMap lingo: Minute forecast.
I now see that they use minutely
as a parameter name. It's fine it use that word in the code.
But I suggest using Minute
in texts that a User will see.
@@ -104,6 +111,14 @@ def _convert_weather_response(self, weather_report: WeatherReport): | |||
], | |||
} | |||
|
|||
def _get_minutely_weather_data(self, minutely_forecast): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add typing to the function?
for item in minutely_forecast | ||
] | ||
|
||
return {f"{Platform.WEATHER}.{DOMAIN}": {"forecast": forecasts}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how much this adds if its static
return round(precipitation["3h"], 2) | ||
if "1h" in precipitation: | ||
return round(precipitation["1h"], 2) | ||
if precipitation is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When would it be none?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pyopenweathermap library >0.2.0 seems to have introduced the possibility of None values being included for rain and snow: wind_gust=14.92, wind_bearing=140, rain=None, snow=None
.
I'll raise, and possibly fix, the issue on pyopenweathermap.
Edit: rain and snow only appear in the response from the API if they are due / above zero, which appears to cause the None. Previously, they were empty dictionaries.
@@ -6,5 +6,5 @@ | |||
"documentation": "https://www.home-assistant.io/integrations/openweathermap", | |||
"iot_class": "cloud_polling", | |||
"loggers": ["pyopenweathermap"], | |||
"requirements": ["pyopenweathermap==0.1.1"] | |||
"requirements": ["pyopenweathermap==0.2.1"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we bump this in a separate preliminary PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do, pending resolution of the comment above (None values) as it may require a new version.
if mode == OWM_MODE_V30: | ||
hass.services.async_register( | ||
domain=DOMAIN, | ||
service=SERVICE_GET_MINUTELY_FORECAST, | ||
service_func=handle_get_minutely_forecasts, | ||
supports_response=SupportsResponse.ONLY, | ||
) | ||
else: | ||
hass.services.async_remove( | ||
domain=DOMAIN, | ||
service=SERVICE_GET_MINUTELY_FORECAST, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Services should be registered in async_setup
and should not be removed on runtime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only called when the user makes a change to the integration configuration (Settings
-> Devices & Services
-> OpenWeatherMap
-> Configure
) and changes the forecast mode of the integration to a mode which does not support Minute forecasting. As such, this isn't really on runtime: it's only when the user reconfigures the integration without first deleting it.
If the service isn't removed when using an unsupported mode, the user will simply be returned an empty forecast - with no feedback as to the reason. I would argue that is worse UX.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the mode of the user is incorrect, you can raise a ServiceValidationError, explaining why it failed. More info about this can be found for now in https://github.com/home-assistant/developers.home-assistant/pull/2400/files
@@ -0,0 +1 @@ | |||
get_minutely_forecasts: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need to add a location or anything? What if I have OWM setup twice?
Agreed. I had thought that it fitted neatly with "daily" and "hourly", but you're right: it does not mean "minute-by-minute". Will change. |
Proposed change
This PR adds functionality to the OpenWeatherMap integration to expose Minutely foreasts as an Action. Minutely forecasts compliment Daily and Hourly forecasts by providing precipitation (rain or snow) levels for each minute of the next hour.
Instead of creating 60 separate sensors, or even 60 state attributes of a single sensor, this PR creates a new Service accessible as an OpenWeatherMap Action. It returns a response in the same format as
weather.get_forecasts
, with 60 objects containing adatetime
in UTC (starting now) andprecipitation
in mm/h.Key changes:
handle_get_minutely_forecast
inservices.py
minutely_forecast
data incoordinator.py
(no additional API data is requested)Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
.To help with the load of incoming pull requests: