mirror of https://github.com/home-assistant/core
Use US_CUSTOMARY_SYSTEM in components (#80623)
This commit is contained in:
parent
374d46ec09
commit
2b2275dfb3
|
@ -37,7 +37,7 @@ from homeassistant.helpers.event import async_track_time_interval
|
|||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.util import location
|
||||
from homeassistant.util.unit_conversion import DistanceConverter
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
||||
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -171,7 +171,7 @@ async def async_setup_platform(
|
|||
stations_list = set(config.get(CONF_STATIONS_LIST, []))
|
||||
radius = config.get(CONF_RADIUS, 0)
|
||||
name = config[CONF_NAME]
|
||||
if hass.config.units is IMPERIAL_SYSTEM:
|
||||
if hass.config.units is US_CUSTOMARY_SYSTEM:
|
||||
radius = DistanceConverter.convert(radius, LENGTH_FEET, LENGTH_METERS)
|
||||
|
||||
# Create a single instance of CityBikesNetworks.
|
||||
|
|
|
@ -40,7 +40,7 @@ from homeassistant.const import (
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import StateType
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM, METRIC_SYSTEM
|
||||
from homeassistant.util.unit_system import METRIC_SYSTEM, US_CUSTOMARY_SYSTEM
|
||||
|
||||
from .const import DOMAIN
|
||||
from .entity import EcowittEntity
|
||||
|
@ -219,7 +219,7 @@ async def async_setup_entry(
|
|||
# Ignore metrics that are not supported by the user's locale
|
||||
if sensor.stype in _METRIC and hass.config.units is not METRIC_SYSTEM:
|
||||
return
|
||||
if sensor.stype in _IMPERIAL and hass.config.units is not IMPERIAL_SYSTEM:
|
||||
if sensor.stype in _IMPERIAL and hass.config.units is not US_CUSTOMARY_SYSTEM:
|
||||
return
|
||||
mapping = ECOWITT_SENSORS_MAPPING[sensor.stype]
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ from homeassistant.helpers.dispatcher import async_dispatcher_send
|
|||
from homeassistant.helpers.event import async_track_time_interval
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.util.unit_conversion import DistanceConverter
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
||||
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM
|
||||
|
||||
from .const import (
|
||||
CONF_CATEGORIES,
|
||||
|
@ -88,7 +88,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
|||
feeds = hass.data[DOMAIN].setdefault(FEED, {})
|
||||
|
||||
radius = config_entry.data[CONF_RADIUS]
|
||||
if hass.config.units is IMPERIAL_SYSTEM:
|
||||
if hass.config.units is US_CUSTOMARY_SYSTEM:
|
||||
radius = DistanceConverter.convert(radius, LENGTH_MILES, LENGTH_KILOMETERS)
|
||||
# Create feed entity manager for all platforms.
|
||||
manager = GdacsFeedEntityManager(hass, config_entry, radius)
|
||||
|
|
|
@ -16,7 +16,7 @@ from homeassistant.helpers import entity_registry as er
|
|||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.util.unit_conversion import DistanceConverter
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
||||
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM
|
||||
|
||||
from . import GdacsFeedEntityManager
|
||||
from .const import DEFAULT_ICON, DOMAIN, FEED
|
||||
|
@ -107,7 +107,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 IMPERIAL_SYSTEM:
|
||||
if self.hass.config.units is US_CUSTOMARY_SYSTEM:
|
||||
self._attr_unit_of_measurement = LENGTH_MILES
|
||||
self._remove_signal_delete = async_dispatcher_connect(
|
||||
self.hass, f"gdacs_delete_{self._external_id}", self._delete_callback
|
||||
|
@ -149,7 +149,7 @@ class GdacsEvent(GeolocationEvent):
|
|||
event_name = f"{feed_entry.country} ({feed_entry.event_id})"
|
||||
self._attr_name = f"{feed_entry.event_type}: {event_name}"
|
||||
# Convert distance if not metric system.
|
||||
if self.hass.config.units is IMPERIAL_SYSTEM:
|
||||
if self.hass.config.units is US_CUSTOMARY_SYSTEM:
|
||||
self._attr_distance = DistanceConverter.convert(
|
||||
feed_entry.distance_to_home, LENGTH_KILOMETERS, LENGTH_MILES
|
||||
)
|
||||
|
|
|
@ -20,7 +20,7 @@ from homeassistant.helpers.dispatcher import async_dispatcher_send
|
|||
from homeassistant.helpers.event import async_track_time_interval
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.util.unit_conversion import DistanceConverter
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
||||
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM
|
||||
|
||||
from .const import (
|
||||
CONF_MINIMUM_MAGNITUDE,
|
||||
|
@ -95,7 +95,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
|||
feeds = hass.data[DOMAIN].setdefault(FEED, {})
|
||||
|
||||
radius = config_entry.data[CONF_RADIUS]
|
||||
if hass.config.units is IMPERIAL_SYSTEM:
|
||||
if hass.config.units is US_CUSTOMARY_SYSTEM:
|
||||
radius = DistanceConverter.convert(radius, LENGTH_MILES, LENGTH_KILOMETERS)
|
||||
# Create feed entity manager for all platforms.
|
||||
manager = GeonetnzQuakesFeedEntityManager(hass, config_entry, radius)
|
||||
|
|
|
@ -15,7 +15,7 @@ from homeassistant.helpers import entity_registry as er
|
|||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.util.unit_conversion import DistanceConverter
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
||||
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM
|
||||
|
||||
from . import GeonetnzQuakesFeedEntityManager
|
||||
from .const import DOMAIN, FEED
|
||||
|
@ -93,7 +93,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 IMPERIAL_SYSTEM:
|
||||
if self.hass.config.units is US_CUSTOMARY_SYSTEM:
|
||||
self._attr_unit_of_measurement = LENGTH_MILES
|
||||
self._remove_signal_delete = async_dispatcher_connect(
|
||||
self.hass,
|
||||
|
@ -136,7 +136,7 @@ class GeonetnzQuakesEvent(GeolocationEvent):
|
|||
"""Update the internal state from the provided feed entry."""
|
||||
self._attr_name = feed_entry.title
|
||||
# Convert distance if not metric system.
|
||||
if self.hass.config.units is IMPERIAL_SYSTEM:
|
||||
if self.hass.config.units is US_CUSTOMARY_SYSTEM:
|
||||
self._attr_distance = DistanceConverter.convert(
|
||||
feed_entry.distance_to_home, LENGTH_KILOMETERS, LENGTH_MILES
|
||||
)
|
||||
|
|
|
@ -11,7 +11,7 @@ from homeassistant.const import (
|
|||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
||||
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM
|
||||
|
||||
from .const import (
|
||||
DEFAULT_RADIUS,
|
||||
|
@ -62,7 +62,7 @@ class GeonetnzVolcanoFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
if identifier in configured_instances(self.hass):
|
||||
return await self._show_form({"base": "already_configured"})
|
||||
|
||||
if self.hass.config.units is IMPERIAL_SYSTEM:
|
||||
if self.hass.config.units is US_CUSTOMARY_SYSTEM:
|
||||
user_input[CONF_UNIT_SYSTEM] = IMPERIAL_UNITS
|
||||
else:
|
||||
user_input[CONF_UNIT_SYSTEM] = METRIC_UNITS
|
||||
|
|
|
@ -22,7 +22,7 @@ from homeassistant.helpers.entity import DeviceInfo
|
|||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.location import find_coordinates
|
||||
import homeassistant.util.dt as dt_util
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
||||
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM
|
||||
|
||||
from .const import (
|
||||
ATTRIBUTION,
|
||||
|
@ -66,7 +66,7 @@ async def async_setup_entry(
|
|||
|
||||
if CONF_UNITS not in options:
|
||||
options[CONF_UNITS] = UNITS_METRIC
|
||||
if hass.config.units is IMPERIAL_SYSTEM:
|
||||
if hass.config.units is US_CUSTOMARY_SYSTEM:
|
||||
options[CONF_UNITS] = UNITS_IMPERIAL
|
||||
|
||||
if CONF_TRAVEL_MODE in new_data:
|
||||
|
|
|
@ -24,7 +24,7 @@ from homeassistant.helpers.selector import (
|
|||
LocationSelector,
|
||||
TimeSelector,
|
||||
)
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
||||
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM
|
||||
|
||||
from .const import (
|
||||
CONF_ARRIVAL_TIME,
|
||||
|
@ -98,7 +98,7 @@ def default_options(hass: HomeAssistant) -> dict[str, str | None]:
|
|||
CONF_DEPARTURE_TIME: None,
|
||||
CONF_UNIT_SYSTEM: METRIC_UNITS,
|
||||
}
|
||||
if hass.config.units is IMPERIAL_SYSTEM:
|
||||
if hass.config.units is US_CUSTOMARY_SYSTEM:
|
||||
default[CONF_UNIT_SYSTEM] = IMPERIAL_UNITS
|
||||
return default
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ from homeassistant.const import (
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import StateType
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM, UnitSystem
|
||||
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM, UnitSystem
|
||||
|
||||
from . import MazdaEntity
|
||||
from .const import DATA_CLIENT, DATA_COORDINATOR, DOMAIN
|
||||
|
@ -51,7 +51,7 @@ class MazdaSensorEntityDescription(
|
|||
|
||||
def _get_distance_unit(unit_system: UnitSystem) -> str:
|
||||
"""Return the distance unit for the given unit system."""
|
||||
if unit_system is IMPERIAL_SYSTEM:
|
||||
if unit_system is US_CUSTOMARY_SYSTEM:
|
||||
return LENGTH_MILES
|
||||
return LENGTH_KILOMETERS
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||
from homeassistant.helpers.icon import icon_for_battery_level
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.util.unit_conversion import DistanceConverter
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
||||
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM
|
||||
|
||||
from . import LeafEntity
|
||||
from .const import (
|
||||
|
@ -123,7 +123,7 @@ class LeafRangeSensor(LeafEntity, SensorEntity):
|
|||
if ret is None:
|
||||
return None
|
||||
|
||||
if self.car.hass.config.units is IMPERIAL_SYSTEM or self.car.force_miles:
|
||||
if self.car.hass.config.units is US_CUSTOMARY_SYSTEM or self.car.force_miles:
|
||||
ret = DistanceConverter.convert(ret, LENGTH_KILOMETERS, LENGTH_MILES)
|
||||
|
||||
return round(ret)
|
||||
|
@ -131,7 +131,7 @@ class LeafRangeSensor(LeafEntity, SensorEntity):
|
|||
@property
|
||||
def native_unit_of_measurement(self) -> str:
|
||||
"""Battery range unit."""
|
||||
if self.car.hass.config.units is IMPERIAL_SYSTEM or self.car.force_miles:
|
||||
if self.car.hass.config.units is US_CUSTOMARY_SYSTEM or self.car.force_miles:
|
||||
return LENGTH_MILES
|
||||
return LENGTH_KILOMETERS
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ from homeassistant.util.unit_conversion import (
|
|||
PressureConverter,
|
||||
SpeedConverter,
|
||||
)
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
||||
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM
|
||||
|
||||
from . import base_unique_id, device_info
|
||||
from .const import (
|
||||
|
@ -81,7 +81,7 @@ class NWSSensor(CoordinatorEntity, SensorEntity):
|
|||
self.entity_description = description
|
||||
|
||||
self._attr_name = f"{station} {description.name}"
|
||||
if hass.config.units is IMPERIAL_SYSTEM:
|
||||
if hass.config.units is US_CUSTOMARY_SYSTEM:
|
||||
self._attr_native_unit_of_measurement = description.unit_convert
|
||||
|
||||
@property
|
||||
|
|
|
@ -11,7 +11,7 @@ from homeassistant.core import HomeAssistant, callback
|
|||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM, UnitSystem
|
||||
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM, UnitSystem
|
||||
|
||||
from . import RainMachineData, RainMachineEntity
|
||||
from .const import DATA_RESTRICTIONS_UNIVERSAL, DOMAIN
|
||||
|
@ -130,7 +130,7 @@ class FreezeProtectionTemperatureSelect(RainMachineEntity, SelectEntity):
|
|||
self._label_to_api_value_map = {}
|
||||
|
||||
for option in description.extended_options:
|
||||
if unit_system is IMPERIAL_SYSTEM:
|
||||
if unit_system is US_CUSTOMARY_SYSTEM:
|
||||
label = option.imperial_label
|
||||
else:
|
||||
label = option.metric_label
|
||||
|
|
|
@ -30,7 +30,11 @@ from homeassistant.helpers.update_coordinator import (
|
|||
DataUpdateCoordinator,
|
||||
)
|
||||
from homeassistant.util.unit_conversion import DistanceConverter, VolumeConverter
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM, LENGTH_UNITS, PRESSURE_UNITS
|
||||
from homeassistant.util.unit_system import (
|
||||
LENGTH_UNITS,
|
||||
PRESSURE_UNITS,
|
||||
US_CUSTOMARY_SYSTEM,
|
||||
)
|
||||
|
||||
from . import get_device_info
|
||||
from .const import (
|
||||
|
@ -223,7 +227,7 @@ class SubaruSensor(
|
|||
if unit in LENGTH_UNITS:
|
||||
return round(unit_system.length(current_value, unit), 1)
|
||||
|
||||
if unit in PRESSURE_UNITS and unit_system == IMPERIAL_SYSTEM:
|
||||
if unit in PRESSURE_UNITS and unit_system == US_CUSTOMARY_SYSTEM:
|
||||
return round(
|
||||
unit_system.pressure(current_value, unit),
|
||||
1,
|
||||
|
@ -235,7 +239,7 @@ class SubaruSensor(
|
|||
FUEL_CONSUMPTION_LITERS_PER_HUNDRED_KILOMETERS,
|
||||
FUEL_CONSUMPTION_MILES_PER_GALLON,
|
||||
]
|
||||
and unit_system == IMPERIAL_SYSTEM
|
||||
and unit_system == US_CUSTOMARY_SYSTEM
|
||||
):
|
||||
return round((100.0 * L_PER_GAL) / (KM_PER_MI * current_value), 1)
|
||||
|
||||
|
@ -250,14 +254,14 @@ class SubaruSensor(
|
|||
return self.hass.config.units.length_unit
|
||||
|
||||
if unit in PRESSURE_UNITS:
|
||||
if self.hass.config.units == IMPERIAL_SYSTEM:
|
||||
if self.hass.config.units == US_CUSTOMARY_SYSTEM:
|
||||
return self.hass.config.units.pressure_unit
|
||||
|
||||
if unit in [
|
||||
FUEL_CONSUMPTION_LITERS_PER_HUNDRED_KILOMETERS,
|
||||
FUEL_CONSUMPTION_MILES_PER_GALLON,
|
||||
]:
|
||||
if self.hass.config.units == IMPERIAL_SYSTEM:
|
||||
if self.hass.config.units == US_CUSTOMARY_SYSTEM:
|
||||
return FUEL_CONSUMPTION_MILES_PER_GALLON
|
||||
|
||||
return unit
|
||||
|
|
|
@ -38,7 +38,7 @@ from homeassistant.core import HomeAssistant
|
|||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.util import slugify
|
||||
from homeassistant.util.unit_conversion import DistanceConverter, SpeedConverter
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
||||
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM
|
||||
|
||||
from . import TomorrowioDataUpdateCoordinator, TomorrowioEntity
|
||||
from .const import (
|
||||
|
@ -327,7 +327,7 @@ class BaseTomorrowioSensorEntity(TomorrowioEntity, SensorEntity):
|
|||
)
|
||||
if self.entity_description.native_unit_of_measurement is None:
|
||||
self._attr_native_unit_of_measurement = description.unit_metric
|
||||
if hass.config.units is IMPERIAL_SYSTEM:
|
||||
if hass.config.units is US_CUSTOMARY_SYSTEM:
|
||||
self._attr_native_unit_of_measurement = description.unit_imperial
|
||||
|
||||
@property
|
||||
|
@ -356,7 +356,7 @@ class BaseTomorrowioSensorEntity(TomorrowioEntity, SensorEntity):
|
|||
desc.imperial_conversion
|
||||
and desc.unit_imperial is not None
|
||||
and desc.unit_imperial != desc.unit_metric
|
||||
and self.hass.config.units is IMPERIAL_SYSTEM
|
||||
and self.hass.config.units is US_CUSTOMARY_SYSTEM
|
||||
):
|
||||
return handle_conversion(state, desc.imperial_conversion)
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ from homeassistant.helpers.entity import DeviceInfo
|
|||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.location import find_coordinates
|
||||
from homeassistant.util.unit_conversion import DistanceConverter
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
||||
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM
|
||||
|
||||
from .const import (
|
||||
CONF_AVOID_FERRIES,
|
||||
|
@ -69,7 +69,7 @@ async def async_setup_entry(
|
|||
CONF_AVOID_SUBSCRIPTION_ROADS: DEFAULT_AVOID_SUBSCRIPTION_ROADS,
|
||||
CONF_AVOID_TOLL_ROADS: DEFAULT_AVOID_TOLL_ROADS,
|
||||
}
|
||||
if hass.config.units is IMPERIAL_SYSTEM:
|
||||
if hass.config.units is US_CUSTOMARY_SYSTEM:
|
||||
defaults[CONF_UNITS] = IMPERIAL_UNITS
|
||||
|
||||
if not config_entry.options:
|
||||
|
|
Loading…
Reference in New Issue