homeassistant-config icon indicating copy to clipboard operation
homeassistant-config copied to clipboard

Units of measurement are inappropriately determined in getUnit

Open im-batman opened this issue 5 years ago • 0 comments

In ui/weather-card.js, several units of measurement are decided based upon whether lengthUnit is set to "km" -- which assumes that the provided data are either all metric or all imperial. The default weather source for hass.io is met.no, which supports mixed metric and imperial data. The result is that the Lovelace weather forecast card (https://www.home-assistant.io/lovelace/weather-forecast/) shows air pressure (which is provided in mbar by the data source) as inHg instead.

Each measurement needs to have its own associated unit tied to the unit of the original data source, particularly air pressure in this instance.

weather-card.js:304:

  getUnit(measure) {
    const lengthUnit = this.hass.config.unit_system.length;
    switch (measure) {
      case "air_pressure":
        return lengthUnit === "km" ? "hPa" : "inHg";
      case "length":
        return lengthUnit;
      case "precipitation":
        return lengthUnit === "km" ? "mm" : "in";
      default:
        return this.hass.config.unit_system[measure] || "";
    }
  }

im-batman avatar Aug 13 '19 12:08 im-batman