diff --git a/homeassistant/components/bmw_connected_drive/const.py b/homeassistant/components/bmw_connected_drive/const.py index 6a8f82ae22d..cee94e942d5 100644 --- a/homeassistant/components/bmw_connected_drive/const.py +++ b/homeassistant/components/bmw_connected_drive/const.py @@ -1,10 +1,5 @@ """Const file for the MyBMW integration.""" -from homeassistant.const import ( - LENGTH_KILOMETERS, - LENGTH_MILES, - VOLUME_GALLONS, - VOLUME_LITERS, -) +from homeassistant.const import VOLUME_GALLONS, VOLUME_LITERS, UnitOfLength DOMAIN = "bmw_connected_drive" ATTRIBUTION = "Data provided by MyBMW" @@ -20,8 +15,8 @@ CONF_REFRESH_TOKEN = "refresh_token" DATA_HASS_CONFIG = "hass_config" UNIT_MAP = { - "KILOMETERS": LENGTH_KILOMETERS, - "MILES": LENGTH_MILES, + "KILOMETERS": UnitOfLength.KILOMETERS, + "MILES": UnitOfLength.MILES, "LITERS": VOLUME_LITERS, "GALLONS": VOLUME_GALLONS, } diff --git a/homeassistant/components/citybikes/sensor.py b/homeassistant/components/citybikes/sensor.py index 5da74167a0b..c87427e0e7e 100644 --- a/homeassistant/components/citybikes/sensor.py +++ b/homeassistant/components/citybikes/sensor.py @@ -24,8 +24,7 @@ from homeassistant.const import ( CONF_LONGITUDE, CONF_NAME, CONF_RADIUS, - LENGTH_FEET, - LENGTH_METERS, + UnitOfLength, ) from homeassistant.core import HomeAssistant from homeassistant.exceptions import PlatformNotReady @@ -172,7 +171,9 @@ async def async_setup_platform( radius = config.get(CONF_RADIUS, 0) name = config[CONF_NAME] if hass.config.units is US_CUSTOMARY_SYSTEM: - radius = DistanceConverter.convert(radius, LENGTH_FEET, LENGTH_METERS) + radius = DistanceConverter.convert( + radius, UnitOfLength.FEET, UnitOfLength.METERS + ) # Create a single instance of CityBikesNetworks. networks = hass.data.setdefault(CITYBIKES_NETWORKS, CityBikesNetworks(hass)) diff --git a/homeassistant/components/eafm/sensor.py b/homeassistant/components/eafm/sensor.py index a695a38bb4b..2650aa35489 100644 --- a/homeassistant/components/eafm/sensor.py +++ b/homeassistant/components/eafm/sensor.py @@ -7,7 +7,7 @@ import async_timeout from homeassistant.components.sensor import SensorEntity, SensorStateClass from homeassistant.config_entries import ConfigEntry -from homeassistant.const import LENGTH_METERS +from homeassistant.const import UnitOfLength from homeassistant.core import HomeAssistant from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.device_registry import DeviceEntryType @@ -23,7 +23,7 @@ from .const import DOMAIN _LOGGER = logging.getLogger(__name__) UNIT_MAPPING = { - "http://qudt.org/1.1/vocab/unit#Meter": LENGTH_METERS, + "http://qudt.org/1.1/vocab/unit#Meter": UnitOfLength.METERS, } diff --git a/homeassistant/components/gdacs/__init__.py b/homeassistant/components/gdacs/__init__.py index 269da061b58..9474e006dbb 100644 --- a/homeassistant/components/gdacs/__init__.py +++ b/homeassistant/components/gdacs/__init__.py @@ -11,8 +11,7 @@ from homeassistant.const import ( CONF_LONGITUDE, CONF_RADIUS, CONF_SCAN_INTERVAL, - LENGTH_KILOMETERS, - LENGTH_MILES, + UnitOfLength, ) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import aiohttp_client, config_validation as cv @@ -89,7 +88,9 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b radius = config_entry.data[CONF_RADIUS] if hass.config.units is US_CUSTOMARY_SYSTEM: - radius = DistanceConverter.convert(radius, LENGTH_MILES, LENGTH_KILOMETERS) + radius = DistanceConverter.convert( + radius, UnitOfLength.MILES, UnitOfLength.KILOMETERS + ) # Create feed entity manager for all platforms. manager = GdacsFeedEntityManager(hass, config_entry, radius) feeds[config_entry.entry_id] = manager diff --git a/homeassistant/components/gdacs/geo_location.py b/homeassistant/components/gdacs/geo_location.py index 5d3b8f3375b..06ab1aa0837 100644 --- a/homeassistant/components/gdacs/geo_location.py +++ b/homeassistant/components/gdacs/geo_location.py @@ -10,7 +10,7 @@ from aio_georss_gdacs.feed_entry import GdacsFeedEntry from homeassistant.components.geo_location import GeolocationEvent from homeassistant.config_entries import ConfigEntry -from homeassistant.const import LENGTH_KILOMETERS, LENGTH_MILES +from homeassistant.const import UnitOfLength from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import entity_registry as er from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -89,7 +89,7 @@ class GdacsEvent(GeolocationEvent): self._feed_manager = feed_manager self._external_id = external_id self._attr_unique_id = f"{integration_id}_{external_id}" - self._attr_unit_of_measurement = LENGTH_KILOMETERS + self._attr_unit_of_measurement = UnitOfLength.KILOMETERS self._alert_level = None self._country = None self._description = None @@ -108,7 +108,7 @@ class GdacsEvent(GeolocationEvent): async def async_added_to_hass(self) -> None: """Call when entity is added to hass.""" if self.hass.config.units is US_CUSTOMARY_SYSTEM: - self._attr_unit_of_measurement = LENGTH_MILES + self._attr_unit_of_measurement = UnitOfLength.MILES self._remove_signal_delete = async_dispatcher_connect( self.hass, f"gdacs_delete_{self._external_id}", self._delete_callback ) @@ -151,7 +151,7 @@ class GdacsEvent(GeolocationEvent): # Convert distance if not metric system. if self.hass.config.units is US_CUSTOMARY_SYSTEM: self._attr_distance = DistanceConverter.convert( - feed_entry.distance_to_home, LENGTH_KILOMETERS, LENGTH_MILES + feed_entry.distance_to_home, UnitOfLength.KILOMETERS, UnitOfLength.MILES ) else: self._attr_distance = feed_entry.distance_to_home diff --git a/homeassistant/components/geo_json_events/geo_location.py b/homeassistant/components/geo_json_events/geo_location.py index c0d6abe694f..166da1184c6 100644 --- a/homeassistant/components/geo_json_events/geo_location.py +++ b/homeassistant/components/geo_json_events/geo_location.py @@ -18,7 +18,7 @@ from homeassistant.const import ( CONF_SCAN_INTERVAL, CONF_URL, EVENT_HOMEASSISTANT_START, - LENGTH_KILOMETERS, + UnitOfLength, ) from homeassistant.core import Event, HomeAssistant, callback from homeassistant.helpers import aiohttp_client @@ -146,7 +146,7 @@ class GeoJsonLocationEvent(GeolocationEvent): _attr_should_poll = False _attr_source = SOURCE - _attr_unit_of_measurement = LENGTH_KILOMETERS + _attr_unit_of_measurement = UnitOfLength.KILOMETERS def __init__(self, feed_manager: GenericFeedManager, external_id: str) -> None: """Initialize entity with data from feed entry.""" diff --git a/homeassistant/components/geo_rss_events/sensor.py b/homeassistant/components/geo_rss_events/sensor.py index eba903a4cdf..2aade681e29 100644 --- a/homeassistant/components/geo_rss_events/sensor.py +++ b/homeassistant/components/geo_rss_events/sensor.py @@ -22,7 +22,7 @@ from homeassistant.const import ( CONF_RADIUS, CONF_UNIT_OF_MEASUREMENT, CONF_URL, - LENGTH_KILOMETERS, + UnitOfLength, ) from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv @@ -162,7 +162,9 @@ class GeoRssServiceSensor(SensorEntity): # And now compute the attributes from the filtered events. matrix = {} for entry in feed_entries: - matrix[entry.title] = f"{entry.distance_to_home:.0f}{LENGTH_KILOMETERS}" + matrix[ + entry.title + ] = f"{entry.distance_to_home:.0f}{UnitOfLength.KILOMETERS}" self._state_attributes = matrix elif status == UPDATE_OK_NO_DATA: _LOGGER.debug("Update successful, but no data received from %s", self._feed) diff --git a/homeassistant/components/geonetnz_quakes/__init__.py b/homeassistant/components/geonetnz_quakes/__init__.py index e09b4e720e3..dfe51f3119e 100644 --- a/homeassistant/components/geonetnz_quakes/__init__.py +++ b/homeassistant/components/geonetnz_quakes/__init__.py @@ -11,8 +11,7 @@ from homeassistant.const import ( CONF_LONGITUDE, CONF_RADIUS, CONF_SCAN_INTERVAL, - LENGTH_KILOMETERS, - LENGTH_MILES, + UnitOfLength, ) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import aiohttp_client, config_validation as cv @@ -96,7 +95,9 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b radius = config_entry.data[CONF_RADIUS] if hass.config.units is US_CUSTOMARY_SYSTEM: - radius = DistanceConverter.convert(radius, LENGTH_MILES, LENGTH_KILOMETERS) + radius = DistanceConverter.convert( + radius, UnitOfLength.MILES, UnitOfLength.KILOMETERS + ) # Create feed entity manager for all platforms. manager = GeonetnzQuakesFeedEntityManager(hass, config_entry, radius) feeds[config_entry.entry_id] = manager diff --git a/homeassistant/components/geonetnz_quakes/geo_location.py b/homeassistant/components/geonetnz_quakes/geo_location.py index a530c2d8fdb..411a0375461 100644 --- a/homeassistant/components/geonetnz_quakes/geo_location.py +++ b/homeassistant/components/geonetnz_quakes/geo_location.py @@ -9,7 +9,7 @@ from aio_geojson_geonetnz_quakes.feed_entry import GeonetnzQuakesFeedEntry from homeassistant.components.geo_location import GeolocationEvent from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ATTR_TIME, LENGTH_KILOMETERS, LENGTH_MILES +from homeassistant.const import ATTR_TIME, UnitOfLength from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import entity_registry as er from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -81,7 +81,7 @@ class GeonetnzQuakesEvent(GeolocationEvent): self._feed_manager = feed_manager self._external_id = external_id self._attr_unique_id = f"{integration_id}_{external_id}" - self._attr_unit_of_measurement = LENGTH_KILOMETERS + self._attr_unit_of_measurement = UnitOfLength.KILOMETERS self._depth = None self._locality = None self._magnitude = None @@ -94,7 +94,7 @@ class GeonetnzQuakesEvent(GeolocationEvent): async def async_added_to_hass(self) -> None: """Call when entity is added to hass.""" if self.hass.config.units is US_CUSTOMARY_SYSTEM: - self._attr_unit_of_measurement = LENGTH_MILES + self._attr_unit_of_measurement = UnitOfLength.MILES self._remove_signal_delete = async_dispatcher_connect( self.hass, f"geonetnz_quakes_delete_{self._external_id}", @@ -138,7 +138,7 @@ class GeonetnzQuakesEvent(GeolocationEvent): # Convert distance if not metric system. if self.hass.config.units is US_CUSTOMARY_SYSTEM: self._attr_distance = DistanceConverter.convert( - feed_entry.distance_to_home, LENGTH_KILOMETERS, LENGTH_MILES + feed_entry.distance_to_home, UnitOfLength.KILOMETERS, UnitOfLength.MILES ) else: self._attr_distance = feed_entry.distance_to_home diff --git a/homeassistant/components/geonetnz_volcano/__init__.py b/homeassistant/components/geonetnz_volcano/__init__.py index da081b42599..fb7770a5461 100644 --- a/homeassistant/components/geonetnz_volcano/__init__.py +++ b/homeassistant/components/geonetnz_volcano/__init__.py @@ -14,8 +14,7 @@ from homeassistant.const import ( CONF_RADIUS, CONF_SCAN_INTERVAL, CONF_UNIT_SYSTEM, - LENGTH_KILOMETERS, - LENGTH_MILES, + UnitOfLength, ) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import aiohttp_client, config_validation as cv @@ -92,7 +91,9 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b radius = config_entry.data[CONF_RADIUS] unit_system = config_entry.data[CONF_UNIT_SYSTEM] if unit_system == IMPERIAL_UNITS: - radius = DistanceConverter.convert(radius, LENGTH_MILES, LENGTH_KILOMETERS) + radius = DistanceConverter.convert( + radius, UnitOfLength.MILES, UnitOfLength.KILOMETERS + ) # Create feed entity manager for all platforms. manager = GeonetnzVolcanoFeedEntityManager(hass, config_entry, radius, unit_system) hass.data[DOMAIN][FEED][config_entry.entry_id] = manager diff --git a/homeassistant/components/geonetnz_volcano/sensor.py b/homeassistant/components/geonetnz_volcano/sensor.py index e78641f99e2..25e02f44308 100644 --- a/homeassistant/components/geonetnz_volcano/sensor.py +++ b/homeassistant/components/geonetnz_volcano/sensor.py @@ -5,12 +5,7 @@ import logging from homeassistant.components.sensor import SensorEntity from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ( - ATTR_LATITUDE, - ATTR_LONGITUDE, - LENGTH_KILOMETERS, - LENGTH_MILES, -) +from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE, UnitOfLength from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -115,7 +110,9 @@ class GeonetnzVolcanoSensor(SensorEntity): if self._unit_system == IMPERIAL_UNITS: self._distance = round( DistanceConverter.convert( - feed_entry.distance_to_home, LENGTH_KILOMETERS, LENGTH_MILES + feed_entry.distance_to_home, + UnitOfLength.KILOMETERS, + UnitOfLength.MILES, ), 1, ) diff --git a/homeassistant/components/ibeacon/sensor.py b/homeassistant/components/ibeacon/sensor.py index 32c17957b60..c0b9e92decc 100644 --- a/homeassistant/components/ibeacon/sensor.py +++ b/homeassistant/components/ibeacon/sensor.py @@ -13,7 +13,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import LENGTH_METERS, SIGNAL_STRENGTH_DECIBELS_MILLIWATT +from homeassistant.const import SIGNAL_STRENGTH_DECIBELS_MILLIWATT, UnitOfLength from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -58,7 +58,7 @@ SENSOR_DESCRIPTIONS = ( key="estimated_distance", name="Estimated Distance", icon="mdi:signal-distance-variant", - native_unit_of_measurement=LENGTH_METERS, + native_unit_of_measurement=UnitOfLength.METERS, value_fn=lambda ibeacon_advertisement: ibeacon_advertisement.distance, state_class=SensorStateClass.MEASUREMENT, device_class=SensorDeviceClass.DISTANCE, diff --git a/homeassistant/components/ign_sismologia/geo_location.py b/homeassistant/components/ign_sismologia/geo_location.py index 1194c58d2ca..e78dafae8ee 100644 --- a/homeassistant/components/ign_sismologia/geo_location.py +++ b/homeassistant/components/ign_sismologia/geo_location.py @@ -19,7 +19,7 @@ from homeassistant.const import ( CONF_RADIUS, CONF_SCAN_INTERVAL, EVENT_HOMEASSISTANT_START, - LENGTH_KILOMETERS, + UnitOfLength, ) from homeassistant.core import Event, HomeAssistant, callback import homeassistant.helpers.config_validation as cv @@ -146,7 +146,7 @@ class IgnSismologiaLocationEvent(GeolocationEvent): _attr_icon = "mdi:pulse" _attr_should_poll = False _attr_source = SOURCE - _attr_unit_of_measurement = LENGTH_KILOMETERS + _attr_unit_of_measurement = UnitOfLength.KILOMETERS def __init__( self, feed_manager: IgnSismologiaFeedEntityManager, external_id: str diff --git a/homeassistant/components/life360/coordinator.py b/homeassistant/components/life360/coordinator.py index b7121cc7fdb..5ea64d3f81d 100644 --- a/homeassistant/components/life360/coordinator.py +++ b/homeassistant/components/life360/coordinator.py @@ -11,12 +11,7 @@ from typing import Any from life360 import Life360, Life360Error, LoginError from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ( - LENGTH_FEET, - LENGTH_KILOMETERS, - LENGTH_METERS, - LENGTH_MILES, -) +from homeassistant.const import UnitOfLength from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryAuthFailed from homeassistant.helpers.aiohttp_client import async_get_clientsession @@ -211,7 +206,7 @@ class Life360DataUpdateCoordinator(DataUpdateCoordinator[Life360Data]): speed = max(0, float(loc["speed"]) * SPEED_FACTOR_MPH) if self._hass.config.units is METRIC_SYSTEM: speed = DistanceConverter.convert( - speed, LENGTH_MILES, LENGTH_KILOMETERS + speed, UnitOfLength.MILES, UnitOfLength.KILOMETERS ) data.members[member_id] = Life360Member( @@ -225,7 +220,9 @@ class Life360DataUpdateCoordinator(DataUpdateCoordinator[Life360Data]): # gps_accuracy in meters. round( DistanceConverter.convert( - float(loc["accuracy"]), LENGTH_FEET, LENGTH_METERS + float(loc["accuracy"]), + UnitOfLength.FEET, + UnitOfLength.METERS, ) ), dt_util.utc_from_timestamp(int(loc["timestamp"])), diff --git a/homeassistant/components/mazda/sensor.py b/homeassistant/components/mazda/sensor.py index 212d646051c..299e8890222 100644 --- a/homeassistant/components/mazda/sensor.py +++ b/homeassistant/components/mazda/sensor.py @@ -12,12 +12,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ( - LENGTH_KILOMETERS, - LENGTH_MILES, - PERCENTAGE, - PRESSURE_PSI, -) +from homeassistant.const import PERCENTAGE, PRESSURE_PSI, UnitOfLength from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import StateType @@ -52,8 +47,8 @@ class MazdaSensorEntityDescription( def _get_distance_unit(unit_system: UnitSystem) -> str: """Return the distance unit for the given unit system.""" if unit_system is US_CUSTOMARY_SYSTEM: - return LENGTH_MILES - return LENGTH_KILOMETERS + return UnitOfLength.MILES + return UnitOfLength.KILOMETERS def _fuel_remaining_percentage_supported(data): @@ -109,14 +104,18 @@ def _ev_remaining_range_supported(data): def _fuel_distance_remaining_value(data, unit_system): """Get the fuel distance remaining value.""" return round( - unit_system.length(data["status"]["fuelDistanceRemainingKm"], LENGTH_KILOMETERS) + unit_system.length( + data["status"]["fuelDistanceRemainingKm"], UnitOfLength.KILOMETERS + ) ) def _odometer_value(data, unit_system): """Get the odometer value.""" # In order to match the behavior of the Mazda mobile app, we always round down - return int(unit_system.length(data["status"]["odometerKm"], LENGTH_KILOMETERS)) + return int( + unit_system.length(data["status"]["odometerKm"], UnitOfLength.KILOMETERS) + ) def _front_left_tire_pressure_value(data, unit_system): @@ -148,7 +147,7 @@ def _ev_remaining_range_value(data, unit_system): """Get the remaining range value.""" return round( unit_system.length( - data["evStatus"]["chargeInfo"]["drivingRangeKm"], LENGTH_KILOMETERS + data["evStatus"]["chargeInfo"]["drivingRangeKm"], UnitOfLength.KILOMETERS ) ) diff --git a/homeassistant/components/met/__init__.py b/homeassistant/components/met/__init__.py index fc79ac4c60f..64734d5faaf 100644 --- a/homeassistant/components/met/__init__.py +++ b/homeassistant/components/met/__init__.py @@ -16,9 +16,8 @@ from homeassistant.const import ( CONF_LATITUDE, CONF_LONGITUDE, EVENT_CORE_CONFIG_UPDATE, - LENGTH_FEET, - LENGTH_METERS, Platform, + UnitOfLength, ) from homeassistant.core import Event, HomeAssistant from homeassistant.exceptions import HomeAssistantError @@ -161,7 +160,11 @@ class MetWeatherData: if not self._is_metric: elevation = int( - round(DistanceConverter.convert(elevation, LENGTH_FEET, LENGTH_METERS)) + round( + DistanceConverter.convert( + elevation, UnitOfLength.FEET, UnitOfLength.METERS + ) + ) ) coordinates = { diff --git a/homeassistant/components/nissan_leaf/sensor.py b/homeassistant/components/nissan_leaf/sensor.py index b0da5757db9..5b2f99b997b 100644 --- a/homeassistant/components/nissan_leaf/sensor.py +++ b/homeassistant/components/nissan_leaf/sensor.py @@ -6,7 +6,7 @@ import logging from voluptuous.validators import Number from homeassistant.components.sensor import SensorDeviceClass, SensorEntity -from homeassistant.const import LENGTH_KILOMETERS, LENGTH_MILES, PERCENTAGE +from homeassistant.const import PERCENTAGE, UnitOfLength from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.icon import icon_for_battery_level @@ -117,7 +117,9 @@ class LeafRangeSensor(LeafEntity, SensorEntity): return None if self.car.hass.config.units is US_CUSTOMARY_SYSTEM or self.car.force_miles: - ret = DistanceConverter.convert(ret, LENGTH_KILOMETERS, LENGTH_MILES) + ret = DistanceConverter.convert( + ret, UnitOfLength.KILOMETERS, UnitOfLength.MILES + ) return round(ret) @@ -125,5 +127,5 @@ class LeafRangeSensor(LeafEntity, SensorEntity): def native_unit_of_measurement(self) -> str: """Battery range unit.""" if self.car.hass.config.units is US_CUSTOMARY_SYSTEM or self.car.force_miles: - return LENGTH_MILES - return LENGTH_KILOMETERS + return UnitOfLength.MILES + return UnitOfLength.KILOMETERS diff --git a/homeassistant/components/nsw_rural_fire_service_feed/geo_location.py b/homeassistant/components/nsw_rural_fire_service_feed/geo_location.py index 553f73a128e..3eb598ffd3e 100644 --- a/homeassistant/components/nsw_rural_fire_service_feed/geo_location.py +++ b/homeassistant/components/nsw_rural_fire_service_feed/geo_location.py @@ -21,7 +21,7 @@ from homeassistant.const import ( CONF_SCAN_INTERVAL, EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP, - LENGTH_KILOMETERS, + UnitOfLength, ) from homeassistant.core import Event, HomeAssistant, callback from homeassistant.helpers import aiohttp_client, config_validation as cv @@ -181,7 +181,7 @@ class NswRuralFireServiceLocationEvent(GeolocationEvent): _attr_should_poll = False _attr_source = SOURCE - _attr_unit_of_measurement = LENGTH_KILOMETERS + _attr_unit_of_measurement = UnitOfLength.KILOMETERS def __init__( self, feed_manager: NswRuralFireServiceFeedEntityManager, external_id: str diff --git a/homeassistant/components/opengarage/sensor.py b/homeassistant/components/opengarage/sensor.py index 5e9591e8b6c..f3eb7b2a522 100644 --- a/homeassistant/components/opengarage/sensor.py +++ b/homeassistant/components/opengarage/sensor.py @@ -11,10 +11,10 @@ from homeassistant.components.sensor import ( ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - LENGTH_CENTIMETERS, PERCENTAGE, SIGNAL_STRENGTH_DECIBELS_MILLIWATT, TEMP_CELSIUS, + UnitOfLength, ) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity import EntityCategory @@ -28,7 +28,7 @@ _LOGGER = logging.getLogger(__name__) SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="dist", - native_unit_of_measurement=LENGTH_CENTIMETERS, + native_unit_of_measurement=UnitOfLength.CENTIMETERS, device_class=SensorDeviceClass.DISTANCE, state_class=SensorStateClass.MEASUREMENT, ), diff --git a/homeassistant/components/opensky/sensor.py b/homeassistant/components/opensky/sensor.py index 4c96d88f321..4c96f2575f0 100644 --- a/homeassistant/components/opensky/sensor.py +++ b/homeassistant/components/opensky/sensor.py @@ -14,8 +14,7 @@ from homeassistant.const import ( CONF_LONGITUDE, CONF_NAME, CONF_RADIUS, - LENGTH_KILOMETERS, - LENGTH_METERS, + UnitOfLength, ) from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv @@ -107,7 +106,7 @@ class OpenSkySensor(SensorEntity): self._latitude = latitude self._longitude = longitude self._radius = DistanceConverter.convert( - radius, LENGTH_KILOMETERS, LENGTH_METERS + radius, UnitOfLength.KILOMETERS, UnitOfLength.METERS ) self._altitude = altitude self._state = 0 diff --git a/homeassistant/components/proximity/__init__.py b/homeassistant/components/proximity/__init__.py index cf99f4fa503..edd50146559 100644 --- a/homeassistant/components/proximity/__init__.py +++ b/homeassistant/components/proximity/__init__.py @@ -11,11 +11,7 @@ from homeassistant.const import ( CONF_DEVICES, CONF_UNIT_OF_MEASUREMENT, CONF_ZONE, - LENGTH_FEET, - LENGTH_KILOMETERS, - LENGTH_METERS, - LENGTH_MILES, - LENGTH_YARD, + UnitOfLength, ) from homeassistant.core import HomeAssistant, State import homeassistant.helpers.config_validation as cv @@ -42,11 +38,11 @@ DEFAULT_TOLERANCE = 1 DOMAIN = "proximity" UNITS = [ - LENGTH_METERS, - LENGTH_KILOMETERS, - LENGTH_FEET, - LENGTH_YARD, - LENGTH_MILES, + UnitOfLength.METERS, + UnitOfLength.KILOMETERS, + UnitOfLength.FEET, + UnitOfLength.YARDS, + UnitOfLength.MILES, ] ZONE_SCHEMA = vol.Schema( @@ -236,7 +232,7 @@ class Proximity(Entity): continue distances_to_zone[device] = round( DistanceConverter.convert( - proximity, LENGTH_METERS, self.unit_of_measurement + proximity, UnitOfLength.METERS, self.unit_of_measurement ), 1, ) diff --git a/homeassistant/components/qld_bushfire/geo_location.py b/homeassistant/components/qld_bushfire/geo_location.py index e754de466d1..fc9fd727615 100644 --- a/homeassistant/components/qld_bushfire/geo_location.py +++ b/homeassistant/components/qld_bushfire/geo_location.py @@ -19,7 +19,7 @@ from homeassistant.const import ( CONF_RADIUS, CONF_SCAN_INTERVAL, EVENT_HOMEASSISTANT_START, - LENGTH_KILOMETERS, + UnitOfLength, ) from homeassistant.core import Event, HomeAssistant, callback import homeassistant.helpers.config_validation as cv @@ -154,7 +154,7 @@ class QldBushfireLocationEvent(GeolocationEvent): _attr_icon = "mdi:fire" _attr_should_poll = False _attr_source = SOURCE - _attr_unit_of_measurement = LENGTH_KILOMETERS + _attr_unit_of_measurement = UnitOfLength.KILOMETERS def __init__( self, feed_manager: QldBushfireFeedEntityManager, external_id: str diff --git a/homeassistant/components/renault/sensor.py b/homeassistant/components/renault/sensor.py index 251db26e889..d2204587549 100644 --- a/homeassistant/components/renault/sensor.py +++ b/homeassistant/components/renault/sensor.py @@ -24,10 +24,10 @@ from homeassistant.components.sensor import ( from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( ENERGY_KILO_WATT_HOUR, - LENGTH_KILOMETERS, PERCENTAGE, TEMP_CELSIUS, TIME_MINUTES, + UnitOfLength, UnitOfPower, UnitOfVolume, ) @@ -246,7 +246,7 @@ SENSOR_TYPES: tuple[RenaultSensorEntityDescription[Any], ...] = ( entity_class=RenaultSensor[KamereonVehicleBatteryStatusData], icon="mdi:ev-station", name="Battery autonomy", - native_unit_of_measurement=LENGTH_KILOMETERS, + native_unit_of_measurement=UnitOfLength.KILOMETERS, state_class=SensorStateClass.MEASUREMENT, ), RenaultSensorEntityDescription( @@ -287,7 +287,7 @@ SENSOR_TYPES: tuple[RenaultSensorEntityDescription[Any], ...] = ( entity_class=RenaultSensor[KamereonVehicleCockpitData], icon="mdi:sign-direction", name="Mileage", - native_unit_of_measurement=LENGTH_KILOMETERS, + native_unit_of_measurement=UnitOfLength.KILOMETERS, state_class=SensorStateClass.TOTAL_INCREASING, value_lambda=_get_rounded_value, ), @@ -299,7 +299,7 @@ SENSOR_TYPES: tuple[RenaultSensorEntityDescription[Any], ...] = ( entity_class=RenaultSensor[KamereonVehicleCockpitData], icon="mdi:gas-station", name="Fuel autonomy", - native_unit_of_measurement=LENGTH_KILOMETERS, + native_unit_of_measurement=UnitOfLength.KILOMETERS, state_class=SensorStateClass.MEASUREMENT, requires_fuel=True, value_lambda=_get_rounded_value, diff --git a/homeassistant/components/starline/sensor.py b/homeassistant/components/starline/sensor.py index 5b4954dcb05..d1a654a0590 100644 --- a/homeassistant/components/starline/sensor.py +++ b/homeassistant/components/starline/sensor.py @@ -11,9 +11,9 @@ from homeassistant.components.sensor import ( from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( ELECTRIC_POTENTIAL_VOLT, - LENGTH_KILOMETERS, PERCENTAGE, TEMP_CELSIUS, + UnitOfLength, UnitOfVolume, ) from homeassistant.core import HomeAssistant @@ -80,7 +80,7 @@ SENSOR_TYPES: tuple[StarlineSensorEntityDescription, ...] = ( StarlineSensorEntityDescription( key="mileage", name_="Mileage", - native_unit_of_measurement=LENGTH_KILOMETERS, + native_unit_of_measurement=UnitOfLength.KILOMETERS, device_class=SensorDeviceClass.DISTANCE, icon="mdi:counter", ), diff --git a/homeassistant/components/subaru/sensor.py b/homeassistant/components/subaru/sensor.py index e8ca6b41e88..7a74f77b1d5 100644 --- a/homeassistant/components/subaru/sensor.py +++ b/homeassistant/components/subaru/sensor.py @@ -13,13 +13,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ( - LENGTH_KILOMETERS, - LENGTH_MILES, - PERCENTAGE, - PRESSURE_HPA, - UnitOfVolume, -) +from homeassistant.const import PERCENTAGE, PRESSURE_HPA, UnitOfLength, UnitOfVolume from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import entity_registry as er from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -55,7 +49,7 @@ FUEL_CONSUMPTION_LITERS_PER_HUNDRED_KILOMETERS = "L/100km" FUEL_CONSUMPTION_MILES_PER_GALLON = "mi/gal" L_PER_GAL = VolumeConverter.convert(1, UnitOfVolume.GALLONS, UnitOfVolume.LITERS) -KM_PER_MI = DistanceConverter.convert(1, LENGTH_MILES, LENGTH_KILOMETERS) +KM_PER_MI = DistanceConverter.convert(1, UnitOfLength.MILES, UnitOfLength.KILOMETERS) # Sensor available to "Subaru Safety Plus" subscribers with Gen1 or Gen2 vehicles SAFETY_SENSORS = [ @@ -64,7 +58,7 @@ SAFETY_SENSORS = [ device_class=SensorDeviceClass.DISTANCE, icon="mdi:road-variant", name="Odometer", - native_unit_of_measurement=LENGTH_KILOMETERS, + native_unit_of_measurement=UnitOfLength.KILOMETERS, state_class=SensorStateClass.TOTAL_INCREASING, ), ] @@ -83,7 +77,7 @@ API_GEN_2_SENSORS = [ device_class=SensorDeviceClass.DISTANCE, icon="mdi:gas-station", name="Range", - native_unit_of_measurement=LENGTH_KILOMETERS, + native_unit_of_measurement=UnitOfLength.KILOMETERS, state_class=SensorStateClass.MEASUREMENT, ), SensorEntityDescription( @@ -123,7 +117,7 @@ EV_SENSORS = [ device_class=SensorDeviceClass.DISTANCE, icon="mdi:ev-station", name="EV range", - native_unit_of_measurement=LENGTH_MILES, + native_unit_of_measurement=UnitOfLength.MILES, state_class=SensorStateClass.MEASUREMENT, ), SensorEntityDescription( diff --git a/homeassistant/components/tankerkoenig/config_flow.py b/homeassistant/components/tankerkoenig/config_flow.py index e3d273825a5..be223e95713 100644 --- a/homeassistant/components/tankerkoenig/config_flow.py +++ b/homeassistant/components/tankerkoenig/config_flow.py @@ -16,7 +16,7 @@ from homeassistant.const import ( CONF_NAME, CONF_RADIUS, CONF_SHOW_ON_MAP, - LENGTH_KILOMETERS, + UnitOfLength, ) from homeassistant.core import HomeAssistant, callback from homeassistant.data_entry_flow import FlowResult @@ -204,7 +204,7 @@ class FlowHandler(config_entries.ConfigFlow, domain=DOMAIN): min=1.0, max=25, step=0.1, - unit_of_measurement=LENGTH_KILOMETERS, + unit_of_measurement=UnitOfLength.KILOMETERS, ), ), } diff --git a/homeassistant/components/tasmota/sensor.py b/homeassistant/components/tasmota/sensor.py index 282ea69d272..94011ca8ba1 100644 --- a/homeassistant/components/tasmota/sensor.py +++ b/homeassistant/components/tasmota/sensor.py @@ -22,7 +22,6 @@ from homeassistant.const import ( ELECTRIC_CURRENT_AMPERE, ELECTRIC_POTENTIAL_VOLT, ENERGY_KILO_WATT_HOUR, - LENGTH_CENTIMETERS, LIGHT_LUX, PERCENTAGE, PRESSURE_HPA, @@ -36,6 +35,7 @@ from homeassistant.const import ( TEMP_KELVIN, UnitOfApparentPower, UnitOfFrequency, + UnitOfLength, UnitOfMass, UnitOfPower, ) @@ -217,7 +217,7 @@ SENSOR_UNIT_MAP = { hc.ELECTRICAL_VOLT_AMPERE: UnitOfApparentPower.VOLT_AMPERE, hc.ENERGY_KILO_WATT_HOUR: ENERGY_KILO_WATT_HOUR, hc.FREQUENCY_HERTZ: UnitOfFrequency.HERTZ, - hc.LENGTH_CENTIMETERS: LENGTH_CENTIMETERS, + hc.LENGTH_CENTIMETERS: UnitOfLength.CENTIMETERS, hc.LIGHT_LUX: LIGHT_LUX, hc.MASS_KILOGRAMS: UnitOfMass.KILOGRAMS, hc.PERCENTAGE: PERCENTAGE, diff --git a/homeassistant/components/usgs_earthquakes_feed/geo_location.py b/homeassistant/components/usgs_earthquakes_feed/geo_location.py index c82705174fe..28927baf926 100644 --- a/homeassistant/components/usgs_earthquakes_feed/geo_location.py +++ b/homeassistant/components/usgs_earthquakes_feed/geo_location.py @@ -20,7 +20,7 @@ from homeassistant.const import ( CONF_RADIUS, CONF_SCAN_INTERVAL, EVENT_HOMEASSISTANT_START, - LENGTH_KILOMETERS, + UnitOfLength, ) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import aiohttp_client @@ -48,7 +48,7 @@ CONF_MINIMUM_MAGNITUDE = "minimum_magnitude" DEFAULT_MINIMUM_MAGNITUDE = 0.0 DEFAULT_RADIUS_IN_KM = 50.0 -DEFAULT_UNIT_OF_MEASUREMENT = LENGTH_KILOMETERS +DEFAULT_UNIT_OF_MEASUREMENT = UnitOfLength.KILOMETERS SCAN_INTERVAL = timedelta(minutes=5) diff --git a/homeassistant/components/wallbox/sensor.py b/homeassistant/components/wallbox/sensor.py index 3c2c5171a70..9e5b17a3111 100644 --- a/homeassistant/components/wallbox/sensor.py +++ b/homeassistant/components/wallbox/sensor.py @@ -15,8 +15,8 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( ELECTRIC_CURRENT_AMPERE, ENERGY_KILO_WATT_HOUR, - LENGTH_KILOMETERS, PERCENTAGE, + UnitOfLength, UnitOfPower, ) from homeassistant.core import HomeAssistant @@ -86,7 +86,7 @@ SENSOR_TYPES: dict[str, WallboxSensorEntityDescription] = { icon="mdi:map-marker-distance", name="Added Range", precision=0, - native_unit_of_measurement=LENGTH_KILOMETERS, + native_unit_of_measurement=UnitOfLength.KILOMETERS, device_class=SensorDeviceClass.DISTANCE, state_class=SensorStateClass.TOTAL_INCREASING, ), diff --git a/homeassistant/components/waze_travel_time/sensor.py b/homeassistant/components/waze_travel_time/sensor.py index c8d3e308435..089d98de905 100644 --- a/homeassistant/components/waze_travel_time/sensor.py +++ b/homeassistant/components/waze_travel_time/sensor.py @@ -16,9 +16,8 @@ from homeassistant.const import ( CONF_NAME, CONF_REGION, EVENT_HOMEASSISTANT_STARTED, - LENGTH_KILOMETERS, - LENGTH_MILES, TIME_MINUTES, + UnitOfLength, ) from homeassistant.core import CoreState, HomeAssistant from homeassistant.helpers.device_registry import DeviceEntryType @@ -210,7 +209,7 @@ class WazeTravelTimeData: if units == IMPERIAL_UNITS: # Convert to miles. self.distance = DistanceConverter.convert( - distance, LENGTH_KILOMETERS, LENGTH_MILES + distance, UnitOfLength.KILOMETERS, UnitOfLength.MILES ) else: self.distance = distance