Replace is_metric
with is METRIC_SYSTEM
(#80262)
This commit is contained in:
parent
faeb663dfe
commit
1445e08090
19 changed files with 47 additions and 23 deletions
|
@ -17,6 +17,7 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
|||
from homeassistant.helpers.device_registry import DeviceEntryType
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
from homeassistant.util.unit_system import METRIC_SYSTEM
|
||||
|
||||
from .const import ATTR_FORECAST, CONF_FORECAST, DOMAIN, MANUFACTURER
|
||||
|
||||
|
@ -116,7 +117,7 @@ class AccuWeatherDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
|||
current = await self.accuweather.async_get_current_conditions()
|
||||
forecast = (
|
||||
await self.accuweather.async_get_forecast(
|
||||
metric=self.hass.config.units.is_metric
|
||||
metric=self.hass.config.units is METRIC_SYSTEM
|
||||
)
|
||||
if self.forecast
|
||||
else {}
|
||||
|
|
|
@ -30,6 +30,7 @@ from homeassistant.core import HomeAssistant, callback
|
|||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import StateType
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
from homeassistant.util.unit_system import METRIC_SYSTEM
|
||||
|
||||
from . import AccuWeatherDataUpdateCoordinator
|
||||
from .const import (
|
||||
|
@ -412,12 +413,12 @@ class AccuWeatherSensor(
|
|||
self._attr_unique_id = (
|
||||
f"{coordinator.location_key}-{description.key}".lower()
|
||||
)
|
||||
if self.coordinator.hass.config.units.is_metric:
|
||||
if self.coordinator.hass.config.units is METRIC_SYSTEM:
|
||||
self._unit_system = API_METRIC
|
||||
else:
|
||||
self._unit_system = API_IMPERIAL
|
||||
self._attr_native_unit_of_measurement = self.entity_description.unit_fn(
|
||||
self.coordinator.hass.config.units.is_metric
|
||||
self.coordinator.hass.config.units is METRIC_SYSTEM
|
||||
)
|
||||
self._attr_device_info = coordinator.device_info
|
||||
if forecast_day is not None:
|
||||
|
|
|
@ -33,6 +33,7 @@ from homeassistant.core import HomeAssistant
|
|||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
from homeassistant.util.dt import utc_from_timestamp
|
||||
from homeassistant.util.unit_system import METRIC_SYSTEM
|
||||
|
||||
from . import AccuWeatherDataUpdateCoordinator
|
||||
from .const import (
|
||||
|
@ -70,7 +71,7 @@ class AccuWeatherEntity(
|
|||
# Coordinator data is used also for sensors which don't have units automatically
|
||||
# converted, hence the weather entity's native units follow the configured unit
|
||||
# system
|
||||
if coordinator.hass.config.units.is_metric:
|
||||
if coordinator.hass.config.units is METRIC_SYSTEM:
|
||||
self._attr_native_precipitation_unit = LENGTH_MILLIMETERS
|
||||
self._attr_native_pressure_unit = PRESSURE_HPA
|
||||
self._attr_native_temperature_unit = TEMP_CELSIUS
|
||||
|
|
|
@ -12,6 +12,7 @@ from homeassistant.const import Platform
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
from homeassistant.util.unit_system import METRIC_SYSTEM
|
||||
|
||||
from .const import DEFAULT_SCAN_INTERVAL, DOMAIN
|
||||
|
||||
|
@ -26,7 +27,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
address = entry.unique_id
|
||||
|
||||
elevation = hass.config.elevation
|
||||
is_metric = hass.config.units.is_metric
|
||||
is_metric = hass.config.units is METRIC_SYSTEM
|
||||
assert address is not None
|
||||
|
||||
ble_device = bluetooth.async_ble_device_from_address(hass, address)
|
||||
|
|
|
@ -29,6 +29,7 @@ from homeassistant.helpers.update_coordinator import (
|
|||
CoordinatorEntity,
|
||||
DataUpdateCoordinator,
|
||||
)
|
||||
from homeassistant.util.unit_system import METRIC_SYSTEM
|
||||
|
||||
from .const import DOMAIN, VOLUME_BECQUEREL, VOLUME_PICOCURIE
|
||||
|
||||
|
@ -112,7 +113,7 @@ async def async_setup_entry(
|
|||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Airthings BLE sensors."""
|
||||
is_metric = hass.config.units.is_metric
|
||||
is_metric = hass.config.units is METRIC_SYSTEM
|
||||
|
||||
coordinator: DataUpdateCoordinator[AirthingsDevice] = hass.data[DOMAIN][
|
||||
entry.entry_id
|
||||
|
|
|
@ -12,6 +12,7 @@ from homeassistant.helpers import discovery
|
|||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.util import Throttle
|
||||
from homeassistant.util.unit_system import METRIC_SYSTEM
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -33,7 +34,7 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
api_key = config[DOMAIN][CONF_API_KEY]
|
||||
|
||||
try:
|
||||
bloomsky = BloomSky(api_key, hass.config.units.is_metric)
|
||||
bloomsky = BloomSky(api_key, hass.config.units is METRIC_SYSTEM)
|
||||
except RuntimeError:
|
||||
return False
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ import homeassistant.helpers.config_validation as cv
|
|||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.util import Throttle
|
||||
from homeassistant.util.unit_system import METRIC_SYSTEM
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -584,7 +585,7 @@ def setup_platform(
|
|||
|
||||
if CONF_UNITS in config:
|
||||
units = config[CONF_UNITS]
|
||||
elif hass.config.units.is_metric:
|
||||
elif hass.config.units is METRIC_SYSTEM:
|
||||
units = "si"
|
||||
else:
|
||||
units = "us"
|
||||
|
|
|
@ -32,6 +32,7 @@ from homeassistant.helpers.icon import icon_for_battery_level
|
|||
from homeassistant.helpers.network import NoURLAvailableError, get_url
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.util.json import load_json, save_json
|
||||
from homeassistant.util.unit_system import METRIC_SYSTEM
|
||||
|
||||
from .const import (
|
||||
ATTR_ACCESS_TOKEN,
|
||||
|
@ -199,7 +200,7 @@ def setup_platform(
|
|||
if (unit_system := config[CONF_UNIT_SYSTEM]) == "default":
|
||||
authd_client.system = user_profile["locale"]
|
||||
if authd_client.system != "en_GB":
|
||||
if hass.config.units.is_metric:
|
||||
if hass.config.units is METRIC_SYSTEM:
|
||||
authd_client.system = "metric"
|
||||
else:
|
||||
authd_client.system = "en_US"
|
||||
|
@ -215,7 +216,7 @@ def setup_platform(
|
|||
user_profile,
|
||||
config_path,
|
||||
description,
|
||||
hass.config.units.is_metric,
|
||||
hass.config.units is METRIC_SYSTEM,
|
||||
clock_format,
|
||||
)
|
||||
for description in FITBIT_RESOURCES_LIST
|
||||
|
@ -229,7 +230,7 @@ def setup_platform(
|
|||
user_profile,
|
||||
config_path,
|
||||
FITBIT_RESOURCE_BATTERY,
|
||||
hass.config.units.is_metric,
|
||||
hass.config.units is METRIC_SYSTEM,
|
||||
clock_format,
|
||||
dev_extra,
|
||||
)
|
||||
|
|
|
@ -23,6 +23,7 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
|||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
from homeassistant.util import dt as dt_util
|
||||
from homeassistant.util.unit_conversion import DistanceConverter
|
||||
from homeassistant.util.unit_system import METRIC_SYSTEM
|
||||
|
||||
from .const import (
|
||||
COMM_TIMEOUT,
|
||||
|
@ -206,7 +207,7 @@ class Life360DataUpdateCoordinator(DataUpdateCoordinator[Life360Data]):
|
|||
address = address1 or address2
|
||||
|
||||
speed = max(0, float(loc["speed"]) * SPEED_FACTOR_MPH)
|
||||
if self._hass.config.units.is_metric:
|
||||
if self._hass.config.units is METRIC_SYSTEM:
|
||||
speed = DistanceConverter.convert(
|
||||
speed, LENGTH_MILES, LENGTH_KILOMETERS
|
||||
)
|
||||
|
|
|
@ -24,6 +24,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.util import Throttle
|
||||
import homeassistant.util.dt as dt_util
|
||||
from homeassistant.util.unit_system import METRIC_SYSTEM
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -92,7 +93,7 @@ def setup_platform(
|
|||
|
||||
if CONF_UNITS in config:
|
||||
units = config.get(CONF_UNITS)
|
||||
elif hass.config.units.is_metric:
|
||||
elif hass.config.units is METRIC_SYSTEM:
|
||||
units = UNITS[0]
|
||||
else:
|
||||
units = UNITS[2]
|
||||
|
|
|
@ -26,6 +26,7 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
|||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
from homeassistant.util import dt as dt_util
|
||||
from homeassistant.util.unit_conversion import DistanceConverter
|
||||
from homeassistant.util.unit_system import METRIC_SYSTEM
|
||||
|
||||
from .const import (
|
||||
CONF_TRACK_HOME,
|
||||
|
@ -95,7 +96,7 @@ class MetDataUpdateCoordinator(DataUpdateCoordinator["MetWeatherData"]):
|
|||
"""Initialize global Met data updater."""
|
||||
self._unsub_track_home: Callable[[], None] | None = None
|
||||
self.weather = MetWeatherData(
|
||||
hass, config_entry.data, hass.config.units.is_metric
|
||||
hass, config_entry.data, hass.config.units is METRIC_SYSTEM
|
||||
)
|
||||
self.weather.set_coordinates()
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ from homeassistant.helpers.device_registry import DeviceEntryType
|
|||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
from homeassistant.util.unit_system import METRIC_SYSTEM
|
||||
|
||||
from . import MetDataUpdateCoordinator
|
||||
from .const import ATTR_MAP, CONDITIONS_MAP, CONF_TRACK_HOME, DOMAIN, FORECAST_MAP
|
||||
|
@ -51,10 +52,13 @@ async def async_setup_entry(
|
|||
async_add_entities(
|
||||
[
|
||||
MetWeather(
|
||||
coordinator, config_entry.data, hass.config.units.is_metric, False
|
||||
coordinator,
|
||||
config_entry.data,
|
||||
hass.config.units is METRIC_SYSTEM,
|
||||
False,
|
||||
),
|
||||
MetWeather(
|
||||
coordinator, config_entry.data, hass.config.units.is_metric, True
|
||||
coordinator, config_entry.data, hass.config.units is METRIC_SYSTEM, True
|
||||
),
|
||||
]
|
||||
)
|
||||
|
|
|
@ -23,6 +23,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||
from homeassistant.helpers.event import async_track_state_change_event
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.util.unit_conversion import TemperatureConverter
|
||||
from homeassistant.util.unit_system import METRIC_SYSTEM
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -67,7 +68,7 @@ async def async_setup_platform(
|
|||
[
|
||||
MoldIndicator(
|
||||
name,
|
||||
hass.config.units.is_metric,
|
||||
hass.config.units is METRIC_SYSTEM,
|
||||
indoor_temp_sensor,
|
||||
outdoor_temp_sensor,
|
||||
indoor_humidity_sensor,
|
||||
|
|
|
@ -20,6 +20,7 @@ from homeassistant.const import (
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.util.unit_system import METRIC_SYSTEM
|
||||
|
||||
from .. import mysensors
|
||||
from .const import MYSENSORS_DISCOVERY, DiscoveryInfo
|
||||
|
@ -94,7 +95,9 @@ class MySensorsHVAC(mysensors.device.MySensorsEntity, ClimateEntity):
|
|||
@property
|
||||
def temperature_unit(self) -> str:
|
||||
"""Return the unit of measurement."""
|
||||
return TEMP_CELSIUS if self.hass.config.units.is_metric else TEMP_FAHRENHEIT
|
||||
return (
|
||||
TEMP_CELSIUS if self.hass.config.units is METRIC_SYSTEM else TEMP_FAHRENHEIT
|
||||
)
|
||||
|
||||
@property
|
||||
def current_temperature(self) -> float | None:
|
||||
|
|
|
@ -22,6 +22,7 @@ from homeassistant.config_entries import ConfigEntry
|
|||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
||||
from homeassistant.core import Event, HomeAssistant, callback
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.util.unit_system import METRIC_SYSTEM
|
||||
|
||||
from .const import (
|
||||
CONF_BAUD_RATE,
|
||||
|
@ -220,7 +221,7 @@ async def _get_gateway(
|
|||
protocol_version=version,
|
||||
)
|
||||
gateway.event_callback = event_callback
|
||||
gateway.metric = hass.config.units.is_metric
|
||||
gateway.metric = hass.config.units is METRIC_SYSTEM
|
||||
|
||||
if persistence:
|
||||
await gateway.start_persistence()
|
||||
|
|
|
@ -35,6 +35,7 @@ from homeassistant.const import (
|
|||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.util.unit_system import METRIC_SYSTEM
|
||||
|
||||
from .. import mysensors
|
||||
from .const import MYSENSORS_DISCOVERY, DiscoveryInfo
|
||||
|
@ -242,7 +243,7 @@ class MySensorsSensor(mysensors.device.MySensorsEntity, SensorEntity):
|
|||
return custom_unit
|
||||
|
||||
if set_req(self.value_type) == set_req.V_TEMP:
|
||||
if self.hass.config.units.is_metric:
|
||||
if self.hass.config.units is METRIC_SYSTEM:
|
||||
return TEMP_CELSIUS
|
||||
return TEMP_FAHRENHEIT
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ from homeassistant.exceptions import PlatformNotReady
|
|||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.util.unit_system import METRIC_SYSTEM
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -57,7 +58,7 @@ def setup_platform(
|
|||
|
||||
if CONF_UNIT_SYSTEM in config:
|
||||
unit_system = config[CONF_UNIT_SYSTEM]
|
||||
elif hass.config.units.is_metric:
|
||||
elif hass.config.units is METRIC_SYSTEM:
|
||||
unit_system = UNIT_SYSTEMS[1]
|
||||
else:
|
||||
unit_system = UNIT_SYSTEMS[0]
|
||||
|
|
|
@ -17,6 +17,7 @@ from homeassistant.const import STATE_IDLE, STATE_PAUSED
|
|||
import homeassistant.helpers.device_registry as dr
|
||||
from homeassistant.helpers.entity import DeviceInfo, Entity
|
||||
import homeassistant.util.dt as dt_util
|
||||
from homeassistant.util.unit_system import METRIC_SYSTEM
|
||||
|
||||
from . import roomba_reported_state
|
||||
from .const import DOMAIN
|
||||
|
@ -221,7 +222,7 @@ class IRobotVacuum(IRobotEntity, StateVacuumEntity):
|
|||
|
||||
if cleaned_area := mission_state.get("sqft", 0): # Imperial
|
||||
# Convert to m2 if the unit_system is set to metric
|
||||
if self.hass.config.units.is_metric:
|
||||
if self.hass.config.units is METRIC_SYSTEM:
|
||||
cleaned_area = round(cleaned_area * 0.0929)
|
||||
|
||||
return (cleaning_time, cleaned_area)
|
||||
|
|
|
@ -20,6 +20,7 @@ from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
|||
from homeassistant.helpers import aiohttp_client, device_registry
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.util.unit_system import METRIC_SYSTEM
|
||||
|
||||
from .const import (
|
||||
AIOSHELLY_DEVICE_TIMEOUT_SEC,
|
||||
|
@ -108,7 +109,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
|
||||
async def _async_setup_block_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
"""Set up Shelly block based device from a config entry."""
|
||||
temperature_unit = "C" if hass.config.units.is_metric else "F"
|
||||
temperature_unit = "C" if hass.config.units is METRIC_SYSTEM else "F"
|
||||
|
||||
options = aioshelly.common.ConnectionOptions(
|
||||
entry.data[CONF_HOST],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue