Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions homeassistant/components/ambient_station/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
EVENT_HOMEASSISTANT_STOP,
SPEED_MILES_PER_HOUR,
TEMP_FAHRENHEIT,
UNIT_DEGREE,
UNIT_PERCENTAGE,
)
from homeassistant.core import callback
Expand Down Expand Up @@ -217,10 +218,10 @@
TYPE_TOTALRAININ: ("Lifetime Rain", "in", TYPE_SENSOR, None),
TYPE_UV: ("uv", "Index", TYPE_SENSOR, None),
TYPE_WEEKLYRAININ: ("Weekly Rain", "in", TYPE_SENSOR, None),
TYPE_WINDDIR: ("Wind Dir", "°", TYPE_SENSOR, None),
TYPE_WINDDIR_AVG10M: ("Wind Dir Avg 10m", "°", TYPE_SENSOR, None),
TYPE_WINDDIR: ("Wind Dir", UNIT_DEGREE, TYPE_SENSOR, None),
TYPE_WINDDIR_AVG10M: ("Wind Dir Avg 10m", UNIT_DEGREE, TYPE_SENSOR, None),
TYPE_WINDDIR_AVG2M: ("Wind Dir Avg 2m", SPEED_MILES_PER_HOUR, TYPE_SENSOR, None),
TYPE_WINDGUSTDIR: ("Gust Dir", "°", TYPE_SENSOR, None),
TYPE_WINDGUSTDIR: ("Gust Dir", UNIT_DEGREE, TYPE_SENSOR, None),
TYPE_WINDGUSTMPH: ("Wind Gust", SPEED_MILES_PER_HOUR, TYPE_SENSOR, None),
TYPE_WINDSPDMPH_AVG10M: ("Wind Avg 10m", SPEED_MILES_PER_HOUR, TYPE_SENSOR, None),
TYPE_WINDSPDMPH_AVG2M: ("Wind Avg 2m", SPEED_MILES_PER_HOUR, TYPE_SENSOR, None),
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/arwn/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging

from homeassistant.components import mqtt
from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT
from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT, UNIT_DEGREE
from homeassistant.core import callback
from homeassistant.helpers.entity import Entity
from homeassistant.util import slugify
Expand Down Expand Up @@ -45,7 +45,7 @@ def discover_sensors(topic, payload):
return (
ArwnSensor("Wind Speed", "speed", unit, "mdi:speedometer"),
ArwnSensor("Wind Gust", "gust", unit, "mdi:speedometer"),
ArwnSensor("Wind Direction", "direction", "°", "mdi:compass"),
ArwnSensor("Wind Direction", "direction", UNIT_DEGREE, "mdi:compass"),
)


