diff --git a/homeassistant/components/bom/sensor.py b/homeassistant/components/bom/sensor.py index 8386409d3ea..59ee8027180 100644 --- a/homeassistant/components/bom/sensor.py +++ b/homeassistant/components/bom/sensor.py @@ -20,6 +20,7 @@ from homeassistant.const import ( CONF_MONITORED_CONDITIONS, CONF_NAME, LENGTH_KILOMETERS, + LENGTH_METERS, SPEED_KILOMETERS_PER_HOUR, TEMP_CELSIUS, UNIT_PERCENTAGE, @@ -73,7 +74,7 @@ SENSOR_TYPES = { "rel_hum": ["Relative Humidity", UNIT_PERCENTAGE], "sea_state": ["Sea State", None], "swell_dir_worded": ["Swell Direction", None], - "swell_height": ["Swell Height", "m"], + "swell_height": ["Swell Height", LENGTH_METERS], "swell_period": ["Swell Period", None], "vis_km": [f"Visability {LENGTH_KILOMETERS}", LENGTH_KILOMETERS], "weather": ["Weather", None], diff --git a/homeassistant/components/darksky/sensor.py b/homeassistant/components/darksky/sensor.py index e4471b7e55f..ab639b2e6a2 100644 --- a/homeassistant/components/darksky/sensor.py +++ b/homeassistant/components/darksky/sensor.py @@ -15,6 +15,7 @@ from homeassistant.const import ( CONF_MONITORED_CONDITIONS, CONF_NAME, CONF_SCAN_INTERVAL, + LENGTH_CENTIMETERS, LENGTH_KILOMETERS, SPEED_KILOMETERS_PER_HOUR, SPEED_METERS_PER_SECOND, @@ -128,11 +129,11 @@ SENSOR_TYPES = { ], "precip_accumulation": [ "Precip Accumulation", - "cm", + LENGTH_CENTIMETERS, "in", - "cm", - "cm", - "cm", + LENGTH_CENTIMETERS, + LENGTH_CENTIMETERS, + LENGTH_CENTIMETERS, "mdi:weather-snowy", ["hourly", "daily"], ], diff --git a/homeassistant/components/garmin_connect/const.py b/homeassistant/components/garmin_connect/const.py index 3b8d99c486a..3c30340fc61 100644 --- a/homeassistant/components/garmin_connect/const.py +++ b/homeassistant/components/garmin_connect/const.py @@ -1,6 +1,7 @@ """Constants for the Garmin Connect integration.""" from homeassistant.const import ( DEVICE_CLASS_TIMESTAMP, + LENGTH_METERS, MASS_KILOGRAMS, TIME_MINUTES, UNIT_PERCENTAGE, @@ -32,7 +33,13 @@ GARMIN_ENTITY_LIST = { False, ], "netCalorieGoal": ["Net Calorie Goal", "cal", "mdi:food", None, False], - "totalDistanceMeters": ["Total Distance Mtr", "m", "mdi:walk", None, True], + "totalDistanceMeters": [ + "Total Distance Mtr", + LENGTH_METERS, + "mdi:walk", + None, + True, + ], "wellnessStartTimeLocal": [ "Wellness Start Time", "", @@ -48,7 +55,13 @@ GARMIN_ENTITY_LIST = { False, ], "wellnessDescription": ["Wellness Description", "", "mdi:clock", None, False], - "wellnessDistanceMeters": ["Wellness Distance Mtr", "m", "mdi:walk", None, False], + "wellnessDistanceMeters": [ + "Wellness Distance Mtr", + LENGTH_METERS, + "mdi:walk", + None, + False, + ], "wellnessActiveKilocalories": [ "Wellness Active KiloCalories", "kcal", @@ -81,8 +94,20 @@ GARMIN_ENTITY_LIST = { None, True, ], - "floorsAscendedInMeters": ["Floors Ascended Mtr", "m", "mdi:stairs", None, False], - "floorsDescendedInMeters": ["Floors Descended Mtr", "m", "mdi:stairs", None, False], + "floorsAscendedInMeters": [ + "Floors Ascended Mtr", + LENGTH_METERS, + "mdi:stairs", + None, + False, + ], + "floorsDescendedInMeters": [ + "Floors Descended Mtr", + LENGTH_METERS, + "mdi:stairs", + None, + False, + ], "floorsAscended": ["Floors Ascended", "floors", "mdi:stairs", None, True], "floorsDescended": ["Floors Descended", "floors", "mdi:stairs", None, True], "userFloorsAscendedGoal": [ diff --git a/homeassistant/components/isy994/sensor.py b/homeassistant/components/isy994/sensor.py index c8c427a5bf5..bc213d805ce 100644 --- a/homeassistant/components/isy994/sensor.py +++ b/homeassistant/components/isy994/sensor.py @@ -5,7 +5,9 @@ from typing import Callable from homeassistant.components.sensor import DOMAIN from homeassistant.const import ( CONCENTRATION_PARTS_PER_MILLION, + LENGTH_CENTIMETERS, LENGTH_KILOMETERS, + LENGTH_METERS, MASS_KILOGRAMS, POWER_WATT, SPEED_KILOMETERS_PER_HOUR, @@ -35,7 +37,7 @@ UOM_FRIENDLY_NAME = { "1": "amp", "3": f"btu/{TIME_HOURS}", "4": TEMP_CELSIUS, - "5": "cm", + "5": LENGTH_CENTIMETERS, "6": "ft³", "7": f"ft³/{TIME_MINUTES}", "8": "m³", @@ -66,7 +68,7 @@ UOM_FRIENDLY_NAME = { "35": "l", "36": "lx", "37": "mercalli", - "38": "m", + "38": LENGTH_METERS, "39": "m³/hr", "40": SPEED_METERS_PER_SECOND, "41": "mA", diff --git a/homeassistant/components/mysensors/sensor.py b/homeassistant/components/mysensors/sensor.py index e528d7c4baa..3e9d39fa64b 100644 --- a/homeassistant/components/mysensors/sensor.py +++ b/homeassistant/components/mysensors/sensor.py @@ -3,6 +3,7 @@ from homeassistant.components import mysensors from homeassistant.components.sensor import DOMAIN from homeassistant.const import ( ENERGY_KILO_WATT_HOUR, + LENGTH_METERS, MASS_KILOGRAMS, POWER_WATT, TEMP_CELSIUS, @@ -26,12 +27,12 @@ SENSORS = { "V_GUST": [None, "mdi:weather-windy"], "V_DIRECTION": [UNIT_DEGREE, "mdi:compass"], "V_WEIGHT": [MASS_KILOGRAMS, "mdi:weight-kilogram"], - "V_DISTANCE": ["m", "mdi:ruler"], + "V_DISTANCE": [LENGTH_METERS, "mdi:ruler"], "V_IMPEDANCE": ["ohm", None], "V_WATT": [POWER_WATT, None], "V_KWH": [ENERGY_KILO_WATT_HOUR, None], "V_LIGHT_LEVEL": [UNIT_PERCENTAGE, "mdi:white-balance-sunny"], - "V_FLOW": ["m", "mdi:gauge"], + "V_FLOW": [LENGTH_METERS, "mdi:gauge"], "V_VOLUME": ["m³", None], "V_LEVEL": { "S_SOUND": ["dB", "mdi:volume-high"], diff --git a/homeassistant/components/proximity/__init__.py b/homeassistant/components/proximity/__init__.py index c82818bca1a..4b6ff477053 100644 --- a/homeassistant/components/proximity/__init__.py +++ b/homeassistant/components/proximity/__init__.py @@ -8,6 +8,7 @@ from homeassistant.const import ( CONF_UNIT_OF_MEASUREMENT, CONF_ZONE, LENGTH_KILOMETERS, + LENGTH_METERS, ) import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity @@ -33,7 +34,7 @@ DEFAULT_PROXIMITY_ZONE = "home" DEFAULT_TOLERANCE = 1 DOMAIN = "proximity" -UNITS = [LENGTH_KILOMETERS, "m", "mi", "ft"] +UNITS = [LENGTH_KILOMETERS, LENGTH_METERS, "mi", "ft"] ZONE_SCHEMA = vol.Schema( { @@ -210,7 +211,7 @@ class Proximity(Entity): # Add the device and distance to a dictionary. distances_to_zone[device] = round( - convert(dist_to_zone, "m", self.unit_of_measurement), 1 + convert(dist_to_zone, LENGTH_METERS, self.unit_of_measurement), 1 ) # Loop through each of the distances collected and work out the diff --git a/homeassistant/components/zamg/sensor.py b/homeassistant/components/zamg/sensor.py index 6580ab0917f..a9f43f0fb21 100644 --- a/homeassistant/components/zamg/sensor.py +++ b/homeassistant/components/zamg/sensor.py @@ -17,6 +17,7 @@ from homeassistant.const import ( CONF_LONGITUDE, CONF_MONITORED_CONDITIONS, CONF_NAME, + LENGTH_METERS, SPEED_KILOMETERS_PER_HOUR, TEMP_CELSIUS, UNIT_DEGREE, @@ -64,7 +65,12 @@ SENSOR_TYPES = { # The following probably not useful for general consumption, # but we need them to fill in internal attributes "station_name": ("Station Name", None, "Name", str), - "station_elevation": ("Station Elevation", "m", "Höhe m", int), + "station_elevation": ( + "Station Elevation", + LENGTH_METERS, + f"Höhe {LENGTH_METERS}", + int, + ), "update_date": ("Update Date", None, "Datum", str), "update_time": ("Update Time", None, "Zeit", str), } diff --git a/homeassistant/core.py b/homeassistant/core.py index 8ad8c24bd53..b3f4a68e37f 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -56,6 +56,7 @@ from homeassistant.const import ( EVENT_STATE_CHANGED, EVENT_TIME_CHANGED, EVENT_TIMER_OUT_OF_SYNC, + LENGTH_METERS, MATCH_ALL, __version__, ) @@ -1324,7 +1325,7 @@ class Config: Async friendly. """ return self.units.length( - location.distance(self.latitude, self.longitude, lat, lon), "m" + location.distance(self.latitude, self.longitude, lat, lon), LENGTH_METERS ) def path(self, *path: str) -> str: diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py index 8c7b103f834..b6c59604b74 100644 --- a/homeassistant/helpers/template.py +++ b/homeassistant/helpers/template.py @@ -19,6 +19,7 @@ from homeassistant.const import ( ATTR_LATITUDE, ATTR_LONGITUDE, ATTR_UNIT_OF_MEASUREMENT, + LENGTH_METERS, MATCH_ALL, STATE_UNKNOWN, ) @@ -638,7 +639,7 @@ def distance(hass, *args): return hass.config.distance(*locations[0]) return hass.config.units.length( - loc_util.distance(*locations[0] + locations[1]), "m" + loc_util.distance(*locations[0] + locations[1]), LENGTH_METERS )