mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Adjust get_distance_unit in mazda integration (#80233)
* Adjust get_distance_unit in mazda integration * Use system compare with DistanceConverter * Adjust rounding * Use is not == * Reduce size of PR
This commit is contained in:
parent
3e0e845217
commit
a06bd04def
@ -13,7 +13,6 @@ from homeassistant.components.sensor import (
|
|||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_UNIT_SYSTEM_IMPERIAL,
|
|
||||||
LENGTH_KILOMETERS,
|
LENGTH_KILOMETERS,
|
||||||
LENGTH_MILES,
|
LENGTH_MILES,
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
@ -22,7 +21,7 @@ from homeassistant.const import (
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import StateType
|
from homeassistant.helpers.typing import StateType
|
||||||
from homeassistant.util.unit_system import UnitSystem
|
from homeassistant.util.unit_system import IMPERIAL_SYSTEM, UnitSystem
|
||||||
|
|
||||||
from . import MazdaEntity
|
from . import MazdaEntity
|
||||||
from .const import DATA_CLIENT, DATA_COORDINATOR, DOMAIN
|
from .const import DATA_CLIENT, DATA_COORDINATOR, DOMAIN
|
||||||
@ -50,9 +49,9 @@ class MazdaSensorEntityDescription(
|
|||||||
unit: Callable[[UnitSystem], str | None] | None = None
|
unit: Callable[[UnitSystem], str | None] | None = None
|
||||||
|
|
||||||
|
|
||||||
def _get_distance_unit(unit_system):
|
def _get_distance_unit(unit_system: UnitSystem) -> str:
|
||||||
"""Return the distance unit for the given unit system."""
|
"""Return the distance unit for the given unit system."""
|
||||||
if unit_system.name == CONF_UNIT_SYSTEM_IMPERIAL:
|
if unit_system is IMPERIAL_SYSTEM:
|
||||||
return LENGTH_MILES
|
return LENGTH_MILES
|
||||||
return LENGTH_KILOMETERS
|
return LENGTH_KILOMETERS
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user