Add unit system support

Add unit symbol constants

Initial unit system object

Import more constants

Pydoc for unit system file

Import constants for configuration validation

Unit system validation method

Typing for constants

Inches are valid lengths too

Typings

Change base class to dict - needed for remote api call serialization

Validation

Use dictionary keys

Defined unit systems

Update location util to use metric instead of us fahrenheit

Update constant imports

Import defined unit systems

Update configuration to use unit system

Update schema to use unit system

Update constants

Add imports to core for unit system and distance

Type for config

Default unit system

Convert distance from HASS instance

Update temperature conversion to use unit system

Update temperature conversion

Set unit system based on configuration

Set info unit system

Return unit system dictionary with config dictionary

Auto discover unit system

Update location test for use metric

Update forecast unit system

Update mold indicator unit system

Update thermostat unit system

Update thermostat demo test

Unit tests around unit system

Update test common hass configuration

Update configuration unit tests

There should always be a unit system!

Update core unit tests

Constants typing

Linting issues

Remove unused import

Update fitbit sensor to use application unit system

Update google travel time to use application unit system

Update configuration example

Update dht sensor

Update DHT temperature conversion to use the utility function

Update swagger config

Update my sensors metric flag

Update hvac component temperature conversion

HVAC conversion for temperature

Pull unit from sensor type map

Pull unit from sensor type map

Update the temper sensor unit

Update yWeather sensor unit

Update hvac demo unit test

Set unit test config unit system to metric

Use hass unit system length for default in proximity

Use the name of the system instead of temperature

Use constants from const

Unused import

Forecasted temperature

Fix calculation in case furthest distance is greater than 1000000 units

Remove unneeded constants

Set default length to km or miles

Use constants

Linting doesn't like importing just for typing

Fix reference

Test is expecting meters - set config to meters

Use constant

Use constant

PyDoc for unit test

Should be not in

Rename to units

Change unit system to be an object - not a dictionary

Return tuple in conversion

Move convert to temperature util

Temperature conversion is now in unit system

Update imports

Rename to units

Units is now an object

Use temperature util conversion

Unit system is now an object

Validate and convert unit system config

Return the scalar value in template distance

Test is expecting meters

Update unit tests around unit system

Distance util returns tuple

Fix location info test

Set units

Update unit tests

Convert distance

DOH

Pull out the scalar from the vector

Linting

I really hate python linting

Linting again

BLARG

Unit test documentation

Unit test around is metric flag

Break ternary statement into if/else blocks

Don't use dictionary - use members

is metric flag

Rename constants

Use is metric flag

Move constants to CONST file

Move to const file

Raise error if unit is not expected

Typing

No need to return unit since only performing conversion if it can work

Use constants

Line wrapping

Raise error if invalid value

Remove subscripts from conversion as they are no longer returned as tuples

No longer tuples

No longer tuples

Check for numeric type

Fix string format to use correct variable

Typing

Assert errors raised

Remove subscript

Only convert temperature if we know the unit

If no unit of measurement set - default to HASS config

Convert only if we know the unit

Remove subscription

Fix not in clause

Linting fixes

Wants a boolean

Clearer if-block

Check if the key is in the config first

Missed a couple expecting tuples

Backwards compatibility

No like-y ternary!

Error handling around state setting

Pretty unit system configuration validation

More tuple crap

Use is metric flag

Error handling around min/max temp

Explode if no unit

Pull unit from config

Celsius has a decimal

Unused import

Check if it's a temperature before we try to convert it to a temperature

Linting says too many statements - combine lat/long in a fairly reasonable manner

Backwards compatibility unit test

Better doc
This commit is contained in:
Teagan M. Glenn authored and Paulus Schoutsen committed 2016-08-04 22:02:19 -07:00
1 parent 792154a6a7
commit 26526ca57a
39 files changed
+597 -263

No files matched your search

