Allow for SI units in forcasts#217
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #217 +/- ##
==========================================
+ Coverage 93.79% 94.09% +0.30%
==========================================
Files 9 9
Lines 645 661 +16
==========================================
+ Hits 605 622 +17
+ Misses 40 39 -1 ☔ View full report in Codecov by Sentry. |
|
Thanks for this PR! I am +1 for getting this in. NWS is flaky with respect to honoring the requested units. This library provides some double checks and conversions in the This code below smells incorrect, although maybe not wrong. And, it isn't commented very well on what the purpose is. There is some conversion between temperature units here. It looks like the conversion can go both ways, so I'm not sure that anything needs to be changed. This maybe more of a note to remember for reviewers including me to look into how this PR interacts with that code bit. Lines 519 to 529 in 20186a8 |
MatthewFlamm
left a comment
There was a problem hiding this comment.
Some comments on my first read through.
|
Cool! |
makushimu
left a comment
There was a problem hiding this comment.
Thanks for all the prompt reviews!
|
Ah yeah, by using a StrEnum, this limits to python 3.11 and greater. I can probably emulate the StrEnum behaviour with a regular enum that will make it work for older versions. |
There's a backport in place already. Look at |
|
Should be better now. I'm not sure about the test changes that I did, but that felt like the cleanest way to handle the parameters. I'm open to updating it to something better, of course! |
src/pynws/forecast_units.py
Outdated
| from .backports.enum import StrEnum | ||
|
|
||
|
|
||
| class NwsForecastUnits(StrEnum): |
There was a problem hiding this comment.
Should we move this to const.py where other values are stored? Or will we prefer to make them separate in the future?
There was a problem hiding this comment.
Also, not sure this needs the Nws prefix as that isn't done elsewhere.
There was a problem hiding this comment.
I agree with moving to const.py.
We have a bit of mixed bag on naming currently. Most constants do not have a Nws prefix, although the error does. In my experience most python packages do not prefix the package, or related, name on variables inside their namespace. I would vote for no prefix to be most consistent with the rest of the package.
There was a problem hiding this comment.
My idea behind the separate file was because this class would be "public" vs the more "private" values that are stored in the const.py, but this makes sense too.
MatthewFlamm
left a comment
There was a problem hiding this comment.
I haven't looked at the testing changes, yet but this is looking really close.
- Remove Nws prefix for NwsForecastUnits enum - Move ForecastUnits to const.py file - Make all raw_data functions that depend on ForecastUnits have a default value
MatthewFlamm
left a comment
There was a problem hiding this comment.
One small nit, but otherwise LGTM
Co-authored-by: MatthewFlamm <39341281+MatthewFlamm@users.noreply.github.com>
|
@lymanepp you have requested changes earlier. We can wait to merge in case you have other comments. |
This allows to request the forecast data to be natively returned with SI units instead of US customary units.
While the lib currently converts the returned value to SI, it can't really convert the textual observations due to its free form text nature. My ultimate goal is to expose this to home assistant.
There is no change to the default values, so there should be no change to existing code.
Still missing some new tests to cover this feature, but I wanted to at least have this out there for initial review.