Use local UNIT constants in waze_travel_time (#80325)

pull/80329/head
epenet 2022-10-14 15:11:22 +02:00 committed by GitHub
parent 2a887e6ed7
commit 7d56ae772e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 8 deletions

View File

@ -1,6 +1,4 @@
"""Constants for waze_travel_time."""
from homeassistant.const import CONF_UNIT_SYSTEM_IMPERIAL, CONF_UNIT_SYSTEM_METRIC
DOMAIN = "waze_travel_time"
CONF_DESTINATION = "destination"
@ -21,7 +19,9 @@ DEFAULT_AVOID_TOLL_ROADS = False
DEFAULT_AVOID_SUBSCRIPTION_ROADS = False
DEFAULT_AVOID_FERRIES = False
UNITS = [CONF_UNIT_SYSTEM_METRIC, CONF_UNIT_SYSTEM_IMPERIAL]
IMPERIAL_UNITS = "imperial"
METRIC_UNITS = "metric"
UNITS = [METRIC_UNITS, IMPERIAL_UNITS]
REGIONS = ["US", "NA", "EU", "IL", "AU"]
VEHICLE_TYPES = ["car", "taxi", "motorcycle"]

View File

@ -16,8 +16,6 @@ from homeassistant.const import (
ATTR_ATTRIBUTION,
CONF_NAME,
CONF_REGION,
CONF_UNIT_SYSTEM_IMPERIAL,
CONF_UNIT_SYSTEM_METRIC,
EVENT_HOMEASSISTANT_STARTED,
LENGTH_KILOMETERS,
LENGTH_MILES,
@ -49,6 +47,8 @@ from .const import (
DEFAULT_REALTIME,
DEFAULT_VEHICLE_TYPE,
DOMAIN,
IMPERIAL_UNITS,
METRIC_UNITS,
)
_LOGGER = logging.getLogger(__name__)
@ -65,13 +65,13 @@ async def async_setup_entry(
defaults = {
CONF_REALTIME: DEFAULT_REALTIME,
CONF_VEHICLE_TYPE: DEFAULT_VEHICLE_TYPE,
CONF_UNITS: CONF_UNIT_SYSTEM_METRIC,
CONF_UNITS: METRIC_UNITS,
CONF_AVOID_FERRIES: DEFAULT_AVOID_FERRIES,
CONF_AVOID_SUBSCRIPTION_ROADS: DEFAULT_AVOID_SUBSCRIPTION_ROADS,
CONF_AVOID_TOLL_ROADS: DEFAULT_AVOID_TOLL_ROADS,
}
if hass.config.units is IMPERIAL_SYSTEM:
defaults[CONF_UNITS] = CONF_UNIT_SYSTEM_IMPERIAL
defaults[CONF_UNITS] = IMPERIAL_UNITS
if not config_entry.options:
new_data = config_entry.data.copy()
@ -248,7 +248,7 @@ class WazeTravelTimeData:
self.duration, distance = routes[route]
if units == CONF_UNIT_SYSTEM_IMPERIAL:
if units == IMPERIAL_UNITS:
# Convert to miles.
self.distance = DistanceConverter.convert(
distance, LENGTH_KILOMETERS, LENGTH_MILES