+3 -2
View File
@@ -6,11 +6,12 @@ from unittest import mock
from homeassistant import core as ha, loader
from homeassistant.bootstrap import _setup_component
from homeassistant.helpers.entity import ToggleEntity
from homeassistant.helpers.unit_system import METRIC_SYSTEM
import homeassistant.util.dt as date_util
from homeassistant.const import (
STATE_ON, STATE_OFF, DEVICE_DEFAULT_NAME, EVENT_TIME_CHANGED,
EVENT_STATE_CHANGED, EVENT_PLATFORM_DISCOVERED, ATTR_SERVICE,
ATTR_DISCOVERED, SERVER_PORT, TEMP_CELSIUS)
ATTR_DISCOVERED, SERVER_PORT)
from homeassistant.components import sun, mqtt
_TEST_INSTANCE_PORT = SERVER_PORT
@@ -37,7 +38,7 @@ def get_test_home_assistant(num_threads=None):
hass.config.longitude = -117.22743
hass.config.elevation = 0
hass.config.time_zone = date_util.get_time_zone('US/Pacific')
hass.config.temperature_unit = TEMP_CELSIUS
hass.config.units = METRIC_SYSTEM
if 'custom_components.test' not in loader.AVAILABLE_COMPONENTS:
loader.prepare(hass)
+3 -3
View File
@@ -1,8 +1,8 @@
"""The tests for the demo hvac."""
import unittest
from homeassistant.const import (
TEMP_CELSIUS,
from homeassistant.helpers.unit_system import (
METRIC_SYSTEM,
)
from homeassistant.components import hvac
@@ -18,7 +18,7 @@ class TestDemoHvac(unittest.TestCase):
def setUp(self): # pylint: disable=invalid-name
"""Setup things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.hass.config.temperature_unit = TEMP_CELSIUS
self.hass.config.units = METRIC_SYSTEM
self.assertTrue(hvac.setup(self.hass, {'hvac': {
'platform': 'demo',
}}))
+5 -5
View File
@@ -1,8 +1,8 @@
"""The tests for the demo thermostat."""
import unittest
from homeassistant.const import (
TEMP_CELSIUS,
from homeassistant.helpers.unit_system import (
METRIC_SYSTEM,
)
from homeassistant.components import thermostat
@@ -18,7 +18,7 @@ class TestDemoThermostat(unittest.TestCase):
def setUp(self): # pylint: disable=invalid-name
"""Setup things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.hass.config.temperature_unit = TEMP_CELSIUS
self.hass.config.units = METRIC_SYSTEM
self.assertTrue(thermostat.setup(self.hass, {'thermostat': {
'platform': 'demo',
}}))
@@ -43,10 +43,10 @@ class TestDemoThermostat(unittest.TestCase):
def test_set_target_temp_bad_attr(self):
"""Test setting the target temperature without required attribute."""
self.assertEqual('21', self.hass.states.get(ENTITY_NEST).state)
self.assertEqual('21.0', self.hass.states.get(ENTITY_NEST).state)
thermostat.set_temperature(self.hass, None, ENTITY_NEST)
self.hass.pool.block_till_done()
self.assertEqual('21', self.hass.states.get(ENTITY_NEST).state)
self.assertEqual('21.0', self.hass.states.get(ENTITY_NEST).state)
def test_set_target_temp(self):
"""Test the setting of the target temperature."""
@@ -10,6 +10,7 @@ from homeassistant.const import (
STATE_OFF,
TEMP_CELSIUS,
)
from homeassistant.helpers.unit_system import METRIC_SYSTEM
from homeassistant.components import thermostat
from tests.common import get_test_home_assistant
@@ -75,7 +76,7 @@ class TestThermostatHeatControl(unittest.TestCase):
def setUp(self): # pylint: disable=invalid-name
"""Setup things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.hass.config.temperature_unit = TEMP_CELSIUS
self.hass.config.units = METRIC_SYSTEM
thermostat.setup(self.hass, {'thermostat': {
'platform': 'heat_control',
'name': 'test',
+10
View File
@@ -6,6 +6,13 @@ from unittest.mock import patch
from homeassistant.components import group
from homeassistant.exceptions import TemplateError
from homeassistant.helpers import template
from homeassistant.helpers.unit_system import UnitSystem
from homeassistant.const import (
LENGTH_METERS,
TEMP_CELSIUS,
MASS_GRAMS,
VOLUME_LITERS,
)
import homeassistant.util.dt as dt_util
from tests.common import get_test_home_assistant
@@ -17,6 +24,9 @@ class TestUtilTemplate(unittest.TestCase):
def setUp(self): # pylint: disable=invalid-name
"""Setup the tests."""
self.hass = get_test_home_assistant()
self.hass.config.units = UnitSystem('custom', TEMP_CELSIUS,
LENGTH_METERS, VOLUME_LITERS,
MASS_GRAMS)
def tearDown(self): # pylint: disable=invalid-name
"""Stop down stuff we started."""
+132
View File
@@ -0,0 +1,132 @@
"""Test the unit system helper."""
import unittest
from homeassistant.helpers.unit_system import (
UnitSystem,
METRIC_SYSTEM,
IMPERIAL_SYSTEM,
)
from homeassistant.const import (
LENGTH_METERS,
LENGTH_KILOMETERS,
MASS_GRAMS,
VOLUME_LITERS,
TEMP_CELSIUS,
LENGTH,
MASS,
TEMPERATURE,
VOLUME
)
SYSTEM_NAME = 'TEST'
INVALID_UNIT = 'INVALID'
class TestUnitSystem(unittest.TestCase):
"""Test the unit system helper."""
def test_invalid_units(self):
"""Test errors are raised when invalid units are passed in."""
with self.assertRaises(ValueError):
UnitSystem(SYSTEM_NAME, INVALID_UNIT, LENGTH_METERS, VOLUME_LITERS,
MASS_GRAMS)
with self.assertRaises(ValueError):
UnitSystem(SYSTEM_NAME, TEMP_CELSIUS, INVALID_UNIT, VOLUME_LITERS,
MASS_GRAMS)
with self.assertRaises(ValueError):
UnitSystem(SYSTEM_NAME, TEMP_CELSIUS, LENGTH_METERS, INVALID_UNIT,
MASS_GRAMS)
with self.assertRaises(ValueError):
UnitSystem(SYSTEM_NAME, TEMP_CELSIUS, LENGTH_METERS, VOLUME_LITERS,
INVALID_UNIT)
def test_invalid_value(self):
"""Test no conversion happens if value is non-numeric."""
with self.assertRaises(TypeError):
METRIC_SYSTEM.length('25a', LENGTH_KILOMETERS)
with self.assertRaises(TypeError):
METRIC_SYSTEM.temperature('50K', TEMP_CELSIUS)
def test_as_dict(self):
"""Test that the as_dict() method returns the expected dictionary."""
expected = {
LENGTH: LENGTH_KILOMETERS,
TEMPERATURE: TEMP_CELSIUS,
VOLUME: VOLUME_LITERS,
MASS: MASS_GRAMS
}
self.assertEqual(expected, METRIC_SYSTEM.as_dict())
def test_temperature_same_unit(self):
"""Test no conversion happens if to unit is same as from unit."""
self.assertEqual(
5,
METRIC_SYSTEM.temperature(5,
METRIC_SYSTEM.temperature_unit))
def test_temperature_unknown_unit(self):
"""Test no conversion happens if unknown unit."""
with self.assertRaises(ValueError):
METRIC_SYSTEM.temperature(5, 'K')
def test_temperature_to_metric(self):
"""Test temperature conversion to metric system."""
self.assertEqual(
25,
METRIC_SYSTEM.temperature(25, METRIC_SYSTEM.temperature_unit))
self.assertEqual(
26.7,
METRIC_SYSTEM.temperature(80, IMPERIAL_SYSTEM.temperature_unit))
def test_temperature_to_imperial(self):
"""Test temperature conversion to imperial system."""
self.assertEqual(
77,
IMPERIAL_SYSTEM.temperature(77, IMPERIAL_SYSTEM.temperature_unit))
self.assertEqual(
77,
IMPERIAL_SYSTEM.temperature(25, METRIC_SYSTEM.temperature_unit))
def test_length_unknown_unit(self):
"""Test length conversion with unknown from unit."""
with self.assertRaises(ValueError):
METRIC_SYSTEM.length(5, 'fr')
def test_length_to_metric(self):
"""Test length conversion to metric system."""
self.assertEqual(
100,
METRIC_SYSTEM.length(100, METRIC_SYSTEM.length_unit)
)
self.assertEqual(
8.04672,
METRIC_SYSTEM.length(5, IMPERIAL_SYSTEM.length_unit)
)
def test_length_to_imperial(self):
"""Test length conversion to imperial system."""
self.assertEqual(
100,
IMPERIAL_SYSTEM.length(100,
IMPERIAL_SYSTEM.length_unit)
)
self.assertEqual(
3.106855,
IMPERIAL_SYSTEM.length(5, METRIC_SYSTEM.length_unit)
)
def test_properties(self):
"""Test the unit properties are returned as expected."""
self.assertEqual(LENGTH_KILOMETERS, METRIC_SYSTEM.length_unit)
self.assertEqual(TEMP_CELSIUS, METRIC_SYSTEM.temperature_unit)
self.assertEqual(MASS_GRAMS, METRIC_SYSTEM.mass_unit)
self.assertEqual(VOLUME_LITERS, METRIC_SYSTEM.volume_unit)
def test_is_metric(self):
"""Test the is metric flag."""
self.assertTrue(METRIC_SYSTEM.is_metric)
self.assertFalse(IMPERIAL_SYSTEM.is_metric)
+31 -9
View File
@@ -11,9 +11,9 @@ from voluptuous import MultipleInvalid
from homeassistant.core import DOMAIN, HomeAssistantError, Config
import homeassistant.config as config_util
from homeassistant.const import (
CONF_LATITUDE, CONF_LONGITUDE, CONF_TEMPERATURE_UNIT, CONF_NAME,
CONF_LATITUDE, CONF_LONGITUDE, CONF_UNIT_SYSTEM, CONF_NAME,
CONF_TIME_ZONE, CONF_ELEVATION, CONF_CUSTOMIZE, __version__,
TEMP_FAHRENHEIT)
CONF_UNIT_SYSTEM_METRIC, CONF_UNIT_SYSTEM_IMPERIAL, CONF_TEMPERATURE_UNIT)
from homeassistant.util import location as location_util, dt as dt_util
from homeassistant.helpers.entity import Entity
@@ -145,7 +145,7 @@ class TestConfig(unittest.TestCase):
CONF_LATITUDE: 32.8594,
CONF_LONGITUDE: -117.2073,
CONF_ELEVATION: 101,
CONF_TEMPERATURE_UNIT: 'F',
CONF_UNIT_SYSTEM: CONF_UNIT_SYSTEM_METRIC,
CONF_NAME: 'Home',
CONF_TIME_ZONE: 'America/Los_Angeles'
}
@@ -167,7 +167,7 @@ class TestConfig(unittest.TestCase):
def test_core_config_schema(self):
for value in (
{'temperature_unit': 'K'},
{CONF_UNIT_SYSTEM: 'K'},
{'time_zone': 'non-exist'},
{'latitude': '91'},
{'longitude': -181},
@@ -182,7 +182,7 @@ class TestConfig(unittest.TestCase):
'name': 'Test name',
'latitude': '-23.45',
'longitude': '123.45',
'temperature_unit': 'c',
CONF_UNIT_SYSTEM: CONF_UNIT_SYSTEM_METRIC,
'customize': {
'sensor.temperature': {
'hidden': True,
@@ -264,7 +264,7 @@ class TestConfig(unittest.TestCase):
'longitude': 50,
'elevation': 25,
'name': 'Huis',
'temperature_unit': 'F',
CONF_UNIT_SYSTEM: CONF_UNIT_SYSTEM_IMPERIAL,
'time_zone': 'America/New_York',
})
@@ -272,7 +272,28 @@ class TestConfig(unittest.TestCase):
assert config.longitude == 50
assert config.elevation == 25
assert config.location_name == 'Huis'
assert config.temperature_unit == TEMP_FAHRENHEIT
assert config.units.name == CONF_UNIT_SYSTEM_IMPERIAL
assert config.time_zone.zone == 'America/New_York'
def test_loading_configuration_temperature_unit(self):
"""Test backward compatibility when loading core config."""
config = Config()
hass = mock.Mock(config=config)
config_util.process_ha_core_config(hass, {
'latitude': 60,
'longitude': 50,
'elevation': 25,
'name': 'Huis',
CONF_TEMPERATURE_UNIT: 'C',
'time_zone': 'America/New_York',
})
assert config.latitude == 60
assert config.longitude == 50
assert config.elevation == 25
assert config.location_name == 'Huis'
assert config.units.name == CONF_UNIT_SYSTEM_METRIC
assert config.time_zone.zone == 'America/New_York'
@mock.patch('homeassistant.util.location.detect_location_info',
@@ -292,7 +313,8 @@ class TestConfig(unittest.TestCase):
assert config.longitude == -117.2073
assert config.elevation == 101
assert config.location_name == 'San Diego'
assert config.temperature_unit == TEMP_FAHRENHEIT
assert config.units.name == CONF_UNIT_SYSTEM_METRIC
assert config.units.is_metric
assert config.time_zone.zone == 'America/Los_Angeles'
@mock.patch('homeassistant.util.location.detect_location_info',
@@ -311,5 +333,5 @@ class TestConfig(unittest.TestCase):
assert config.longitude == blankConfig.longitude
assert config.elevation == blankConfig.elevation
assert config.location_name == blankConfig.location_name
assert config.temperature_unit == blankConfig.temperature_unit
assert config.units == blankConfig.units
assert config.time_zone == blankConfig.time_zone
+3 -47
View File
@@ -15,10 +15,10 @@ import homeassistant.core as ha
from homeassistant.exceptions import (
HomeAssistantError, InvalidEntityFormatError)
import homeassistant.util.dt as dt_util
from homeassistant.helpers.unit_system import (METRIC_SYSTEM)
from homeassistant.const import (
__version__, EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP,
EVENT_STATE_CHANGED, ATTR_FRIENDLY_NAME, TEMP_CELSIUS,
TEMP_FAHRENHEIT)
EVENT_STATE_CHANGED, ATTR_FRIENDLY_NAME, CONF_UNIT_SYSTEM)
from tests.common import get_test_home_assistant
@@ -465,56 +465,12 @@ class TestConfig(unittest.TestCase):
os.path.join(data_dir, ".homeassistant", "dir", "test.conf"),
self.config.path("dir", "test.conf"))
def test_temperature_not_convert_if_no_preference(self):
"""No unit conversion to happen if no preference."""
self.assertEqual(
(25, TEMP_CELSIUS),
self.config.temperature(25, TEMP_CELSIUS))
self.assertEqual(
(80, TEMP_FAHRENHEIT),
self.config.temperature(80, TEMP_FAHRENHEIT))
def test_temperature_not_convert_if_invalid_value(self):
"""No unit conversion to happen if no preference."""
self.config.temperature_unit = TEMP_FAHRENHEIT
self.assertEqual(
('25a', TEMP_CELSIUS),
self.config.temperature('25a', TEMP_CELSIUS))
def test_temperature_not_convert_if_invalid_unit(self):
"""No unit conversion to happen if no preference."""
self.assertEqual(
(25, 'Invalid unit'),
self.config.temperature(25, 'Invalid unit'))
def test_temperature_to_convert_to_celsius(self):
"""Test temperature conversion to celsius."""
self.config.temperature_unit = TEMP_CELSIUS
self.assertEqual(
(25, TEMP_CELSIUS),
self.config.temperature(25, TEMP_CELSIUS))
self.assertEqual(
(26.7, TEMP_CELSIUS),
self.config.temperature(80, TEMP_FAHRENHEIT))
def test_temperature_to_convert_to_fahrenheit(self):
"""Test temperature conversion to fahrenheit."""
self.config.temperature_unit = TEMP_FAHRENHEIT
self.assertEqual(
(77, TEMP_FAHRENHEIT),
self.config.temperature(25, TEMP_CELSIUS))
self.assertEqual(
(80, TEMP_FAHRENHEIT),
self.config.temperature(80, TEMP_FAHRENHEIT))
def test_as_dict(self):
"""Test as dict."""
expected = {
'latitude': None,
'longitude': None,
'temperature_unit': None,
CONF_UNIT_SYSTEM: METRIC_SYSTEM.as_dict(),
'location_name': None,
'time_zone': 'UTC',
'components': [],
+52 -29
View File
@@ -2,14 +2,11 @@
import unittest
import homeassistant.util.distance as distance_util
KILOMETERS = distance_util.KILOMETERS_SYMBOL
METERS = distance_util.METERS_SYMBOL
FEET = distance_util.FEET_SYMBOL
MILES = distance_util.MILES_SYMBOL
from homeassistant.const import (LENGTH_KILOMETERS, LENGTH_METERS, LENGTH_FEET,
LENGTH_MILES)
INVALID_SYMBOL = 'bob'
VALID_SYMBOL = KILOMETERS
VALID_SYMBOL = LENGTH_KILOMETERS
class TestDistanceUtil(unittest.TestCase):
@@ -17,52 +14,78 @@ class TestDistanceUtil(unittest.TestCase):
def test_convert_same_unit(self):
"""Test conversion from any unit to same unit."""
self.assertEqual(5, distance_util.convert(5, KILOMETERS, KILOMETERS))
self.assertEqual(2, distance_util.convert(2, METERS, METERS))
self.assertEqual(10, distance_util.convert(10, MILES, MILES))
self.assertEqual(9, distance_util.convert(9, FEET, FEET))
self.assertEqual(5,
distance_util.convert(5, LENGTH_KILOMETERS,
LENGTH_KILOMETERS))
self.assertEqual(2,
distance_util.convert(2, LENGTH_METERS,
LENGTH_METERS))
self.assertEqual(10,
distance_util.convert(10, LENGTH_MILES, LENGTH_MILES))
self.assertEqual(9,
distance_util.convert(9, LENGTH_FEET, LENGTH_FEET))
def test_convert_invalid_unit(self):
"""Test exception is thrown for invalid units."""
with self.assertRaises(ValueError):
distance_util.convert(5, INVALID_SYMBOL, VALID_SYMBOL)
distance_util.convert(5, INVALID_SYMBOL,
VALID_SYMBOL)
with self.assertRaises(ValueError):
distance_util.convert(5, VALID_SYMBOL, INVALID_SYMBOL)
distance_util.convert(5, VALID_SYMBOL,
INVALID_SYMBOL)
def test_convert_nonnumeric_value(self):
"""Test exception is thrown for nonnumeric type."""
with self.assertRaises(TypeError):
distance_util.convert('a', KILOMETERS, METERS)
distance_util.convert('a', LENGTH_KILOMETERS, LENGTH_METERS)
def test_convert_from_miles(self):
"""Test conversion from miles to other units."""
miles = 5
self.assertEqual(distance_util.convert(miles, MILES, KILOMETERS),
8.04672)
self.assertEqual(distance_util.convert(miles, MILES, METERS), 8046.72)
self.assertEqual(distance_util.convert(miles, MILES, FEET),
26400.0008448)
self.assertEqual(
distance_util.convert(miles, LENGTH_MILES, LENGTH_KILOMETERS),
8.04672)
self.assertEqual(
distance_util.convert(miles, LENGTH_MILES, LENGTH_METERS),
8046.72)
self.assertEqual(
distance_util.convert(miles, LENGTH_MILES, LENGTH_FEET),
26400.0008448)
def test_convert_from_feet(self):
"""Test conversion from feet to other units."""
feet = 5000
self.assertEqual(distance_util.convert(feet, FEET, KILOMETERS), 1.524)
self.assertEqual(distance_util.convert(feet, FEET, METERS), 1524)
self.assertEqual(distance_util.convert(feet, FEET, MILES),
0.9469694040000001)
self.assertEqual(
distance_util.convert(feet, LENGTH_FEET, LENGTH_KILOMETERS),
1.524)
self.assertEqual(
distance_util.convert(feet, LENGTH_FEET, LENGTH_METERS),
1524)
self.assertEqual(
distance_util.convert(feet, LENGTH_FEET, LENGTH_MILES),
0.9469694040000001)
def test_convert_from_kilometers(self):
"""Test conversion from kilometers to other units."""
km = 5
self.assertEqual(distance_util.convert(km, KILOMETERS, FEET), 16404.2)
self.assertEqual(distance_util.convert(km, KILOMETERS, METERS), 5000)
self.assertEqual(distance_util.convert(km, KILOMETERS, MILES),
3.106855)
self.assertEqual(
distance_util.convert(km, LENGTH_KILOMETERS, LENGTH_FEET),
16404.2)
self.assertEqual(
distance_util.convert(km, LENGTH_KILOMETERS, LENGTH_METERS),
5000)
self.assertEqual(
distance_util.convert(km, LENGTH_KILOMETERS, LENGTH_MILES),
3.106855)
def test_convert_from_meters(self):
"""Test conversion from meters to other units."""
m = 5000
self.assertEqual(distance_util.convert(m, METERS, FEET), 16404.2)
self.assertEqual(distance_util.convert(m, METERS, KILOMETERS), 5)
self.assertEqual(distance_util.convert(m, METERS, MILES), 3.106855)
self.assertEqual(distance_util.convert(m, LENGTH_METERS, LENGTH_FEET),
16404.2)
self.assertEqual(
distance_util.convert(m, LENGTH_METERS, LENGTH_KILOMETERS),
5)
self.assertEqual(distance_util.convert(m, LENGTH_METERS, LENGTH_MILES),
3.106855)
+2 -2
View File
@@ -79,7 +79,7 @@ class TestLocationUtil(TestCase):
assert info.time_zone == 'America/Los_Angeles'
assert info.latitude == 32.8594
assert info.longitude == -117.2073
assert info.use_fahrenheit
assert not info.use_metric
@requests_mock.Mocker()
@patch('homeassistant.util.location._get_freegeoip', return_value=None)
@@ -101,7 +101,7 @@ class TestLocationUtil(TestCase):
assert info.time_zone == 'America/Los_Angeles'
assert info.latitude == 32.8594
assert info.longitude == -117.2073
assert info.use_fahrenheit
assert not info.use_metric
@patch('homeassistant.util.location.elevation', return_value=0)
@patch('homeassistant.util.location._get_freegeoip', return_value=None)