From ef9d9b17bde1dcec44448f263a0a66498ad558ae Mon Sep 17 00:00:00 2001 From: springstan <46536646+springstan@users.noreply.github.com> Date: Tue, 21 Apr 2020 19:45:53 +0200 Subject: [PATCH] Drop UNIT_ prefix for constants (#34164) * Drop UNIT_ prefix for VOLT * Drop UNIT_ prefix for DEGREE * Drop UNIT_ prefix for CONDUCTIVITY * Drop UNIT_ prefix for UV_INDEX * Run isort --- .../components/ambient_station/__init__.py | 8 ++--- homeassistant/components/apcupsd/sensor.py | 24 ++++++------- homeassistant/components/arwn/sensor.py | 4 +-- homeassistant/components/buienradar/sensor.py | 14 ++++---- homeassistant/components/darksky/sensor.py | 34 +++++++++---------- .../components/dsmr_reader/definitions.py | 8 ++--- homeassistant/components/elkm1/sensor.py | 4 +-- homeassistant/components/envirophat/sensor.py | 10 +++--- .../components/greeneye_monitor/sensor.py | 4 +-- .../components/growatt_server/sensor.py | 10 +++--- homeassistant/components/homematic/sensor.py | 10 +++--- homeassistant/components/isy994/sensor.py | 18 +++++----- homeassistant/components/juicenet/sensor.py | 4 +-- homeassistant/components/lcn/const.py | 8 ++--- homeassistant/components/metoffice/sensor.py | 4 +-- homeassistant/components/miflora/sensor.py | 4 +-- homeassistant/components/mysensors/sensor.py | 12 +++---- homeassistant/components/nut/const.py | 27 ++++++--------- homeassistant/components/onewire/sensor.py | 8 ++--- homeassistant/components/openuv/sensor.py | 6 ++-- .../components/openweathermap/sensor.py | 4 +-- homeassistant/components/plant/__init__.py | 4 +-- homeassistant/components/rfxtrx/__init__.py | 4 +-- homeassistant/components/smappee/sensor.py | 8 ++--- .../components/smartthings/sensor.py | 4 +-- .../components/solaredge_local/sensor.py | 20 +++-------- homeassistant/components/solarlog/const.py | 11 ++---- homeassistant/components/starline/sensor.py | 4 +-- homeassistant/components/ted5000/sensor.py | 8 ++--- .../components/tellduslive/sensor.py | 4 +-- homeassistant/components/torque/sensor.py | 4 +-- .../trafikverket_weatherstation/sensor.py | 4 +-- homeassistant/components/wink/sensor.py | 4 +-- .../components/wirelesstag/__init__.py | 4 +-- .../components/wunderground/sensor.py | 4 +-- homeassistant/components/yr/sensor.py | 4 +-- homeassistant/components/zamg/sensor.py | 6 ++-- homeassistant/const.py | 14 ++++---- tests/components/plant/test_init.py | 16 ++++----- tests/components/prometheus/test_init.py | 4 +-- tests/components/sma/test_sensor.py | 4 +-- tests/components/yr/test_sensor.py | 6 ++-- 42 files changed, 170 insertions(+), 196 deletions(-) diff --git a/homeassistant/components/ambient_station/__init__.py b/homeassistant/components/ambient_station/__init__.py index 6bdb6d0d4f6..8ee37f4503e 100644 --- a/homeassistant/components/ambient_station/__init__.py +++ b/homeassistant/components/ambient_station/__init__.py @@ -12,11 +12,11 @@ from homeassistant.const import ( ATTR_NAME, CONCENTRATION_PARTS_PER_MILLION, CONF_API_KEY, + DEGREE, EVENT_HOMEASSISTANT_STOP, POWER_WATT, SPEED_MILES_PER_HOUR, TEMP_FAHRENHEIT, - UNIT_DEGREE, UNIT_PERCENTAGE, ) from homeassistant.core import callback @@ -219,10 +219,10 @@ SENSOR_TYPES = { 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", UNIT_DEGREE, TYPE_SENSOR, None), - TYPE_WINDDIR_AVG10M: ("Wind Dir Avg 10m", UNIT_DEGREE, TYPE_SENSOR, None), + TYPE_WINDDIR: ("Wind Dir", DEGREE, TYPE_SENSOR, None), + TYPE_WINDDIR_AVG10M: ("Wind Dir Avg 10m", DEGREE, TYPE_SENSOR, None), TYPE_WINDDIR_AVG2M: ("Wind Dir Avg 2m", SPEED_MILES_PER_HOUR, TYPE_SENSOR, None), - TYPE_WINDGUSTDIR: ("Gust Dir", UNIT_DEGREE, TYPE_SENSOR, None), + TYPE_WINDGUSTDIR: ("Gust Dir", 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), diff --git a/homeassistant/components/apcupsd/sensor.py b/homeassistant/components/apcupsd/sensor.py index 1e73f040555..44c1c498c28 100644 --- a/homeassistant/components/apcupsd/sensor.py +++ b/homeassistant/components/apcupsd/sensor.py @@ -13,7 +13,7 @@ from homeassistant.const import ( TIME_MINUTES, TIME_SECONDS, UNIT_PERCENTAGE, - UNIT_VOLT, + VOLT, ) import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity @@ -31,7 +31,7 @@ SENSOR_TYPES = { "badbatts": ["Bad Batteries", "", "mdi:information-outline"], "battdate": ["Battery Replaced", "", "mdi:calendar-clock"], "battstat": ["Battery Status", "", "mdi:information-outline"], - "battv": ["Battery Voltage", UNIT_VOLT, "mdi:flash"], + "battv": ["Battery Voltage", VOLT, "mdi:flash"], "bcharge": ["Battery", UNIT_PERCENTAGE, "mdi:battery"], "cable": ["Cable Type", "", "mdi:ethernet-cable"], "cumonbatt": ["Total Time on Battery", "", "mdi:timer"], @@ -44,33 +44,33 @@ SENSOR_TYPES = { "endapc": ["Date and Time", "", "mdi:calendar-clock"], "extbatts": ["External Batteries", "", "mdi:information-outline"], "firmware": ["Firmware Version", "", "mdi:information-outline"], - "hitrans": ["Transfer High", UNIT_VOLT, "mdi:flash"], + "hitrans": ["Transfer High", VOLT, "mdi:flash"], "hostname": ["Hostname", "", "mdi:information-outline"], "humidity": ["Ambient Humidity", UNIT_PERCENTAGE, "mdi:water-percent"], "itemp": ["Internal Temperature", TEMP_CELSIUS, "mdi:thermometer"], "lastxfer": ["Last Transfer", "", "mdi:transfer"], "linefail": ["Input Voltage Status", "", "mdi:information-outline"], "linefreq": ["Line Frequency", FREQUENCY_HERTZ, "mdi:information-outline"], - "linev": ["Input Voltage", UNIT_VOLT, "mdi:flash"], + "linev": ["Input Voltage", VOLT, "mdi:flash"], "loadpct": ["Load", UNIT_PERCENTAGE, "mdi:gauge"], "loadapnt": ["Load Apparent Power", UNIT_PERCENTAGE, "mdi:gauge"], - "lotrans": ["Transfer Low", UNIT_VOLT, "mdi:flash"], + "lotrans": ["Transfer Low", VOLT, "mdi:flash"], "mandate": ["Manufacture Date", "", "mdi:calendar"], "masterupd": ["Master Update", "", "mdi:information-outline"], - "maxlinev": ["Input Voltage High", UNIT_VOLT, "mdi:flash"], + "maxlinev": ["Input Voltage High", VOLT, "mdi:flash"], "maxtime": ["Battery Timeout", "", "mdi:timer-off"], "mbattchg": ["Battery Shutdown", UNIT_PERCENTAGE, "mdi:battery-alert"], - "minlinev": ["Input Voltage Low", UNIT_VOLT, "mdi:flash"], + "minlinev": ["Input Voltage Low", VOLT, "mdi:flash"], "mintimel": ["Shutdown Time", "", "mdi:timer"], "model": ["Model", "", "mdi:information-outline"], - "nombattv": ["Battery Nominal Voltage", UNIT_VOLT, "mdi:flash"], - "nominv": ["Nominal Input Voltage", UNIT_VOLT, "mdi:flash"], - "nomoutv": ["Nominal Output Voltage", UNIT_VOLT, "mdi:flash"], + "nombattv": ["Battery Nominal Voltage", VOLT, "mdi:flash"], + "nominv": ["Nominal Input Voltage", VOLT, "mdi:flash"], + "nomoutv": ["Nominal Output Voltage", VOLT, "mdi:flash"], "nompower": ["Nominal Output Power", POWER_WATT, "mdi:flash"], "nomapnt": ["Nominal Apparent Power", "VA", "mdi:flash"], "numxfers": ["Transfer Count", "", "mdi:counter"], "outcurnt": ["Output Current", "A", "mdi:flash"], - "outputv": ["Output Voltage", UNIT_VOLT, "mdi:flash"], + "outputv": ["Output Voltage", VOLT, "mdi:flash"], "reg1": ["Register 1 Fault", "", "mdi:information-outline"], "reg2": ["Register 2 Fault", "", "mdi:information-outline"], "reg3": ["Register 3 Fault", "", "mdi:information-outline"], @@ -97,7 +97,7 @@ INFERRED_UNITS = { " Minutes": TIME_MINUTES, " Seconds": TIME_SECONDS, " Percent": UNIT_PERCENTAGE, - " Volts": UNIT_VOLT, + " Volts": VOLT, " Ampere": "A", " Volt-Ampere": "VA", " Watts": POWER_WATT, diff --git a/homeassistant/components/arwn/sensor.py b/homeassistant/components/arwn/sensor.py index 334c086f8d6..5da860d8a50 100644 --- a/homeassistant/components/arwn/sensor.py +++ b/homeassistant/components/arwn/sensor.py @@ -3,7 +3,7 @@ import json import logging from homeassistant.components import mqtt -from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT, UNIT_DEGREE +from homeassistant.const import DEGREE, TEMP_CELSIUS, TEMP_FAHRENHEIT from homeassistant.core import callback from homeassistant.helpers.entity import Entity from homeassistant.util import slugify @@ -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", UNIT_DEGREE, "mdi:compass"), + ArwnSensor("Wind Direction", "direction", DEGREE, "mdi:compass"), ) diff --git a/homeassistant/components/buienradar/sensor.py b/homeassistant/components/buienradar/sensor.py index 7c5e21191a3..92811b98a80 100644 --- a/homeassistant/components/buienradar/sensor.py +++ b/homeassistant/components/buienradar/sensor.py @@ -27,12 +27,12 @@ from homeassistant.const import ( CONF_LONGITUDE, CONF_MONITORED_CONDITIONS, CONF_NAME, + DEGREE, IRRADIATION_WATTS_PER_SQUARE_METER, LENGTH_KILOMETERS, SPEED_KILOMETERS_PER_HOUR, TEMP_CELSIUS, TIME_HOURS, - UNIT_DEGREE, UNIT_PERCENTAGE, ) from homeassistant.core import callback @@ -77,7 +77,7 @@ SENSOR_TYPES = { "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", UNIT_DEGREE, "mdi:compass-outline"], + "windazimuth": ["Wind direction azimuth", DEGREE, "mdi:compass-outline"], "pressure": ["Pressure", "hPa", "mdi:gauge"], "visibility": ["Visibility", LENGTH_KILOMETERS, None], "windgust": ["Wind gust", SPEED_KILOMETERS_PER_HOUR, "mdi:weather-windy"], @@ -149,11 +149,11 @@ SENSOR_TYPES = { "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", 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"], + "windazimuth_1d": ["Wind direction azimuth 1d", DEGREE, "mdi:compass-outline"], + "windazimuth_2d": ["Wind direction azimuth 2d", DEGREE, "mdi:compass-outline"], + "windazimuth_3d": ["Wind direction azimuth 3d", DEGREE, "mdi:compass-outline"], + "windazimuth_4d": ["Wind direction azimuth 4d", DEGREE, "mdi:compass-outline"], + "windazimuth_5d": ["Wind direction azimuth 5d", DEGREE, "mdi:compass-outline"], "condition_1d": ["Condition 1d", None, None], "condition_2d": ["Condition 2d", None, None], "condition_3d": ["Condition 3d", None, None], diff --git a/homeassistant/components/darksky/sensor.py b/homeassistant/components/darksky/sensor.py index ab639b2e6a2..e3742231e1e 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, + DEGREE, LENGTH_CENTIMETERS, LENGTH_KILOMETERS, SPEED_KILOMETERS_PER_HOUR, @@ -23,9 +24,8 @@ from homeassistant.const import ( TEMP_CELSIUS, TEMP_FAHRENHEIT, TIME_HOURS, - UNIT_DEGREE, UNIT_PERCENTAGE, - UNIT_UV_INDEX, + UV_INDEX, ) import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity @@ -89,11 +89,11 @@ SENSOR_TYPES = { ], "nearest_storm_bearing": [ "Nearest Storm Bearing", - UNIT_DEGREE, - UNIT_DEGREE, - UNIT_DEGREE, - UNIT_DEGREE, - UNIT_DEGREE, + DEGREE, + DEGREE, + DEGREE, + DEGREE, + DEGREE, "mdi:weather-lightning", ["currently"], ], @@ -179,11 +179,11 @@ SENSOR_TYPES = { ], "wind_bearing": [ "Wind Bearing", - UNIT_DEGREE, - UNIT_DEGREE, - UNIT_DEGREE, - UNIT_DEGREE, - UNIT_DEGREE, + DEGREE, + DEGREE, + DEGREE, + DEGREE, + DEGREE, "mdi:compass", ["currently", "hourly", "daily"], ], @@ -339,11 +339,11 @@ SENSOR_TYPES = { ], "uv_index": [ "UV Index", - UNIT_UV_INDEX, - UNIT_UV_INDEX, - UNIT_UV_INDEX, - UNIT_UV_INDEX, - UNIT_UV_INDEX, + UV_INDEX, + UV_INDEX, + UV_INDEX, + UV_INDEX, + UV_INDEX, "mdi:weather-sunny", ["currently", "hourly", "daily"], ], diff --git a/homeassistant/components/dsmr_reader/definitions.py b/homeassistant/components/dsmr_reader/definitions.py index 87e6d6ff872..b6740655434 100644 --- a/homeassistant/components/dsmr_reader/definitions.py +++ b/homeassistant/components/dsmr_reader/definitions.py @@ -1,6 +1,6 @@ """Definitions for DSMR Reader sensors added to MQTT.""" -from homeassistant.const import ENERGY_KILO_WATT_HOUR, UNIT_VOLT, VOLUME_CUBIC_METERS +from homeassistant.const import ENERGY_KILO_WATT_HOUR, VOLT, VOLUME_CUBIC_METERS def dsmr_transform(value): @@ -86,17 +86,17 @@ DEFINITIONS = { "dsmr/reading/phase_voltage_l1": { "name": "Current voltage L1", "icon": "mdi:flash", - "unit": UNIT_VOLT, + "unit": VOLT, }, "dsmr/reading/phase_voltage_l2": { "name": "Current voltage L2", "icon": "mdi:flash", - "unit": UNIT_VOLT, + "unit": VOLT, }, "dsmr/reading/phase_voltage_l3": { "name": "Current voltage L3", "icon": "mdi:flash", - "unit": UNIT_VOLT, + "unit": VOLT, }, "dsmr/consumption/gas/delivered": { "name": "Gas usage", diff --git a/homeassistant/components/elkm1/sensor.py b/homeassistant/components/elkm1/sensor.py index 0c7a454990d..20efb3e956d 100644 --- a/homeassistant/components/elkm1/sensor.py +++ b/homeassistant/components/elkm1/sensor.py @@ -7,7 +7,7 @@ from elkm1_lib.const import ( ) from elkm1_lib.util import pretty_const, username -from homeassistant.const import UNIT_VOLT +from homeassistant.const import VOLT from . import ElkAttachedEntity, create_elk_entities from .const import DOMAIN @@ -197,7 +197,7 @@ class ElkZone(ElkSensor): if self._element.definition == ZoneType.TEMPERATURE.value: return self._temperature_unit if self._element.definition == ZoneType.ANALOG_ZONE.value: - return UNIT_VOLT + return VOLT return None def _element_changed(self, element, changeset): diff --git a/homeassistant/components/envirophat/sensor.py b/homeassistant/components/envirophat/sensor.py index 81420cf389f..1aa07c83027 100644 --- a/homeassistant/components/envirophat/sensor.py +++ b/homeassistant/components/envirophat/sensor.py @@ -6,7 +6,7 @@ import logging import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA -from homeassistant.const import CONF_DISPLAY_OPTIONS, CONF_NAME, TEMP_CELSIUS, UNIT_VOLT +from homeassistant.const import CONF_DISPLAY_OPTIONS, CONF_NAME, TEMP_CELSIUS, VOLT import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity from homeassistant.util import Throttle @@ -31,10 +31,10 @@ SENSOR_TYPES = { "magnetometer_z": ["magnetometer_z", " ", "mdi:magnet"], "temperature": ["temperature", TEMP_CELSIUS, "mdi:thermometer"], "pressure": ["pressure", "hPa", "mdi:gauge"], - "voltage_0": ["voltage_0", UNIT_VOLT, "mdi:flash"], - "voltage_1": ["voltage_1", UNIT_VOLT, "mdi:flash"], - "voltage_2": ["voltage_2", UNIT_VOLT, "mdi:flash"], - "voltage_3": ["voltage_3", UNIT_VOLT, "mdi:flash"], + "voltage_0": ["voltage_0", VOLT, "mdi:flash"], + "voltage_1": ["voltage_1", VOLT, "mdi:flash"], + "voltage_2": ["voltage_2", VOLT, "mdi:flash"], + "voltage_3": ["voltage_3", VOLT, "mdi:flash"], } PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( diff --git a/homeassistant/components/greeneye_monitor/sensor.py b/homeassistant/components/greeneye_monitor/sensor.py index 18d564765d1..06a60ab3fd7 100644 --- a/homeassistant/components/greeneye_monitor/sensor.py +++ b/homeassistant/components/greeneye_monitor/sensor.py @@ -8,7 +8,7 @@ from homeassistant.const import ( TIME_HOURS, TIME_MINUTES, TIME_SECONDS, - UNIT_VOLT, + VOLT, ) from homeassistant.helpers.entity import Entity @@ -311,4 +311,4 @@ class VoltageSensor(GEMSensor): @property def unit_of_measurement(self): """Return the unit of measurement for this sensor.""" - return UNIT_VOLT + return VOLT diff --git a/homeassistant/components/growatt_server/sensor.py b/homeassistant/components/growatt_server/sensor.py index d2b92e8efb3..6bfdf7f2552 100644 --- a/homeassistant/components/growatt_server/sensor.py +++ b/homeassistant/components/growatt_server/sensor.py @@ -15,7 +15,7 @@ from homeassistant.const import ( ENERGY_KILO_WATT_HOUR, FREQUENCY_HERTZ, POWER_WATT, - UNIT_VOLT, + VOLT, ) import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity @@ -60,17 +60,17 @@ INVERTER_SENSOR_TYPES = { "e_total", "power", ), - "inverter_voltage_input_1": ("Input 1 voltage", UNIT_VOLT, "vpv1", None), + "inverter_voltage_input_1": ("Input 1 voltage", VOLT, "vpv1", None), "inverter_amperage_input_1": ("Input 1 Amperage", "A", "ipv1", None), "inverter_wattage_input_1": ("Input 1 Wattage", POWER_WATT, "ppv1", "power"), - "inverter_voltage_input_2": ("Input 2 voltage", UNIT_VOLT, "vpv2", None), + "inverter_voltage_input_2": ("Input 2 voltage", VOLT, "vpv2", None), "inverter_amperage_input_2": ("Input 2 Amperage", "A", "ipv2", None), "inverter_wattage_input_2": ("Input 2 Wattage", POWER_WATT, "ppv2", "power"), - "inverter_voltage_input_3": ("Input 3 voltage", UNIT_VOLT, "vpv3", None), + "inverter_voltage_input_3": ("Input 3 voltage", VOLT, "vpv3", None), "inverter_amperage_input_3": ("Input 3 Amperage", "A", "ipv3", None), "inverter_wattage_input_3": ("Input 3 Wattage", POWER_WATT, "ppv3", "power"), "inverter_internal_wattage": ("Internal wattage", POWER_WATT, "ppv", "power"), - "inverter_reactive_voltage": ("Reactive voltage", UNIT_VOLT, "vacr", None), + "inverter_reactive_voltage": ("Reactive voltage", VOLT, "vacr", None), "inverter_inverter_reactive_amperage": ("Reactive amperage", "A", "iacr", None), "inverter_frequency": ("AC frequency", FREQUENCY_HERTZ, "fac", None), "inverter_current_wattage": ("Output power", POWER_WATT, "pac", "power"), diff --git a/homeassistant/components/homematic/sensor.py b/homeassistant/components/homematic/sensor.py index d52a4a2a19f..7c4486065b4 100644 --- a/homeassistant/components/homematic/sensor.py +++ b/homeassistant/components/homematic/sensor.py @@ -2,6 +2,7 @@ import logging from homeassistant.const import ( + DEGREE, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_ILLUMINANCE, DEVICE_CLASS_POWER, @@ -11,9 +12,8 @@ from homeassistant.const import ( POWER_WATT, SPEED_KILOMETERS_PER_HOUR, TEMP_CELSIUS, - UNIT_DEGREE, UNIT_PERCENTAGE, - UNIT_VOLT, + VOLT, VOLUME_CUBIC_METERS, ) @@ -43,7 +43,7 @@ HM_UNIT_HA_CAST = { "BRIGHTNESS": "#", "POWER": POWER_WATT, "CURRENT": "mA", - "VOLTAGE": UNIT_VOLT, + "VOLTAGE": VOLT, "ENERGY_COUNTER": ENERGY_WATT_HOUR, "GAS_POWER": VOLUME_CUBIC_METERS, "GAS_ENERGY_COUNTER": VOLUME_CUBIC_METERS, @@ -55,8 +55,8 @@ HM_UNIT_HA_CAST = { "HIGHEST_ILLUMINATION": "lx", "RAIN_COUNTER": "mm", "WIND_SPEED": SPEED_KILOMETERS_PER_HOUR, - "WIND_DIRECTION": UNIT_DEGREE, - "WIND_DIRECTION_RANGE": UNIT_DEGREE, + "WIND_DIRECTION": DEGREE, + "WIND_DIRECTION_RANGE": DEGREE, "SUNSHINEDURATION": "#", "AIR_PRESSURE": "hPa", "FREQUENCY": FREQUENCY_HERTZ, diff --git a/homeassistant/components/isy994/sensor.py b/homeassistant/components/isy994/sensor.py index 2e694e5d234..1252d0ef53b 100644 --- a/homeassistant/components/isy994/sensor.py +++ b/homeassistant/components/isy994/sensor.py @@ -5,6 +5,7 @@ from typing import Callable from homeassistant.components.sensor import DOMAIN from homeassistant.const import ( CONCENTRATION_PARTS_PER_MILLION, + DEGREE, FREQUENCY_HERTZ, LENGTH_CENTIMETERS, LENGTH_KILOMETERS, @@ -23,10 +24,9 @@ from homeassistant.const import ( TIME_MONTHS, TIME_SECONDS, TIME_YEARS, - UNIT_DEGREE, UNIT_PERCENTAGE, - UNIT_UV_INDEX, - UNIT_VOLT, + UV_INDEX, + VOLT, ) from homeassistant.helpers.typing import ConfigType @@ -46,7 +46,7 @@ UOM_FRIENDLY_NAME = { "10": TIME_DAYS, "12": "dB", "13": "dB A", - "14": UNIT_DEGREE, + "14": DEGREE, "16": "macroseismic", "17": TEMP_FAHRENHEIT, "18": "ft", @@ -97,12 +97,12 @@ UOM_FRIENDLY_NAME = { "64": "shindo", "65": "SML", "69": "gal", - "71": UNIT_UV_INDEX, - "72": UNIT_VOLT, + "71": UV_INDEX, + "72": VOLT, "73": POWER_WATT, "74": f"{POWER_WATT}/m²", "75": "weekday", - "76": f"Wind Direction ({UNIT_DEGREE})", + "76": f"Wind Direction ({DEGREE})", "77": TIME_YEARS, "82": "mm", "83": LENGTH_KILOMETERS, @@ -112,8 +112,8 @@ UOM_FRIENDLY_NAME = { "88": "Water activity", "89": "RPM", "90": FREQUENCY_HERTZ, - "91": f"{UNIT_DEGREE} (Relative to North)", - "92": f"{UNIT_DEGREE} (Relative to South)", + "91": f"{DEGREE} (Relative to North)", + "92": f"{DEGREE} (Relative to South)", } UOM_TO_STATES = { diff --git a/homeassistant/components/juicenet/sensor.py b/homeassistant/components/juicenet/sensor.py index 93eec19d41b..63eeb6fc58f 100644 --- a/homeassistant/components/juicenet/sensor.py +++ b/homeassistant/components/juicenet/sensor.py @@ -6,7 +6,7 @@ from homeassistant.const import ( POWER_WATT, TEMP_CELSIUS, TIME_SECONDS, - UNIT_VOLT, + VOLT, ) from homeassistant.helpers.entity import Entity @@ -17,7 +17,7 @@ _LOGGER = logging.getLogger(__name__) SENSOR_TYPES = { "status": ["Charging Status", None], "temperature": ["Temperature", TEMP_CELSIUS], - "voltage": ["Voltage", UNIT_VOLT], + "voltage": ["Voltage", VOLT], "amps": ["Amps", "A"], "watts": ["Watts", POWER_WATT], "charge_time": ["Charge time", TIME_SECONDS], diff --git a/homeassistant/components/lcn/const.py b/homeassistant/components/lcn/const.py index 817b6821db1..219db45dbd4 100644 --- a/homeassistant/components/lcn/const.py +++ b/homeassistant/components/lcn/const.py @@ -2,12 +2,12 @@ from itertools import product from homeassistant.const import ( + DEGREE, TEMP_CELSIUS, TEMP_FAHRENHEIT, TEMP_KELVIN, - UNIT_DEGREE, UNIT_PERCENTAGE, - UNIT_VOLT, + VOLT, ) DOMAIN = "lcn" @@ -164,12 +164,12 @@ VAR_UNITS = [ "PERCENT", "PPM", "VOLT", - UNIT_VOLT, + VOLT, "AMPERE", "AMP", "A", "DEGREE", - UNIT_DEGREE, + DEGREE, ] RELVARREF = ["CURRENT", "PROG"] diff --git a/homeassistant/components/metoffice/sensor.py b/homeassistant/components/metoffice/sensor.py index 678d02d9d83..b594517ac50 100644 --- a/homeassistant/components/metoffice/sensor.py +++ b/homeassistant/components/metoffice/sensor.py @@ -17,7 +17,7 @@ from homeassistant.const import ( SPEED_MILES_PER_HOUR, TEMP_CELSIUS, UNIT_PERCENTAGE, - UNIT_UV_INDEX, + UV_INDEX, ) import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity @@ -73,7 +73,7 @@ SENSOR_TYPES = { "wind_gust": ["Wind Gust", SPEED_MILES_PER_HOUR], "visibility": ["Visibility", None], "visibility_distance": ["Visibility Distance", LENGTH_KILOMETERS], - "uv": ["UV", UNIT_UV_INDEX], + "uv": ["UV", UV_INDEX], "precipitation": ["Probability of Precipitation", UNIT_PERCENTAGE], "humidity": ["Humidity", UNIT_PERCENTAGE], } diff --git a/homeassistant/components/miflora/sensor.py b/homeassistant/components/miflora/sensor.py index 61db00fa148..187f883187f 100644 --- a/homeassistant/components/miflora/sensor.py +++ b/homeassistant/components/miflora/sensor.py @@ -10,6 +10,7 @@ import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.const import ( + CONDUCTIVITY, CONF_FORCE_UPDATE, CONF_MAC, CONF_MONITORED_CONDITIONS, @@ -18,7 +19,6 @@ from homeassistant.const import ( EVENT_HOMEASSISTANT_START, TEMP_CELSIUS, TEMP_FAHRENHEIT, - UNIT_CONDUCTIVITY, UNIT_PERCENTAGE, ) from homeassistant.core import callback @@ -55,7 +55,7 @@ SENSOR_TYPES = { "temperature": ["Temperature", TEMP_CELSIUS, "mdi:thermometer"], "light": ["Light intensity", "lx", "mdi:white-balance-sunny"], "moisture": ["Moisture", UNIT_PERCENTAGE, "mdi:water-percent"], - "conductivity": ["Conductivity", UNIT_CONDUCTIVITY, "mdi:flash-circle"], + "conductivity": ["Conductivity", CONDUCTIVITY, "mdi:flash-circle"], "battery": ["Battery", UNIT_PERCENTAGE, "mdi:battery-charging"], } diff --git a/homeassistant/components/mysensors/sensor.py b/homeassistant/components/mysensors/sensor.py index ea621228cc4..15876163762 100644 --- a/homeassistant/components/mysensors/sensor.py +++ b/homeassistant/components/mysensors/sensor.py @@ -2,6 +2,8 @@ from homeassistant.components import mysensors from homeassistant.components.sensor import DOMAIN from homeassistant.const import ( + CONDUCTIVITY, + DEGREE, ENERGY_KILO_WATT_HOUR, FREQUENCY_HERTZ, LENGTH_METERS, @@ -9,10 +11,8 @@ from homeassistant.const import ( POWER_WATT, TEMP_CELSIUS, TEMP_FAHRENHEIT, - UNIT_CONDUCTIVITY, - UNIT_DEGREE, UNIT_PERCENTAGE, - UNIT_VOLT, + VOLT, ) SENSORS = { @@ -26,7 +26,7 @@ SENSORS = { "V_RAINRATE": [None, "mdi:weather-rainy"], "V_WIND": [None, "mdi:weather-windy"], "V_GUST": [None, "mdi:weather-windy"], - "V_DIRECTION": [UNIT_DEGREE, "mdi:compass"], + "V_DIRECTION": [DEGREE, "mdi:compass"], "V_WEIGHT": [MASS_KILOGRAMS, "mdi:weight-kilogram"], "V_DISTANCE": [LENGTH_METERS, "mdi:ruler"], "V_IMPEDANCE": ["ohm", None], @@ -40,11 +40,11 @@ SENSORS = { "S_VIBRATION": [FREQUENCY_HERTZ, None], "S_LIGHT_LEVEL": ["lx", "mdi:white-balance-sunny"], }, - "V_VOLTAGE": [UNIT_VOLT, "mdi:flash"], + "V_VOLTAGE": [VOLT, "mdi:flash"], "V_CURRENT": ["A", "mdi:flash-auto"], "V_PH": ["pH", None], "V_ORP": ["mV", None], - "V_EC": [UNIT_CONDUCTIVITY, None], + "V_EC": [CONDUCTIVITY, None], "V_VAR": ["var", None], "V_VA": ["VA", None], } diff --git a/homeassistant/components/nut/const.py b/homeassistant/components/nut/const.py index 13ffa318a4a..9b4908530a8 100644 --- a/homeassistant/components/nut/const.py +++ b/homeassistant/components/nut/const.py @@ -10,7 +10,7 @@ from homeassistant.const import ( TEMP_CELSIUS, TIME_SECONDS, UNIT_PERCENTAGE, - UNIT_VOLT, + VOLT, ) DOMAIN = "nut" @@ -102,15 +102,10 @@ SENSOR_TYPES = { None, ], "battery.charger.status": ["Charging Status", "", "mdi:information-outline", None], - "battery.voltage": ["Battery Voltage", UNIT_VOLT, "mdi:flash", None], - "battery.voltage.nominal": [ - "Nominal Battery Voltage", - UNIT_VOLT, - "mdi:flash", - None, - ], - "battery.voltage.low": ["Low Battery Voltage", UNIT_VOLT, "mdi:flash", None], - "battery.voltage.high": ["High Battery Voltage", UNIT_VOLT, "mdi:flash", None], + "battery.voltage": ["Battery Voltage", VOLT, "mdi:flash", None], + "battery.voltage.nominal": ["Nominal Battery Voltage", VOLT, "mdi:flash", None], + "battery.voltage.low": ["Low Battery Voltage", VOLT, "mdi:flash", None], + "battery.voltage.high": ["High Battery Voltage", VOLT, "mdi:flash", None], "battery.capacity": ["Battery Capacity", "Ah", "mdi:flash", None], "battery.current": ["Battery Current", "A", "mdi:flash", None], "battery.current.total": ["Total Battery Current", "A", "mdi:flash", None], @@ -150,16 +145,16 @@ SENSOR_TYPES = { "mdi:information-outline", None, ], - "input.transfer.low": ["Low Voltage Transfer", UNIT_VOLT, "mdi:flash", None], - "input.transfer.high": ["High Voltage Transfer", UNIT_VOLT, "mdi:flash", None], + "input.transfer.low": ["Low Voltage Transfer", VOLT, "mdi:flash", None], + "input.transfer.high": ["High Voltage Transfer", VOLT, "mdi:flash", None], "input.transfer.reason": [ "Voltage Transfer Reason", "", "mdi:information-outline", None, ], - "input.voltage": ["Input Voltage", UNIT_VOLT, "mdi:flash", None], - "input.voltage.nominal": ["Nominal Input Voltage", UNIT_VOLT, "mdi:flash", None], + "input.voltage": ["Input Voltage", VOLT, "mdi:flash", None], + "input.voltage.nominal": ["Nominal Input Voltage", VOLT, "mdi:flash", None], "input.frequency": ["Input Line Frequency", FREQUENCY_HERTZ, "mdi:flash", None], "input.frequency.nominal": [ "Nominal Input Line Frequency", @@ -175,8 +170,8 @@ SENSOR_TYPES = { ], "output.current": ["Output Current", "A", "mdi:flash", None], "output.current.nominal": ["Nominal Output Current", "A", "mdi:flash", None], - "output.voltage": ["Output Voltage", UNIT_VOLT, "mdi:flash", None], - "output.voltage.nominal": ["Nominal Output Voltage", UNIT_VOLT, "mdi:flash", None], + "output.voltage": ["Output Voltage", VOLT, "mdi:flash", None], + "output.voltage.nominal": ["Nominal Output Voltage", VOLT, "mdi:flash", None], "output.frequency": ["Output Frequency", FREQUENCY_HERTZ, "mdi:flash", None], "output.frequency.nominal": [ "Nominal Output Frequency", diff --git a/homeassistant/components/onewire/sensor.py b/homeassistant/components/onewire/sensor.py index d38c115c9d4..12a4546dbeb 100644 --- a/homeassistant/components/onewire/sensor.py +++ b/homeassistant/components/onewire/sensor.py @@ -13,7 +13,7 @@ from homeassistant.const import ( CONF_PORT, TEMP_CELSIUS, UNIT_PERCENTAGE, - UNIT_VOLT, + VOLT, ) import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity @@ -81,9 +81,9 @@ SENSOR_TYPES = { "counter_a": ["counter", "count"], "counter_b": ["counter", "count"], "HobbyBoard": ["none", "none"], - "voltage": ["voltage", UNIT_VOLT], - "voltage_VAD": ["voltage", UNIT_VOLT], - "voltage_VDD": ["voltage", UNIT_VOLT], + "voltage": ["voltage", VOLT], + "voltage_VAD": ["voltage", VOLT], + "voltage_VDD": ["voltage", VOLT], "current": ["current", "A"], } diff --git a/homeassistant/components/openuv/sensor.py b/homeassistant/components/openuv/sensor.py index 162fac50c6c..ec6e75d0e17 100644 --- a/homeassistant/components/openuv/sensor.py +++ b/homeassistant/components/openuv/sensor.py @@ -1,7 +1,7 @@ """Support for OpenUV sensors.""" import logging -from homeassistant.const import TIME_MINUTES, UNIT_UV_INDEX +from homeassistant.const import TIME_MINUTES, UV_INDEX from homeassistant.core import callback from homeassistant.util.dt import as_local, parse_datetime @@ -43,9 +43,9 @@ UV_LEVEL_LOW = "Low" SENSORS = { TYPE_CURRENT_OZONE_LEVEL: ("Current Ozone Level", "mdi:vector-triangle", "du"), - TYPE_CURRENT_UV_INDEX: ("Current UV Index", "mdi:weather-sunny", UNIT_UV_INDEX), + TYPE_CURRENT_UV_INDEX: ("Current UV Index", "mdi:weather-sunny", UV_INDEX), TYPE_CURRENT_UV_LEVEL: ("Current UV Level", "mdi:weather-sunny", None), - TYPE_MAX_UV_INDEX: ("Max UV Index", "mdi:weather-sunny", UNIT_UV_INDEX), + TYPE_MAX_UV_INDEX: ("Max UV Index", "mdi:weather-sunny", UV_INDEX), TYPE_SAFE_EXPOSURE_TIME_1: ( "Skin Type 1 Safe Exposure Time", "mdi:timer", diff --git a/homeassistant/components/openweathermap/sensor.py b/homeassistant/components/openweathermap/sensor.py index b5b9aa25e47..b730923f0bd 100644 --- a/homeassistant/components/openweathermap/sensor.py +++ b/homeassistant/components/openweathermap/sensor.py @@ -12,10 +12,10 @@ from homeassistant.const import ( CONF_API_KEY, CONF_MONITORED_CONDITIONS, CONF_NAME, + DEGREE, SPEED_METERS_PER_SECOND, TEMP_CELSIUS, TEMP_FAHRENHEIT, - UNIT_DEGREE, UNIT_PERCENTAGE, ) import homeassistant.helpers.config_validation as cv @@ -37,7 +37,7 @@ SENSOR_TYPES = { "weather": ["Condition", None], "temperature": ["Temperature", None], "wind_speed": ["Wind speed", SPEED_METERS_PER_SECOND], - "wind_bearing": ["Wind bearing", UNIT_DEGREE], + "wind_bearing": ["Wind bearing", DEGREE], "humidity": ["Humidity", UNIT_PERCENTAGE], "pressure": ["Pressure", "mbar"], "clouds": ["Cloud coverage", UNIT_PERCENTAGE], diff --git a/homeassistant/components/plant/__init__.py b/homeassistant/components/plant/__init__.py index f63df3995ec..5364fbf2e21 100644 --- a/homeassistant/components/plant/__init__.py +++ b/homeassistant/components/plant/__init__.py @@ -10,13 +10,13 @@ from homeassistant.components.recorder.util import execute, session_scope from homeassistant.const import ( ATTR_TEMPERATURE, ATTR_UNIT_OF_MEASUREMENT, + CONDUCTIVITY, CONF_SENSORS, STATE_OK, STATE_PROBLEM, STATE_UNAVAILABLE, STATE_UNKNOWN, TEMP_CELSIUS, - UNIT_CONDUCTIVITY, UNIT_PERCENTAGE, ) from homeassistant.core import callback @@ -148,7 +148,7 @@ class Plant(Entity): "max": CONF_MAX_MOISTURE, }, READING_CONDUCTIVITY: { - ATTR_UNIT_OF_MEASUREMENT: UNIT_CONDUCTIVITY, + ATTR_UNIT_OF_MEASUREMENT: CONDUCTIVITY, "min": CONF_MIN_CONDUCTIVITY, "max": CONF_MAX_CONDUCTIVITY, }, diff --git a/homeassistant/components/rfxtrx/__init__.py b/homeassistant/components/rfxtrx/__init__.py index 387c42a35b5..fb57359829c 100644 --- a/homeassistant/components/rfxtrx/__init__.py +++ b/homeassistant/components/rfxtrx/__init__.py @@ -19,7 +19,7 @@ from homeassistant.const import ( POWER_WATT, TEMP_CELSIUS, UNIT_PERCENTAGE, - UNIT_UV_INDEX, + UV_INDEX, ) import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity @@ -58,7 +58,7 @@ DATA_TYPES = OrderedDict( ("Sound", ""), ("Sensor Status", ""), ("Counter value", ""), - ("UV", UNIT_UV_INDEX), + ("UV", UV_INDEX), ("Humidity status", ""), ("Forecast", ""), ("Forecast numeric", ""), diff --git a/homeassistant/components/smappee/sensor.py b/homeassistant/components/smappee/sensor.py index d82e63a2614..cb252dda98b 100644 --- a/homeassistant/components/smappee/sensor.py +++ b/homeassistant/components/smappee/sensor.py @@ -3,11 +3,11 @@ from datetime import timedelta import logging from homeassistant.const import ( + DEGREE, ENERGY_KILO_WATT_HOUR, POWER_WATT, - UNIT_DEGREE, UNIT_PERCENTAGE, - UNIT_VOLT, + VOLT, VOLUME_CUBIC_METERS, ) from homeassistant.helpers.entity import Entity @@ -27,7 +27,7 @@ SENSOR_TYPES = { "active_power", ], "current": ["Current", "mdi:gauge", "local", "A", "current"], - "voltage": ["Voltage", "mdi:gauge", "local", UNIT_VOLT, "voltage"], + "voltage": ["Voltage", "mdi:gauge", "local", VOLT, "voltage"], "active_cosfi": [ "Power Factor", "mdi:gauge", @@ -74,7 +74,7 @@ SENSOR_TYPES = { "Water Sensor Temperature", "mdi:temperature-celsius", "water", - UNIT_DEGREE, + DEGREE, "temperature", ], "water_sensor_humidity": [ diff --git a/homeassistant/components/smartthings/sensor.py b/homeassistant/components/smartthings/sensor.py index b25b89ac9cf..8a6cf3cc215 100644 --- a/homeassistant/components/smartthings/sensor.py +++ b/homeassistant/components/smartthings/sensor.py @@ -17,7 +17,7 @@ from homeassistant.const import ( TEMP_CELSIUS, TEMP_FAHRENHEIT, UNIT_PERCENTAGE, - UNIT_VOLT, + VOLT, ) from . import SmartThingsEntity @@ -234,7 +234,7 @@ CAPABILITY_TO_SENSORS = { Map(Attribute.ultraviolet_index, "Ultraviolet Index", None, None) ], Capability.voltage_measurement: [ - Map(Attribute.voltage, "Voltage Measurement", UNIT_VOLT, None) + Map(Attribute.voltage, "Voltage Measurement", VOLT, None) ], Capability.washer_mode: [Map(Attribute.washer_mode, "Washer Mode", None, None)], Capability.washer_operating_state: [ diff --git a/homeassistant/components/solaredge_local/sensor.py b/homeassistant/components/solaredge_local/sensor.py index d9e7a45def2..94aa06c2647 100644 --- a/homeassistant/components/solaredge_local/sensor.py +++ b/homeassistant/components/solaredge_local/sensor.py @@ -17,7 +17,7 @@ from homeassistant.const import ( POWER_WATT, TEMP_CELSIUS, TEMP_FAHRENHEIT, - UNIT_VOLT, + VOLT, ) import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity @@ -42,20 +42,8 @@ INVERTER_MODES = ( # Supported sensor types: # Key: ['json_key', 'name', unit, icon, attribute name] SENSOR_TYPES = { - "current_AC_voltage": [ - "gridvoltage", - "Grid Voltage", - UNIT_VOLT, - "mdi:current-ac", - None, - ], - "current_DC_voltage": [ - "dcvoltage", - "DC Voltage", - UNIT_VOLT, - "mdi:current-dc", - None, - ], + "current_AC_voltage": ["gridvoltage", "Grid Voltage", VOLT, "mdi:current-ac", None], + "current_DC_voltage": ["dcvoltage", "DC Voltage", VOLT, "mdi:current-dc", None], "current_frequency": [ "gridfrequency", "Grid Frequency", @@ -136,7 +124,7 @@ SENSOR_TYPES = { "optimizer_voltage": [ "optimizervoltage", "Average Optimizer Voltage", - UNIT_VOLT, + VOLT, "mdi:solar-panel", None, ], diff --git a/homeassistant/components/solarlog/const.py b/homeassistant/components/solarlog/const.py index d89b175962e..07dd101b943 100644 --- a/homeassistant/components/solarlog/const.py +++ b/homeassistant/components/solarlog/const.py @@ -1,12 +1,7 @@ """Constants for the Solar-Log integration.""" from datetime import timedelta -from homeassistant.const import ( - ENERGY_KILO_WATT_HOUR, - POWER_WATT, - UNIT_PERCENTAGE, - UNIT_VOLT, -) +from homeassistant.const import ENERGY_KILO_WATT_HOUR, POWER_WATT, UNIT_PERCENTAGE, VOLT DOMAIN = "solarlog" @@ -22,8 +17,8 @@ SENSOR_TYPES = { "time": ["TIME", "last update", None, "mdi:calendar-clock"], "power_ac": ["powerAC", "power AC", POWER_WATT, "mdi:solar-power"], "power_dc": ["powerDC", "power DC", POWER_WATT, "mdi:solar-power"], - "voltage_ac": ["voltageAC", "voltage AC", UNIT_VOLT, "mdi:flash"], - "voltage_dc": ["voltageDC", "voltage DC", UNIT_VOLT, "mdi:flash"], + "voltage_ac": ["voltageAC", "voltage AC", VOLT, "mdi:flash"], + "voltage_dc": ["voltageDC", "voltage DC", VOLT, "mdi:flash"], "yield_day": ["yieldDAY", "yield day", ENERGY_KILO_WATT_HOUR, "mdi:solar-power"], "yield_yesterday": [ "yieldYESTERDAY", diff --git a/homeassistant/components/starline/sensor.py b/homeassistant/components/starline/sensor.py index 09642e66479..83392b31380 100644 --- a/homeassistant/components/starline/sensor.py +++ b/homeassistant/components/starline/sensor.py @@ -1,6 +1,6 @@ """Reads vehicle status from StarLine API.""" from homeassistant.components.sensor import DEVICE_CLASS_TEMPERATURE -from homeassistant.const import TEMP_CELSIUS, UNIT_PERCENTAGE, UNIT_VOLT +from homeassistant.const import TEMP_CELSIUS, UNIT_PERCENTAGE, VOLT from homeassistant.helpers.entity import Entity from homeassistant.helpers.icon import icon_for_battery_level, icon_for_signal_level @@ -9,7 +9,7 @@ from .const import DOMAIN from .entity import StarlineEntity SENSOR_TYPES = { - "battery": ["Battery", None, UNIT_VOLT, None], + "battery": ["Battery", None, VOLT, None], "balance": ["Balance", None, None, "mdi:cash-multiple"], "ctemp": ["Interior Temperature", DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, None], "etemp": ["Engine Temperature", DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, None], diff --git a/homeassistant/components/ted5000/sensor.py b/homeassistant/components/ted5000/sensor.py index 3982c7f0d04..3ea26286b18 100644 --- a/homeassistant/components/ted5000/sensor.py +++ b/homeassistant/components/ted5000/sensor.py @@ -7,7 +7,7 @@ import voluptuous as vol import xmltodict from homeassistant.components.sensor import PLATFORM_SCHEMA -from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT, POWER_WATT, UNIT_VOLT +from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT, POWER_WATT, VOLT from homeassistant.helpers import config_validation as cv from homeassistant.helpers.entity import Entity from homeassistant.util import Throttle @@ -43,7 +43,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): dev = [] for mtu in gateway.data: dev.append(Ted5000Sensor(gateway, name, mtu, POWER_WATT)) - dev.append(Ted5000Sensor(gateway, name, mtu, UNIT_VOLT)) + dev.append(Ted5000Sensor(gateway, name, mtu, VOLT)) add_entities(dev) return True @@ -54,7 +54,7 @@ class Ted5000Sensor(Entity): def __init__(self, gateway, name, mtu, unit): """Initialize the sensor.""" - units = {POWER_WATT: "power", UNIT_VOLT: "voltage"} + units = {POWER_WATT: "power", VOLT: "voltage"} self._gateway = gateway self._name = "{} mtu{} {}".format(name, mtu, units[unit]) self._mtu = mtu @@ -108,4 +108,4 @@ class Ted5000Gateway: power = int(doc["LiveData"]["Power"]["MTU%d" % mtu]["PowerNow"]) voltage = int(doc["LiveData"]["Voltage"]["MTU%d" % mtu]["VoltageNow"]) - self.data[mtu] = {POWER_WATT: power, UNIT_VOLT: voltage / 10} + self.data[mtu] = {POWER_WATT: power, VOLT: voltage / 10} diff --git a/homeassistant/components/tellduslive/sensor.py b/homeassistant/components/tellduslive/sensor.py index 693616ab78c..2e36f8f3ac2 100644 --- a/homeassistant/components/tellduslive/sensor.py +++ b/homeassistant/components/tellduslive/sensor.py @@ -11,7 +11,7 @@ from homeassistant.const import ( TEMP_CELSIUS, TIME_HOURS, UNIT_PERCENTAGE, - UNIT_UV_INDEX, + UV_INDEX, ) from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -45,7 +45,7 @@ SENSOR_TYPES = { SENSOR_TYPE_WINDDIRECTION: ["Wind direction", "", "", None], SENSOR_TYPE_WINDAVERAGE: ["Wind average", SPEED_METERS_PER_SECOND, "", None], SENSOR_TYPE_WINDGUST: ["Wind gust", SPEED_METERS_PER_SECOND, "", None], - SENSOR_TYPE_UV: ["UV", UNIT_UV_INDEX, "", None], + SENSOR_TYPE_UV: ["UV", UV_INDEX, "", None], SENSOR_TYPE_WATT: ["Power", POWER_WATT, "", None], SENSOR_TYPE_LUMINANCE: ["Luminance", "lx", None, DEVICE_CLASS_ILLUMINANCE], SENSOR_TYPE_DEW_POINT: ["Dew Point", TEMP_CELSIUS, None, DEVICE_CLASS_TEMPERATURE], diff --git a/homeassistant/components/torque/sensor.py b/homeassistant/components/torque/sensor.py index 7b7f7d7ec16..b4b44bdfb4f 100644 --- a/homeassistant/components/torque/sensor.py +++ b/homeassistant/components/torque/sensor.py @@ -6,7 +6,7 @@ import voluptuous as vol from homeassistant.components.http import HomeAssistantView from homeassistant.components.sensor import PLATFORM_SCHEMA -from homeassistant.const import CONF_EMAIL, CONF_NAME, UNIT_DEGREE +from homeassistant.const import CONF_EMAIL, CONF_NAME, DEGREE from homeassistant.core import callback import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity @@ -91,7 +91,7 @@ class TorqueReceiveDataView(HomeAssistantView): temp_unit = data[key] if "\\xC2\\xB0" in temp_unit: - temp_unit = temp_unit.replace("\\xC2\\xB0", UNIT_DEGREE) + temp_unit = temp_unit.replace("\\xC2\\xB0", DEGREE) units[pid] = temp_unit elif is_value: diff --git a/homeassistant/components/trafikverket_weatherstation/sensor.py b/homeassistant/components/trafikverket_weatherstation/sensor.py index 6c678ab732c..a8d992e02d5 100644 --- a/homeassistant/components/trafikverket_weatherstation/sensor.py +++ b/homeassistant/components/trafikverket_weatherstation/sensor.py @@ -14,11 +14,11 @@ from homeassistant.const import ( CONF_API_KEY, CONF_MONITORED_CONDITIONS, CONF_NAME, + DEGREE, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_TEMPERATURE, SPEED_METERS_PER_SECOND, TEMP_CELSIUS, - UNIT_DEGREE, UNIT_PERCENTAGE, ) from homeassistant.helpers.aiohttp_client import async_get_clientsession @@ -62,7 +62,7 @@ SENSOR_TYPES = { ], "wind_direction": [ "Wind direction", - UNIT_DEGREE, + DEGREE, "winddirection", "mdi:flag-triangle", None, diff --git a/homeassistant/components/wink/sensor.py b/homeassistant/components/wink/sensor.py index 1d2339702ad..cd3eb756fb3 100644 --- a/homeassistant/components/wink/sensor.py +++ b/homeassistant/components/wink/sensor.py @@ -3,7 +3,7 @@ import logging import pywink -from homeassistant.const import TEMP_CELSIUS, UNIT_DEGREE +from homeassistant.const import DEGREE, TEMP_CELSIUS from . import DOMAIN, WinkDevice @@ -48,7 +48,7 @@ class WinkSensorDevice(WinkDevice): """Initialize the Wink device.""" super().__init__(wink, hass) self.capability = self.wink.capability() - if self.wink.unit() == UNIT_DEGREE: + if self.wink.unit() == DEGREE: self._unit_of_measurement = TEMP_CELSIUS else: self._unit_of_measurement = self.wink.unit() diff --git a/homeassistant/components/wirelesstag/__init__.py b/homeassistant/components/wirelesstag/__init__.py index 335b24b8557..d4d60e220c6 100644 --- a/homeassistant/components/wirelesstag/__init__.py +++ b/homeassistant/components/wirelesstag/__init__.py @@ -12,7 +12,7 @@ from homeassistant.const import ( CONF_PASSWORD, CONF_USERNAME, UNIT_PERCENTAGE, - UNIT_VOLT, + VOLT, ) import homeassistant.helpers.config_validation as cv from homeassistant.helpers.dispatcher import dispatcher_send @@ -281,7 +281,7 @@ class WirelessTagBaseSensor(Entity): """Return the state attributes.""" return { ATTR_BATTERY_LEVEL: int(self._tag.battery_remaining * 100), - ATTR_VOLTAGE: f"{self._tag.battery_volts:.2f}{UNIT_VOLT}", + ATTR_VOLTAGE: f"{self._tag.battery_volts:.2f}{VOLT}", ATTR_TAG_SIGNAL_STRENGTH: f"{self._tag.signal_strength}dBm", ATTR_TAG_OUT_OF_RANGE: not self._tag.is_in_range, ATTR_TAG_POWER_CONSUMPTION: f"{self._tag.power_consumption:.2f}{UNIT_PERCENTAGE}", diff --git a/homeassistant/components/wunderground/sensor.py b/homeassistant/components/wunderground/sensor.py index b9532daa995..d6b7cb447f9 100644 --- a/homeassistant/components/wunderground/sensor.py +++ b/homeassistant/components/wunderground/sensor.py @@ -17,6 +17,7 @@ from homeassistant.const import ( CONF_LATITUDE, CONF_LONGITUDE, CONF_MONITORED_CONDITIONS, + DEGREE, IRRADIATION_WATTS_PER_SQUARE_METER, LENGTH_FEET, LENGTH_INCHES, @@ -26,7 +27,6 @@ from homeassistant.const import ( SPEED_MILES_PER_HOUR, TEMP_CELSIUS, TEMP_FAHRENHEIT, - UNIT_DEGREE, UNIT_PERCENTAGE, ) from homeassistant.exceptions import PlatformNotReady @@ -457,7 +457,7 @@ SENSOR_TYPES = { ), "weather": WUCurrentConditionsSensorConfig("Weather Summary", "weather", None), "wind_degrees": WUCurrentConditionsSensorConfig( - "Wind Degrees", "wind_degrees", "mdi:weather-windy", UNIT_DEGREE + "Wind Degrees", "wind_degrees", "mdi:weather-windy", DEGREE ), "wind_dir": WUCurrentConditionsSensorConfig( "Wind Direction", "wind_dir", "mdi:weather-windy" diff --git a/homeassistant/components/yr/sensor.py b/homeassistant/components/yr/sensor.py index e648e059fab..58a04ce62a6 100644 --- a/homeassistant/components/yr/sensor.py +++ b/homeassistant/components/yr/sensor.py @@ -17,6 +17,7 @@ from homeassistant.const import ( CONF_LONGITUDE, CONF_MONITORED_CONDITIONS, CONF_NAME, + DEGREE, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_PRESSURE, DEVICE_CLASS_TEMPERATURE, @@ -24,7 +25,6 @@ from homeassistant.const import ( PRESSURE_HPA, SPEED_METERS_PER_SECOND, TEMP_CELSIUS, - UNIT_DEGREE, UNIT_PERCENTAGE, ) from homeassistant.helpers.aiohttp_client import async_get_clientsession @@ -48,7 +48,7 @@ SENSOR_TYPES = { "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", UNIT_DEGREE, None], + "windDirection": ["Wind direction", DEGREE, None], "humidity": ["Humidity", UNIT_PERCENTAGE, DEVICE_CLASS_HUMIDITY], "fog": ["Fog", UNIT_PERCENTAGE, None], "cloudiness": ["Cloudiness", UNIT_PERCENTAGE, None], diff --git a/homeassistant/components/zamg/sensor.py b/homeassistant/components/zamg/sensor.py index a9f43f0fb21..e893c854804 100644 --- a/homeassistant/components/zamg/sensor.py +++ b/homeassistant/components/zamg/sensor.py @@ -17,10 +17,10 @@ from homeassistant.const import ( CONF_LONGITUDE, CONF_MONITORED_CONDITIONS, CONF_NAME, + DEGREE, LENGTH_METERS, SPEED_KILOMETERS_PER_HOUR, TEMP_CELSIUS, - UNIT_DEGREE, UNIT_PERCENTAGE, __version__, ) @@ -50,14 +50,14 @@ SENSOR_TYPES = { f"WG {SPEED_KILOMETERS_PER_HOUR}", float, ), - "wind_bearing": ("Wind Bearing", UNIT_DEGREE, f"WR {UNIT_DEGREE}", int), + "wind_bearing": ("Wind Bearing", DEGREE, f"WR {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", UNIT_DEGREE, f"WSR {UNIT_DEGREE}", int), + "wind_max_bearing": ("Top Wind Bearing", DEGREE, f"WSR {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), diff --git a/homeassistant/const.py b/homeassistant/const.py index e2fc11cf22e..1605fc751f8 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -346,19 +346,19 @@ ATTR_TEMPERATURE = "temperature" POWER_WATT = "W" # Voltage units -UNIT_VOLT = "V" +VOLT = "V" # Energy units ENERGY_WATT_HOUR = f"{POWER_WATT}h" ENERGY_KILO_WATT_HOUR = f"k{ENERGY_WATT_HOUR}" # Degree units -UNIT_DEGREE = "°" +DEGREE = "°" # Temperature units -TEMP_CELSIUS = f"{UNIT_DEGREE}C" -TEMP_FAHRENHEIT = f"{UNIT_DEGREE}F" -TEMP_KELVIN = f"{UNIT_DEGREE}K" +TEMP_CELSIUS = f"{DEGREE}C" +TEMP_FAHRENHEIT = f"{DEGREE}F" +TEMP_KELVIN = f"{DEGREE}K" # Time units TIME_MICROSECONDS = "μs" @@ -414,10 +414,10 @@ MASS_OUNCES: str = "oz" MASS_POUNDS: str = "lb" # Conductivity units -UNIT_CONDUCTIVITY: str = f"µS/{LENGTH_CENTIMETERS}" +CONDUCTIVITY: str = f"µS/{LENGTH_CENTIMETERS}" # UV Index units -UNIT_UV_INDEX: str = "UV index" +UV_INDEX: str = "UV index" # Percentage units UNIT_PERCENTAGE = "%" diff --git a/tests/components/plant/test_init.py b/tests/components/plant/test_init.py index 0f8cac370e8..801061e94ea 100644 --- a/tests/components/plant/test_init.py +++ b/tests/components/plant/test_init.py @@ -9,11 +9,11 @@ from homeassistant.components import recorder import homeassistant.components.plant as plant from homeassistant.const import ( ATTR_UNIT_OF_MEASUREMENT, + CONDUCTIVITY, STATE_OK, STATE_PROBLEM, STATE_UNAVAILABLE, STATE_UNKNOWN, - UNIT_CONDUCTIVITY, ) from homeassistant.setup import setup_component @@ -95,7 +95,7 @@ class TestPlant(unittest.TestCase): def test_initial_states(self): """Test plant initialises attributes if sensor already exists.""" self.hass.states.set( - MOISTURE_ENTITY, 5, {ATTR_UNIT_OF_MEASUREMENT: UNIT_CONDUCTIVITY} + MOISTURE_ENTITY, 5, {ATTR_UNIT_OF_MEASUREMENT: CONDUCTIVITY} ) plant_name = "some_plant" assert setup_component( @@ -115,7 +115,7 @@ class TestPlant(unittest.TestCase): self.hass, plant.DOMAIN, {plant.DOMAIN: {plant_name: GOOD_CONFIG}} ) self.hass.states.set( - MOISTURE_ENTITY, 5, {ATTR_UNIT_OF_MEASUREMENT: UNIT_CONDUCTIVITY} + MOISTURE_ENTITY, 5, {ATTR_UNIT_OF_MEASUREMENT: CONDUCTIVITY} ) self.hass.block_till_done() state = self.hass.states.get(f"plant.{plant_name}") @@ -132,9 +132,7 @@ class TestPlant(unittest.TestCase): self.hass, plant.DOMAIN, {plant.DOMAIN: {plant_name: GOOD_CONFIG}} ) self.hass.states.set( - MOISTURE_ENTITY, - STATE_UNAVAILABLE, - {ATTR_UNIT_OF_MEASUREMENT: UNIT_CONDUCTIVITY}, + MOISTURE_ENTITY, STATE_UNAVAILABLE, {ATTR_UNIT_OF_MEASUREMENT: CONDUCTIVITY} ) self.hass.block_till_done() state = self.hass.states.get(f"plant.{plant_name}") @@ -151,16 +149,14 @@ class TestPlant(unittest.TestCase): self.hass, plant.DOMAIN, {plant.DOMAIN: {plant_name: GOOD_CONFIG}} ) self.hass.states.set( - MOISTURE_ENTITY, 42, {ATTR_UNIT_OF_MEASUREMENT: UNIT_CONDUCTIVITY} + MOISTURE_ENTITY, 42, {ATTR_UNIT_OF_MEASUREMENT: CONDUCTIVITY} ) self.hass.block_till_done() state = self.hass.states.get(f"plant.{plant_name}") assert state.state == STATE_OK assert state.attributes[plant.READING_MOISTURE] == 42 self.hass.states.set( - MOISTURE_ENTITY, - STATE_UNAVAILABLE, - {ATTR_UNIT_OF_MEASUREMENT: UNIT_CONDUCTIVITY}, + MOISTURE_ENTITY, STATE_UNAVAILABLE, {ATTR_UNIT_OF_MEASUREMENT: CONDUCTIVITY} ) self.hass.block_till_done() state = self.hass.states.get(f"plant.{plant_name}") diff --git a/tests/components/prometheus/test_init.py b/tests/components/prometheus/test_init.py index 699df2c3505..55c09183e63 100644 --- a/tests/components/prometheus/test_init.py +++ b/tests/components/prometheus/test_init.py @@ -7,9 +7,9 @@ from homeassistant.components.demo.sensor import DemoSensor import homeassistant.components.prometheus as prometheus from homeassistant.const import ( CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, + DEGREE, DEVICE_CLASS_POWER, ENERGY_KILO_WATT_HOUR, - UNIT_DEGREE, ) from homeassistant.setup import async_setup_component @@ -48,7 +48,7 @@ async def prometheus_client(loop, hass, hass_client): sensor3.entity_id = "sensor.electricity_price" await sensor3.async_update_ha_state() - sensor4 = DemoSensor(None, "Wind Direction", 25, None, UNIT_DEGREE, None) + sensor4 = DemoSensor(None, "Wind Direction", 25, None, DEGREE, None) sensor4.hass = hass sensor4.entity_id = "sensor.wind_direction" await sensor4.async_update_ha_state() diff --git a/tests/components/sma/test_sensor.py b/tests/components/sma/test_sensor.py index 2556a0d2e76..de465d233ba 100644 --- a/tests/components/sma/test_sensor.py +++ b/tests/components/sma/test_sensor.py @@ -2,7 +2,7 @@ import logging from homeassistant.components.sensor import DOMAIN -from homeassistant.const import UNIT_VOLT +from homeassistant.const import VOLT from homeassistant.setup import async_setup_component from tests.common import assert_setup_component @@ -12,7 +12,7 @@ BASE_CFG = { "platform": "sma", "host": "1.1.1.1", "password": "", - "custom": {"my_sensor": {"key": "1234567890123", "unit": UNIT_VOLT}}, + "custom": {"my_sensor": {"key": "1234567890123", "unit": VOLT}}, } diff --git a/tests/components/yr/test_sensor.py b/tests/components/yr/test_sensor.py index b500a03c422..d676e88bfc3 100644 --- a/tests/components/yr/test_sensor.py +++ b/tests/components/yr/test_sensor.py @@ -3,7 +3,7 @@ from datetime import datetime from unittest.mock import patch from homeassistant.bootstrap import async_setup_component -from homeassistant.const import SPEED_METERS_PER_SECOND, UNIT_DEGREE, UNIT_PERCENTAGE +from homeassistant.const import DEGREE, SPEED_METERS_PER_SECOND, UNIT_PERCENTAGE import homeassistant.util.dt as dt_util from tests.common import assert_setup_component, load_fixture @@ -59,7 +59,7 @@ async def test_custom_setup(hass, aioclient_mock): assert state.state == "1009.3" state = hass.states.get("sensor.yr_wind_direction") - assert state.attributes.get("unit_of_measurement") == UNIT_DEGREE + assert state.attributes.get("unit_of_measurement") == DEGREE assert state.state == "103.6" state = hass.states.get("sensor.yr_humidity") @@ -105,7 +105,7 @@ async def test_forecast_setup(hass, aioclient_mock): assert state.state == "1008.3" state = hass.states.get("sensor.yr_wind_direction") - assert state.attributes.get("unit_of_measurement") == UNIT_DEGREE + assert state.attributes.get("unit_of_measurement") == DEGREE assert state.state == "148.9" state = hass.states.get("sensor.yr_humidity")