mirror of
https://github.com/home-assistant/core.git
synced 2025-06-10 16:17:10 +00:00
Adjust distance unit check in geonetnz_quakes (#80236)
* Adjust length unit check in geonetnz_quakes * Use system compare * Use is not == * Apply suggestion Co-authored-by: Erik Montnemery <erik@montnemery.com> Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
parent
689dcb02dd
commit
faeb663dfe
@ -11,7 +11,6 @@ from homeassistant.const import (
|
|||||||
CONF_LONGITUDE,
|
CONF_LONGITUDE,
|
||||||
CONF_RADIUS,
|
CONF_RADIUS,
|
||||||
CONF_SCAN_INTERVAL,
|
CONF_SCAN_INTERVAL,
|
||||||
CONF_UNIT_SYSTEM_IMPERIAL,
|
|
||||||
LENGTH_KILOMETERS,
|
LENGTH_KILOMETERS,
|
||||||
LENGTH_MILES,
|
LENGTH_MILES,
|
||||||
)
|
)
|
||||||
@ -21,6 +20,7 @@ from homeassistant.helpers.dispatcher import async_dispatcher_send
|
|||||||
from homeassistant.helpers.event import async_track_time_interval
|
from homeassistant.helpers.event import async_track_time_interval
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
from homeassistant.util.unit_conversion import DistanceConverter
|
from homeassistant.util.unit_conversion import DistanceConverter
|
||||||
|
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_MINIMUM_MAGNITUDE,
|
CONF_MINIMUM_MAGNITUDE,
|
||||||
@ -95,7 +95,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
|||||||
feeds = hass.data[DOMAIN].setdefault(FEED, {})
|
feeds = hass.data[DOMAIN].setdefault(FEED, {})
|
||||||
|
|
||||||
radius = config_entry.data[CONF_RADIUS]
|
radius = config_entry.data[CONF_RADIUS]
|
||||||
if hass.config.units.name == CONF_UNIT_SYSTEM_IMPERIAL:
|
if hass.config.units is IMPERIAL_SYSTEM:
|
||||||
radius = DistanceConverter.convert(radius, LENGTH_MILES, LENGTH_KILOMETERS)
|
radius = DistanceConverter.convert(radius, LENGTH_MILES, LENGTH_KILOMETERS)
|
||||||
# Create feed entity manager for all platforms.
|
# Create feed entity manager for all platforms.
|
||||||
manager = GeonetnzQuakesFeedEntityManager(hass, config_entry, radius)
|
manager = GeonetnzQuakesFeedEntityManager(hass, config_entry, radius)
|
||||||
|
@ -9,17 +9,13 @@ from aio_geojson_geonetnz_quakes.feed_entry import GeonetnzQuakesFeedEntry
|
|||||||
|
|
||||||
from homeassistant.components.geo_location import GeolocationEvent
|
from homeassistant.components.geo_location import GeolocationEvent
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import ATTR_TIME, LENGTH_KILOMETERS, LENGTH_MILES
|
||||||
ATTR_TIME,
|
|
||||||
CONF_UNIT_SYSTEM_IMPERIAL,
|
|
||||||
LENGTH_KILOMETERS,
|
|
||||||
LENGTH_MILES,
|
|
||||||
)
|
|
||||||
from homeassistant.core import HomeAssistant, callback
|
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_conversion import DistanceConverter
|
from homeassistant.util.unit_conversion import DistanceConverter
|
||||||
|
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
||||||
|
|
||||||
from . import GeonetnzQuakesFeedEntityManager
|
from . import GeonetnzQuakesFeedEntityManager
|
||||||
from .const import DOMAIN, FEED
|
from .const import DOMAIN, FEED
|
||||||
@ -97,7 +93,7 @@ class GeonetnzQuakesEvent(GeolocationEvent):
|
|||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Call when entity is added to hass."""
|
"""Call when entity is added to hass."""
|
||||||
if self.hass.config.units.name == CONF_UNIT_SYSTEM_IMPERIAL:
|
if self.hass.config.units is IMPERIAL_SYSTEM:
|
||||||
self._attr_unit_of_measurement = LENGTH_MILES
|
self._attr_unit_of_measurement = LENGTH_MILES
|
||||||
self._remove_signal_delete = async_dispatcher_connect(
|
self._remove_signal_delete = async_dispatcher_connect(
|
||||||
self.hass,
|
self.hass,
|
||||||
@ -140,7 +136,7 @@ class GeonetnzQuakesEvent(GeolocationEvent):
|
|||||||
"""Update the internal state from the provided feed entry."""
|
"""Update the internal state from the provided feed entry."""
|
||||||
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 is IMPERIAL_SYSTEM:
|
||||||
self._attr_distance = DistanceConverter.convert(
|
self._attr_distance = DistanceConverter.convert(
|
||||||
feed_entry.distance_to_home, LENGTH_KILOMETERS, LENGTH_MILES
|
feed_entry.distance_to_home, LENGTH_KILOMETERS, LENGTH_MILES
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user