Expand Down
13 changes: 7 additions & 6 deletions homeassistant/components/buienradar/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
SPEED_KILOMETERS_PER_HOUR,
TEMP_CELSIUS,
TIME_HOURS,
UNIT_DEGREE,
UNIT_PERCENTAGE,
)
from homeassistant.core import callback
Expand Down Expand Up @@ -76,7 +77,7 @@
"windspeed": ["Wind speed", SPEED_KILOMETERS_PER_HOUR, "mdi:weather-windy"],
"windforce": ["Wind force", "Bft", "mdi:weather-windy"],
"winddirection": ["Wind direction", None, "mdi:compass-outline"],
"windazimuth": ["Wind direction azimuth", "°", "mdi:compass-outline"],
"windazimuth": ["Wind direction azimuth", UNIT_DEGREE, "mdi:compass-outline"],
"pressure": ["Pressure", "hPa", "mdi:gauge"],
"visibility": ["Visibility", LENGTH_KILOMETERS, None],
"windgust": ["Wind gust", SPEED_KILOMETERS_PER_HOUR, "mdi:weather-windy"],
Expand Down Expand Up @@ -148,11 +149,11 @@
"winddirection_3d": ["Wind direction 3d", None, "mdi:compass-outline"],
"winddirection_4d": ["Wind direction 4d", None, "mdi:compass-outline"],
"winddirection_5d": ["Wind direction 5d", None, "mdi:compass-outline"],
"windazimuth_1d": ["Wind direction azimuth 1d", "°", "mdi:compass-outline"],
"windazimuth_2d": ["Wind direction azimuth 2d", "°", "mdi:compass-outline"],
"windazimuth_3d": ["Wind direction azimuth 3d", "°", "mdi:compass-outline"],
"windazimuth_4d": ["Wind direction azimuth 4d", "°", "mdi:compass-outline"],
"windazimuth_5d": ["Wind direction azimuth 5d", "°", "mdi:compass-outline"],
"windazimuth_1d": ["Wind direction azimuth 1d", UNIT_DEGREE, "mdi:compass-outline"],
"windazimuth_2d": ["Wind direction azimuth 2d", UNIT_DEGREE, "mdi:compass-outline"],
"windazimuth_3d": ["Wind direction azimuth 3d", UNIT_DEGREE, "mdi:compass-outline"],
"windazimuth_4d": ["Wind direction azimuth 4d", UNIT_DEGREE, "mdi:compass-outline"],
"windazimuth_5d": ["Wind direction azimuth 5d", UNIT_DEGREE, "mdi:compass-outline"],
"condition_1d": ["Condition 1d", None, None],
"condition_2d": ["Condition 2d", None, None],
"condition_3d": ["Condition 3d", None, None],
Expand Down
21 changes: 11 additions & 10 deletions homeassistant/components/darksky/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
TIME_HOURS,
UNIT_DEGREE,
UNIT_PERCENTAGE,
UNIT_UV_INDEX,
)
Expand Down Expand Up @@ -87,11 +88,11 @@
],
"nearest_storm_bearing": [
"Nearest Storm Bearing",
"°",
"°",
"°",
"°",
"°",
UNIT_DEGREE,
UNIT_DEGREE,
UNIT_DEGREE,
UNIT_DEGREE,
UNIT_DEGREE,
"mdi:weather-lightning",
["currently"],
],
Expand Down Expand Up @@ -177,11 +178,11 @@
],
"wind_bearing": [
"Wind Bearing",
"°",
"°",
"°",
"°",
"°",
UNIT_DEGREE,
UNIT_DEGREE,
UNIT_DEGREE,
UNIT_DEGREE,
UNIT_DEGREE,
"mdi:compass",
["currently", "hourly", "daily"],
],
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/homematic/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
POWER_WATT,
SPEED_KILOMETERS_PER_HOUR,
TEMP_CELSIUS,
UNIT_DEGREE,
UNIT_PERCENTAGE,
UNIT_VOLT,
VOLUME_CUBIC_METERS,
Expand Down Expand Up @@ -53,8 +54,8 @@
"HIGHEST_ILLUMINATION": "lx",
"RAIN_COUNTER": "mm",
"WIND_SPEED": SPEED_KILOMETERS_PER_HOUR,
"WIND_DIRECTION": "°",
"WIND_DIRECTION_RANGE": "°",
"WIND_DIRECTION": UNIT_DEGREE,
"WIND_DIRECTION_RANGE": UNIT_DEGREE,
"SUNSHINEDURATION": "#",
"AIR_PRESSURE": "hPa",
"FREQUENCY": "Hz",
Expand Down
9 changes: 5 additions & 4 deletions homeassistant/components/isy994/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
TIME_MONTHS,
TIME_SECONDS,
TIME_YEARS,
UNIT_DEGREE,
UNIT_PERCENTAGE,
UNIT_UV_INDEX,
UNIT_VOLT,
Expand All @@ -41,7 +42,7 @@
"10": TIME_DAYS,
"12": "dB",
"13": "dB A",
"14": "°",
"14": UNIT_DEGREE,
"16": "macroseismic",
"17": TEMP_FAHRENHEIT,
"18": "ft",
Expand Down Expand Up @@ -97,7 +98,7 @@
"73": POWER_WATT,
"74": "W/m²",
"75": "weekday",
"76": "Wind Direction (°)",
"76": f"Wind Direction ({UNIT_DEGREE})",
"77": TIME_YEARS,
"82": "mm",
"83": LENGTH_KILOMETERS,
Expand All @@ -107,8 +108,8 @@
"88": "Water activity",
"89": "RPM",
"90": "Hz",
"91": (Relative to North)",
"92": (Relative to South)",
"91": f"{UNIT_DEGREE} (Relative to North)",
"92": f"{UNIT_DEGREE} (Relative to South)",
}

