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:
epenet 2022-10-14 12:21:23 +02:00 committed by GitHub
parent 3e0e845217
commit a06bd04def
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,7 +13,6 @@ from homeassistant.components.sensor import (
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONF_UNIT_SYSTEM_IMPERIAL,
LENGTH_KILOMETERS,
LENGTH_MILES,
PERCENTAGE,
@ -22,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 UnitSystem
from homeassistant.util.unit_system import IMPERIAL_SYSTEM, UnitSystem
from . import MazdaEntity
from .const import DATA_CLIENT, DATA_COORDINATOR, DOMAIN
@ -50,9 +49,9 @@ class MazdaSensorEntityDescription(
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."""
if unit_system.name == CONF_UNIT_SYSTEM_IMPERIAL:
if unit_system is IMPERIAL_SYSTEM:
return LENGTH_MILES
return LENGTH_KILOMETERS