Use LENGTH_METERS constant (#34110)

This commit is contained in:
springstan 2020-04-12 21:44:56 +02:00 committed by GitHub
parent 538bb60022
commit 00b6409b76
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 57 additions and 18 deletions

View file

@ -20,6 +20,7 @@ from homeassistant.const import (
CONF_MONITORED_CONDITIONS, CONF_MONITORED_CONDITIONS,
CONF_NAME, CONF_NAME,
LENGTH_KILOMETERS, LENGTH_KILOMETERS,
LENGTH_METERS,
SPEED_KILOMETERS_PER_HOUR, SPEED_KILOMETERS_PER_HOUR,
TEMP_CELSIUS, TEMP_CELSIUS,
UNIT_PERCENTAGE, UNIT_PERCENTAGE,
@ -73,7 +74,7 @@ SENSOR_TYPES = {
"rel_hum": ["Relative Humidity", UNIT_PERCENTAGE], "rel_hum": ["Relative Humidity", UNIT_PERCENTAGE],
"sea_state": ["Sea State", None], "sea_state": ["Sea State", None],
"swell_dir_worded": ["Swell Direction", None], "swell_dir_worded": ["Swell Direction", None],
"swell_height": ["Swell Height", "m"], "swell_height": ["Swell Height", LENGTH_METERS],
"swell_period": ["Swell Period", None], "swell_period": ["Swell Period", None],
"vis_km": [f"Visability {LENGTH_KILOMETERS}", LENGTH_KILOMETERS], "vis_km": [f"Visability {LENGTH_KILOMETERS}", LENGTH_KILOMETERS],
"weather": ["Weather", None], "weather": ["Weather", None],

View file

@ -15,6 +15,7 @@ from homeassistant.const import (
CONF_MONITORED_CONDITIONS, CONF_MONITORED_CONDITIONS,
CONF_NAME, CONF_NAME,
CONF_SCAN_INTERVAL, CONF_SCAN_INTERVAL,
LENGTH_CENTIMETERS,
LENGTH_KILOMETERS, LENGTH_KILOMETERS,
SPEED_KILOMETERS_PER_HOUR, SPEED_KILOMETERS_PER_HOUR,
SPEED_METERS_PER_SECOND, SPEED_METERS_PER_SECOND,
@ -128,11 +129,11 @@ SENSOR_TYPES = {
], ],
"precip_accumulation": [ "precip_accumulation": [
"Precip Accumulation", "Precip Accumulation",
"cm", LENGTH_CENTIMETERS,
"in", "in",
"cm", LENGTH_CENTIMETERS,
"cm", LENGTH_CENTIMETERS,
"cm", LENGTH_CENTIMETERS,
"mdi:weather-snowy", "mdi:weather-snowy",
["hourly", "daily"], ["hourly", "daily"],
], ],

View file

@ -1,6 +1,7 @@
"""Constants for the Garmin Connect integration.""" """Constants for the Garmin Connect integration."""
from homeassistant.const import ( from homeassistant.const import (
DEVICE_CLASS_TIMESTAMP, DEVICE_CLASS_TIMESTAMP,
LENGTH_METERS,
MASS_KILOGRAMS, MASS_KILOGRAMS,
TIME_MINUTES, TIME_MINUTES,
UNIT_PERCENTAGE, UNIT_PERCENTAGE,
@ -32,7 +33,13 @@ GARMIN_ENTITY_LIST = {
False, False,
], ],
"netCalorieGoal": ["Net Calorie Goal", "cal", "mdi:food", None, 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": [ "wellnessStartTimeLocal": [
"Wellness Start Time", "Wellness Start Time",
"", "",
@ -48,7 +55,13 @@ GARMIN_ENTITY_LIST = {
False, False,
], ],
"wellnessDescription": ["Wellness Description", "", "mdi:clock", None, 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": [ "wellnessActiveKilocalories": [
"Wellness Active KiloCalories", "Wellness Active KiloCalories",
"kcal", "kcal",
@ -81,8 +94,20 @@ GARMIN_ENTITY_LIST = {
None, None,
True, True,
], ],
"floorsAscendedInMeters": ["Floors Ascended Mtr", "m", "mdi:stairs", None, False], "floorsAscendedInMeters": [
"floorsDescendedInMeters": ["Floors Descended Mtr", "m", "mdi:stairs", None, False], "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], "floorsAscended": ["Floors Ascended", "floors", "mdi:stairs", None, True],
"floorsDescended": ["Floors Descended", "floors", "mdi:stairs", None, True], "floorsDescended": ["Floors Descended", "floors", "mdi:stairs", None, True],
"userFloorsAscendedGoal": [ "userFloorsAscendedGoal": [

View file

@ -5,7 +5,9 @@ from typing import Callable
from homeassistant.components.sensor import DOMAIN from homeassistant.components.sensor import DOMAIN
from homeassistant.const import ( from homeassistant.const import (
CONCENTRATION_PARTS_PER_MILLION, CONCENTRATION_PARTS_PER_MILLION,
LENGTH_CENTIMETERS,
LENGTH_KILOMETERS, LENGTH_KILOMETERS,
LENGTH_METERS,
MASS_KILOGRAMS, MASS_KILOGRAMS,
POWER_WATT, POWER_WATT,
SPEED_KILOMETERS_PER_HOUR, SPEED_KILOMETERS_PER_HOUR,
@ -35,7 +37,7 @@ UOM_FRIENDLY_NAME = {
"1": "amp", "1": "amp",
"3": f"btu/{TIME_HOURS}", "3": f"btu/{TIME_HOURS}",
"4": TEMP_CELSIUS, "4": TEMP_CELSIUS,
"5": "cm", "5": LENGTH_CENTIMETERS,
"6": "ft³", "6": "ft³",
"7": f"ft³/{TIME_MINUTES}", "7": f"ft³/{TIME_MINUTES}",
"8": "", "8": "",
@ -66,7 +68,7 @@ UOM_FRIENDLY_NAME = {
"35": "l", "35": "l",
"36": "lx", "36": "lx",
"37": "mercalli", "37": "mercalli",
"38": "m", "38": LENGTH_METERS,
"39": "m³/hr", "39": "m³/hr",
"40": SPEED_METERS_PER_SECOND, "40": SPEED_METERS_PER_SECOND,
"41": "mA", "41": "mA",

View file

@ -3,6 +3,7 @@ from homeassistant.components import mysensors
from homeassistant.components.sensor import DOMAIN from homeassistant.components.sensor import DOMAIN
from homeassistant.const import ( from homeassistant.const import (
ENERGY_KILO_WATT_HOUR, ENERGY_KILO_WATT_HOUR,
LENGTH_METERS,
MASS_KILOGRAMS, MASS_KILOGRAMS,
POWER_WATT, POWER_WATT,
TEMP_CELSIUS, TEMP_CELSIUS,
@ -26,12 +27,12 @@ SENSORS = {
"V_GUST": [None, "mdi:weather-windy"], "V_GUST": [None, "mdi:weather-windy"],
"V_DIRECTION": [UNIT_DEGREE, "mdi:compass"], "V_DIRECTION": [UNIT_DEGREE, "mdi:compass"],
"V_WEIGHT": [MASS_KILOGRAMS, "mdi:weight-kilogram"], "V_WEIGHT": [MASS_KILOGRAMS, "mdi:weight-kilogram"],
"V_DISTANCE": ["m", "mdi:ruler"], "V_DISTANCE": [LENGTH_METERS, "mdi:ruler"],
"V_IMPEDANCE": ["ohm", None], "V_IMPEDANCE": ["ohm", None],
"V_WATT": [POWER_WATT, None], "V_WATT": [POWER_WATT, None],
"V_KWH": [ENERGY_KILO_WATT_HOUR, None], "V_KWH": [ENERGY_KILO_WATT_HOUR, None],
"V_LIGHT_LEVEL": [UNIT_PERCENTAGE, "mdi:white-balance-sunny"], "V_LIGHT_LEVEL": [UNIT_PERCENTAGE, "mdi:white-balance-sunny"],
"V_FLOW": ["m", "mdi:gauge"], "V_FLOW": [LENGTH_METERS, "mdi:gauge"],
"V_VOLUME": ["", None], "V_VOLUME": ["", None],
"V_LEVEL": { "V_LEVEL": {
"S_SOUND": ["dB", "mdi:volume-high"], "S_SOUND": ["dB", "mdi:volume-high"],

View file

@ -8,6 +8,7 @@ from homeassistant.const import (
CONF_UNIT_OF_MEASUREMENT, CONF_UNIT_OF_MEASUREMENT,
CONF_ZONE, CONF_ZONE,
LENGTH_KILOMETERS, LENGTH_KILOMETERS,
LENGTH_METERS,
) )
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
@ -33,7 +34,7 @@ DEFAULT_PROXIMITY_ZONE = "home"
DEFAULT_TOLERANCE = 1 DEFAULT_TOLERANCE = 1
DOMAIN = "proximity" DOMAIN = "proximity"
UNITS = [LENGTH_KILOMETERS, "m", "mi", "ft"] UNITS = [LENGTH_KILOMETERS, LENGTH_METERS, "mi", "ft"]
ZONE_SCHEMA = vol.Schema( ZONE_SCHEMA = vol.Schema(
{ {
@ -210,7 +211,7 @@ class Proximity(Entity):
# Add the device and distance to a dictionary. # Add the device and distance to a dictionary.
distances_to_zone[device] = round( 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 # Loop through each of the distances collected and work out the

View file

@ -17,6 +17,7 @@ from homeassistant.const import (
CONF_LONGITUDE, CONF_LONGITUDE,
CONF_MONITORED_CONDITIONS, CONF_MONITORED_CONDITIONS,
CONF_NAME, CONF_NAME,
LENGTH_METERS,
SPEED_KILOMETERS_PER_HOUR, SPEED_KILOMETERS_PER_HOUR,
TEMP_CELSIUS, TEMP_CELSIUS,
UNIT_DEGREE, UNIT_DEGREE,
@ -64,7 +65,12 @@ SENSOR_TYPES = {
# The following probably not useful for general consumption, # The following probably not useful for general consumption,
# but we need them to fill in internal attributes # but we need them to fill in internal attributes
"station_name": ("Station Name", None, "Name", str), "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_date": ("Update Date", None, "Datum", str),
"update_time": ("Update Time", None, "Zeit", str), "update_time": ("Update Time", None, "Zeit", str),
} }

View file

@ -56,6 +56,7 @@ from homeassistant.const import (
EVENT_STATE_CHANGED, EVENT_STATE_CHANGED,
EVENT_TIME_CHANGED, EVENT_TIME_CHANGED,
EVENT_TIMER_OUT_OF_SYNC, EVENT_TIMER_OUT_OF_SYNC,
LENGTH_METERS,
MATCH_ALL, MATCH_ALL,
__version__, __version__,
) )
@ -1324,7 +1325,7 @@ class Config:
Async friendly. Async friendly.
""" """
return self.units.length( 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: def path(self, *path: str) -> str:

View file

@ -19,6 +19,7 @@ from homeassistant.const import (
ATTR_LATITUDE, ATTR_LATITUDE,
ATTR_LONGITUDE, ATTR_LONGITUDE,
ATTR_UNIT_OF_MEASUREMENT, ATTR_UNIT_OF_MEASUREMENT,
LENGTH_METERS,
MATCH_ALL, MATCH_ALL,
STATE_UNKNOWN, STATE_UNKNOWN,
) )
@ -638,7 +639,7 @@ def distance(hass, *args):
return hass.config.distance(*locations[0]) return hass.config.distance(*locations[0])
return hass.config.units.length( return hass.config.units.length(
loc_util.distance(*locations[0] + locations[1]), "m" loc_util.distance(*locations[0] + locations[1]), LENGTH_METERS
) )