UOM_TO_STATES = {
Expand Down
6 changes: 4 additions & 2 deletions homeassistant/components/lcn/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from homeassistant.const import (
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
TEMP_KELVIN,
UNIT_DEGREE,
UNIT_PERCENTAGE,
UNIT_VOLT,
)
Expand Down Expand Up @@ -149,7 +151,7 @@
"LCN",
"NATIVE",
TEMP_CELSIUS,
"°K",
TEMP_KELVIN,
TEMP_FAHRENHEIT,
"LUX_T",
"LX_T",
Expand All @@ -167,7 +169,7 @@
"AMP",
"A",
"DEGREE",
"°",
UNIT_DEGREE,
]

RELVARREF = ["CURRENT", "PROG"]
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/mysensors/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
POWER_WATT,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
UNIT_DEGREE,
UNIT_PERCENTAGE,
UNIT_VOLT,
)
Expand All @@ -22,7 +23,7 @@
"V_RAINRATE": [None, "mdi:weather-rainy"],
"V_WIND": [None, "mdi:weather-windy"],
"V_GUST": [None, "mdi:weather-windy"],
"V_DIRECTION": ["°", "mdi:compass"],
"V_DIRECTION": [UNIT_DEGREE, "mdi:compass"],
"V_WEIGHT": [MASS_KILOGRAMS, "mdi:weight-kilogram"],
"V_DISTANCE": ["m", "mdi:ruler"],
"V_IMPEDANCE": ["ohm", None],
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/openweathermap/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
SPEED_METERS_PER_SECOND,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
UNIT_DEGREE,
UNIT_PERCENTAGE,
)
import homeassistant.helpers.config_validation as cv
Expand All @@ -36,7 +37,7 @@
"weather": ["Condition", None],
"temperature": ["Temperature", None],
"wind_speed": ["Wind speed", SPEED_METERS_PER_SECOND],
"wind_bearing": ["Wind bearing", "°"],
"wind_bearing": ["Wind bearing", UNIT_DEGREE],
"humidity": ["Humidity", UNIT_PERCENTAGE],
"pressure": ["Pressure", "mbar"],
"clouds": ["Cloud coverage", UNIT_PERCENTAGE],
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/smappee/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from homeassistant.const import (
ENERGY_KILO_WATT_HOUR,
POWER_WATT,
UNIT_DEGREE,
UNIT_PERCENTAGE,
UNIT_VOLT,
VOLUME_CUBIC_METERS,
Expand Down Expand Up @@ -73,7 +74,7 @@
"Water Sensor Temperature",
"mdi:temperature-celsius",
"water",
"°",
UNIT_DEGREE,
"temperature",
],
"water_sensor_humidity": [
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/torque/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from homeassistant.components.http import HomeAssistantView
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import CONF_EMAIL, CONF_NAME
from homeassistant.const import CONF_EMAIL, CONF_NAME, UNIT_DEGREE
from homeassistant.core import callback
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
Expand Down Expand Up @@ -91,7 +91,7 @@ def get(self, request):

temp_unit = data[key]
if "\\xC2\\xB0" in temp_unit:
temp_unit = temp_unit.replace("\\xC2\\xB0", "°")
temp_unit = temp_unit.replace("\\xC2\\xB0", UNIT_DEGREE)

units[pid] = temp_unit
elif is_value:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
DEVICE_CLASS_TEMPERATURE,
SPEED_METERS_PER_SECOND,
TEMP_CELSIUS,
UNIT_DEGREE,
UNIT_PERCENTAGE,
)
from homeassistant.helpers.aiohttp_client import async_get_clientsession
Expand Down Expand Up @@ -61,7 +62,7 @@
],
"wind_direction": [
"Wind direction",
"°",
UNIT_DEGREE,
"winddirection",
"mdi:flag-triangle",
None,
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/wink/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pywink

from homeassistant.const import TEMP_CELSIUS
from homeassistant.const import TEMP_CELSIUS, UNIT_DEGREE

from . import DOMAIN, WinkDevice

Expand Down Expand Up @@ -48,7 +48,7 @@ def __init__(self, wink, hass):
"""Initialize the Wink device."""
super().__init__(wink, hass)
self.capability = self.wink.capability()
if self.wink.unit() == "°":
if self.wink.unit() == UNIT_DEGREE:
self._unit_of_measurement = TEMP_CELSIUS
else:
self._unit_of_measurement = self.wink.unit()
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/wunderground/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
SPEED_MILES_PER_HOUR,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
UNIT_DEGREE,
UNIT_PERCENTAGE,
)
from homeassistant.exceptions import PlatformNotReady
Expand Down Expand Up @@ -456,7 +457,7 @@ def _get_attributes(rest):
),
"weather": WUCurrentConditionsSensorConfig("Weather Summary", "weather", None),
"wind_degrees": WUCurrentConditionsSensorConfig(
"Wind Degrees", "wind_degrees", "mdi:weather-windy", "°"
"Wind Degrees", "wind_degrees", "mdi:weather-windy", UNIT_DEGREE
),
"wind_dir": WUCurrentConditionsSensorConfig(
"Wind Direction", "wind_dir", "mdi:weather-windy"
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/yr/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
PRESSURE_HPA,
SPEED_METERS_PER_SECOND,
TEMP_CELSIUS,
UNIT_DEGREE,
UNIT_PERCENTAGE,
)
from homeassistant.helpers.aiohttp_client import async_get_clientsession
Expand All @@ -47,7 +48,7 @@
"windSpeed": ["Wind speed", SPEED_METERS_PER_SECOND, None],
"windGust": ["Wind gust", SPEED_METERS_PER_SECOND, None],
"pressure": ["Pressure", PRESSURE_HPA, DEVICE_CLASS_PRESSURE],
"windDirection": ["Wind direction", "°", None],
"windDirection": ["Wind direction", UNIT_DEGREE, None],
"humidity": ["Humidity", UNIT_PERCENTAGE, DEVICE_CLASS_HUMIDITY],
"fog": ["Fog", UNIT_PERCENTAGE, None],
"cloudiness": ["Cloudiness", UNIT_PERCENTAGE, None],
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/zamg/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
CONF_NAME,
SPEED_KILOMETERS_PER_HOUR,
TEMP_CELSIUS,
UNIT_DEGREE,
UNIT_PERCENTAGE,
__version__,
)
Expand Down Expand Up @@ -48,14 +49,14 @@
f"WG {SPEED_KILOMETERS_PER_HOUR}",
float,
),
"wind_bearing": ("Wind Bearing", "°", "WR °", int),
"wind_bearing": ("Wind Bearing", UNIT_DEGREE, f"WR {UNIT_DEGREE}", int),
"wind_max_speed": (
"Top Wind Speed",
SPEED_KILOMETERS_PER_HOUR,
f"WSG {SPEED_KILOMETERS_PER_HOUR}",
float,
),
"wind_max_bearing": ("Top Wind Bearing", "°", "WSR °", int),
"wind_max_bearing": ("Top Wind Bearing", UNIT_DEGREE, f"WSR {UNIT_DEGREE}", int),
"sun_last_hour": ("Sun Last Hour", UNIT_PERCENTAGE, f"SO {UNIT_PERCENTAGE}", int),
"temperature": ("Temperature", TEMP_CELSIUS, f"T {TEMP_CELSIUS}", float),
"precipitation": ("Precipitation", "l/m²", "N l/m²", float),
Expand Down
9 changes: 7 additions & 2 deletions homeassistant/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,13 @@
ENERGY_KILO_WATT_HOUR = "kWh"
ENERGY_WATT_HOUR = "Wh"

# Degree units
UNIT_DEGREE = "°"

# Temperature units
TEMP_CELSIUS = "°C"
TEMP_FAHRENHEIT = "°F"
TEMP_CELSIUS = f"{UNIT_DEGREE}C"
TEMP_FAHRENHEIT = f"{UNIT_DEGREE}F"
TEMP_KELVIN = f"{UNIT_DEGREE}K"

# Time units
TIME_MICROSECONDS = "μs"
Expand Down Expand Up @@ -410,6 +414,7 @@

# Percentage units
UNIT_PERCENTAGE = "%"

# Irradiation units
IRRADIATION_WATTS_PER_SQUARE_METER = f"{POWER_WATT}/{AREA_SQUARE_METERS}"

Expand Down
Loading