mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Use DistanceConverter in components (#80207)
This commit is contained in:
parent
503434e538
commit
a396e35c21
@ -19,7 +19,7 @@ from homeassistant.core import HomeAssistant, callback
|
|||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
from homeassistant.util.unit_conversion import DistanceConverter
|
||||||
|
|
||||||
from . import GdacsFeedEntityManager
|
from . import GdacsFeedEntityManager
|
||||||
from .const import DEFAULT_ICON, DOMAIN, FEED
|
from .const import DEFAULT_ICON, DOMAIN, FEED
|
||||||
@ -153,8 +153,8 @@ class GdacsEvent(GeolocationEvent):
|
|||||||
self._attr_name = f"{feed_entry.event_type}: {event_name}"
|
self._attr_name = f"{feed_entry.event_type}: {event_name}"
|
||||||
# Convert distance if not metric system.
|
# Convert distance if not metric system.
|
||||||
if self.hass.config.units.name == CONF_UNIT_SYSTEM_IMPERIAL:
|
if self.hass.config.units.name == CONF_UNIT_SYSTEM_IMPERIAL:
|
||||||
self._attr_distance = IMPERIAL_SYSTEM.length(
|
self._attr_distance = DistanceConverter.convert(
|
||||||
feed_entry.distance_to_home, LENGTH_KILOMETERS
|
feed_entry.distance_to_home, LENGTH_KILOMETERS, LENGTH_MILES
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self._attr_distance = feed_entry.distance_to_home
|
self._attr_distance = feed_entry.distance_to_home
|
||||||
|
@ -19,7 +19,7 @@ from homeassistant.core import HomeAssistant, callback
|
|||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
from homeassistant.util.unit_conversion import DistanceConverter
|
||||||
|
|
||||||
from . import GeonetnzQuakesFeedEntityManager
|
from . import GeonetnzQuakesFeedEntityManager
|
||||||
from .const import DOMAIN, FEED
|
from .const import DOMAIN, FEED
|
||||||
@ -141,8 +141,8 @@ class GeonetnzQuakesEvent(GeolocationEvent):
|
|||||||
self._attr_name = feed_entry.title
|
self._attr_name = feed_entry.title
|
||||||
# Convert distance if not metric system.
|
# Convert distance if not metric system.
|
||||||
if self.hass.config.units.name == CONF_UNIT_SYSTEM_IMPERIAL:
|
if self.hass.config.units.name == CONF_UNIT_SYSTEM_IMPERIAL:
|
||||||
self._attr_distance = IMPERIAL_SYSTEM.length(
|
self._attr_distance = DistanceConverter.convert(
|
||||||
feed_entry.distance_to_home, LENGTH_KILOMETERS
|
feed_entry.distance_to_home, LENGTH_KILOMETERS, LENGTH_MILES
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self._attr_distance = feed_entry.distance_to_home
|
self._attr_distance = feed_entry.distance_to_home
|
||||||
|
Loading…
x
Reference in New Issue
Block a user