Add more units to distance conversion util#40181
Add more units to distance conversion util#40181balloob merged 11 commits intohome-assistant:devfrom
Conversation
DaAwesomeP
left a comment
There was a problem hiding this comment.
Great work! Please add tests for the new conversion functions. You should be able to model them off of the existing conversion function tests.
DaAwesomeP
left a comment
There was a problem hiding this comment.
Also, I assume that you checked that there are no instances of cm, in, or yd anywhere else in HA.
I would recommend to do that in a separate PR. |
|
Even though I asked if this should be done, previous PRs for adding units and conversions were not accepted if they weren't used in the code. See #35575 Can these conversions be used anywhere? |
Yeah I have found the proximity integration which could utilize all of these added units and conversions. I would just have to add the units to that integration and convert it here: |
|
Miles and yards I suppose make sense to add, but I don't see how millimeters, centimeters,n or inches would be used. I would imagine most entities use GPS for location which does not have sub-meter accuracy. |
|
You are probably right. Centimeters, millimeters and inches are just too precise for device trackers. Will remove them from the proximity integration. |
| @@ -34,19 +47,35 @@ def convert(value: float, unit_1: str, unit_2: str) -> float: | |||
|
|
|||
| if unit_1 == LENGTH_MILES: | |||
There was a problem hiding this comment.
For a future PR, instead of doing hundreds of if…elif statements, we should rewrite this like this:
TO_METERS = {
LENGTH_METERS: lambda meters: meters,
LENGTH_YARD: lambda yards: yards * 0.9144,
LENGTH_FEET: lambda feet: feet * 0.3048,
...
}
meters = TO_METERS[unit_1](value)|
Don't forget to update the docs for Proximity. |
Updated the docs accordingly: home-assistant/home-assistant.io#15578 |
Breaking change
Proposed change
#40116 has to be merged before
Adds the following length units to distance conversion util:
LENGTH_CENTIMETERSLENGTH_MILLIMETERSLENGTH_INCHESLENGTH_YARDMake LENGTH_YARD available in proximity integration.
cc @MatthewFlamm
Type of change
Example entry for
configuration.yaml:# Example configuration.yamlAdditional information
Checklist
black --fast 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..coveragerc.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: