Use length_util conversion (#67049)
This commit is contained in:
parent
d96c2df6a8
commit
dbb8806b31
2 changed files with 39 additions and 5 deletions
|
@ -14,6 +14,7 @@ from homeassistant.const import (
|
||||||
CONF_REGION,
|
CONF_REGION,
|
||||||
CONF_UNIT_SYSTEM_IMPERIAL,
|
CONF_UNIT_SYSTEM_IMPERIAL,
|
||||||
EVENT_HOMEASSISTANT_STARTED,
|
EVENT_HOMEASSISTANT_STARTED,
|
||||||
|
LENGTH_KILOMETERS,
|
||||||
TIME_MINUTES,
|
TIME_MINUTES,
|
||||||
)
|
)
|
||||||
from homeassistant.core import CoreState, HomeAssistant
|
from homeassistant.core import CoreState, HomeAssistant
|
||||||
|
@ -21,6 +22,7 @@ from homeassistant.helpers.device_registry import DeviceEntryType
|
||||||
from homeassistant.helpers.entity import DeviceInfo
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.location import find_coordinates
|
from homeassistant.helpers.location import find_coordinates
|
||||||
|
from homeassistant.util.unit_system import IMPERIAL_SYSTEM
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_AVOID_FERRIES,
|
CONF_AVOID_FERRIES,
|
||||||
|
@ -237,7 +239,7 @@ class WazeTravelTimeData:
|
||||||
|
|
||||||
if units == CONF_UNIT_SYSTEM_IMPERIAL:
|
if units == CONF_UNIT_SYSTEM_IMPERIAL:
|
||||||
# Convert to miles.
|
# Convert to miles.
|
||||||
self.distance = distance / 1.609
|
self.distance = IMPERIAL_SYSTEM.length(distance, LENGTH_KILOMETERS)
|
||||||
else:
|
else:
|
||||||
self.distance = distance
|
self.distance = distance
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,16 @@
|
||||||
from WazeRouteCalculator import WRCError
|
from WazeRouteCalculator import WRCError
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.waze_travel_time.const import DOMAIN
|
from homeassistant.components.waze_travel_time.const import (
|
||||||
|
CONF_AVOID_FERRIES,
|
||||||
|
CONF_AVOID_SUBSCRIPTION_ROADS,
|
||||||
|
CONF_AVOID_TOLL_ROADS,
|
||||||
|
CONF_REALTIME,
|
||||||
|
CONF_UNITS,
|
||||||
|
CONF_VEHICLE_TYPE,
|
||||||
|
DOMAIN,
|
||||||
|
)
|
||||||
|
from homeassistant.const import CONF_UNIT_SYSTEM_IMPERIAL
|
||||||
|
|
||||||
from .const import MOCK_CONFIG
|
from .const import MOCK_CONFIG
|
||||||
|
|
||||||
|
@ -11,11 +20,12 @@ from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="mock_config")
|
@pytest.fixture(name="mock_config")
|
||||||
async def mock_config_fixture(hass, data):
|
async def mock_config_fixture(hass, data, options):
|
||||||
"""Mock a Waze Travel Time config entry."""
|
"""Mock a Waze Travel Time config entry."""
|
||||||
config_entry = MockConfigEntry(
|
config_entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
data=data,
|
data=data,
|
||||||
|
options=options,
|
||||||
entry_id="test",
|
entry_id="test",
|
||||||
)
|
)
|
||||||
config_entry.add_to_hass(hass)
|
config_entry.add_to_hass(hass)
|
||||||
|
@ -40,8 +50,8 @@ def mock_update_keyerror_fixture(mock_wrc):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"data",
|
"data,options",
|
||||||
[MOCK_CONFIG],
|
[(MOCK_CONFIG, {})],
|
||||||
)
|
)
|
||||||
@pytest.mark.usefixtures("mock_update", "mock_config")
|
@pytest.mark.usefixtures("mock_update", "mock_config")
|
||||||
async def test_sensor(hass):
|
async def test_sensor(hass):
|
||||||
|
@ -68,6 +78,28 @@ async def test_sensor(hass):
|
||||||
assert hass.states.get("sensor.waze_travel_time").attributes["icon"] == "mdi:car"
|
assert hass.states.get("sensor.waze_travel_time").attributes["icon"] == "mdi:car"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"data,options",
|
||||||
|
[
|
||||||
|
(
|
||||||
|
MOCK_CONFIG,
|
||||||
|
{
|
||||||
|
CONF_UNITS: CONF_UNIT_SYSTEM_IMPERIAL,
|
||||||
|
CONF_REALTIME: True,
|
||||||
|
CONF_VEHICLE_TYPE: "car",
|
||||||
|
CONF_AVOID_TOLL_ROADS: True,
|
||||||
|
CONF_AVOID_SUBSCRIPTION_ROADS: True,
|
||||||
|
CONF_AVOID_FERRIES: True,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
@pytest.mark.usefixtures("mock_update", "mock_config")
|
||||||
|
async def test_imperial(hass):
|
||||||
|
"""Test that the imperial option works."""
|
||||||
|
assert hass.states.get("sensor.waze_travel_time").attributes["distance"] == 186.4113
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("mock_update_wrcerror")
|
@pytest.mark.usefixtures("mock_update_wrcerror")
|
||||||
async def test_sensor_failed_wrcerror(hass, caplog):
|
async def test_sensor_failed_wrcerror(hass, caplog):
|
||||||
"""Test that sensor update fails with log message."""
|
"""Test that sensor update fails with log message."""
|
||||||
|
|
Loading…
Add table
Reference in a new issue