Add speed to units system#58437
Conversation
|
Hey there @Danielhiversen, @thimic, mind taking a look at this pull request as it has been labeled with an integration ( |
|
Hey there @MatthewFlamm, mind taking a look at this pull request as it has been labeled with an integration ( |
|
Hey there @raman325, mind taking a look at this pull request as it has been labeled with an integration ( |
|
Hey there @DylanGore, mind taking a look at this pull request as it has been labeled with an integration ( |
|
@emontnemery continuing our discussion here (I've tangentially lost comment access on #53846, so hopefully you see I've split these PRs), I chose km/h to match the units I saw in most of Home Assistant, since most speeds were used for wind speed. I found that for preciptation speeds, there is a class of units prefixed by In that case, I wonder if we should add precipitation units to the unit system as well. TL;DR: |
|
I'm responding to some of the comments in the linked PR about using SI units in |
|
The bot locked comments on #53846, fixed now.
If that's the case, I think this change is good. @MatthewFlamm agreed km/h is more widely used, I just didn't want to block merge of #53846 by discussing what unit is preferred |
3c532f2 to
c40ca7b
Compare
|
I've rebased and marked this as ready for review. Happy to discuss more about unit choices & how we are handling other types of units like precipitation. |
|
How do we handle wind speeds and rainfall? In my own case (Sweden), we use "m/s" for wind speed, but we measure most other speeds in "km/h". Do we include rainfall in the unit system? |
|
In reverse order:
After working through the weather PR, I realize the forecast includes precipitation information ( I was trying to figure out how the code currently deals with precipitation and got stuck. I found this one snippet of the darksky I started at for a while before thinking maybe core/homeassistant/components/darksky/sensor.py Lines 147 to 157 in 363de37 However, in the arwn component precipitation is being used here as a length/thickness/volume: core/homeassistant/components/arwn/sensor.py Lines 47 to 53 in ea2e94a This makes me think we should have two units for both precipitation rate and accumulated precipitation .
Thank you for the correction! It sounds like the default should be |
|
Another thing: all these units are currently being set in the frontend rather than the core. Which means we do already have defaults, even if they aren't the best: See frontend/src/data/weather.ts export const getWeatherUnit = (
hass: HomeAssistant,
measure: string
): string => {
const lengthUnit = hass.config.unit_system.length || "";
switch (measure) {
case "pressure":
return lengthUnit === "km" ? "hPa" : "inHg";
case "wind_speed":
return `${lengthUnit}/h`;
case "visibility":
case "length":
return lengthUnit;
case "precipitation":
return lengthUnit === "km" ? "mm" : "in";
case "humidity":
case "precipitation_probability":
return "%";
default:
return hass.config.unit_system[measure] || "";
}
};Ideally these units could be queried from Home Assistant, but that's a change for another PR. |
I'm not sure what default unit is preferred, but no matter what we go for we should make it possible to override the wind speed unit in the unit system both via yaml and frontend IMHO. |
|
What is the user impact if we merge this? You mention the frontend already supports weather units, does it convert them too, so a wind speed in |
|
I don't forsee any user impact if we merge this, since the wind speed units is hardcoded on the frontend and this PR doesn't do any conversions.
|

Proposed change
This is a result of splitting #53846. This PR builds on the speed conversion functions to make speed a part of the units system.
There are a lot of commits here, but I will rebase once the former PR gets merged.
Type of change
Additional information
Checklist
black --fast homeassistant tests)If user exposed functionality or configuration variables are added/changed:
To help with the load of incoming pull requests: