本文整理汇总了Python中homeassistant.util.unit_system.METRIC_SYSTEM类的典型用法代码示例。如果您正苦于以下问题:Python METRIC_SYSTEM类的具体用法?Python METRIC_SYSTEM怎么用?Python METRIC_SYSTEM使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了METRIC_SYSTEM类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_temperature_to_metric
def test_temperature_to_metric(self):
"""Test temperature conversion to metric system."""
assert 25 == \
METRIC_SYSTEM.temperature(25, METRIC_SYSTEM.temperature_unit)
assert 26.7 == \
round(METRIC_SYSTEM.temperature(
80, IMPERIAL_SYSTEM.temperature_unit), 1)
示例2: test_pressure_to_metric
def test_pressure_to_metric(self):
"""Test pressure conversion to metric system."""
assert 25 == \
METRIC_SYSTEM.pressure(25, METRIC_SYSTEM.pressure_unit)
self.assertAlmostEqual(
METRIC_SYSTEM.pressure(14.7, IMPERIAL_SYSTEM.pressure_unit),
101352.932, places=1)
示例3: test_temperature_to_metric
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))
示例4: test_length_to_metric
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)
)
示例5: test_invalid_value
def test_invalid_value(self):
"""Test no conversion happens if value is non-numeric."""
with pytest.raises(TypeError):
METRIC_SYSTEM.length('25a', LENGTH_KILOMETERS)
with pytest.raises(TypeError):
METRIC_SYSTEM.temperature('50K', TEMP_CELSIUS)
with pytest.raises(TypeError):
METRIC_SYSTEM.volume('50L', VOLUME_LITERS)
with pytest.raises(TypeError):
METRIC_SYSTEM.pressure('50Pa', PRESSURE_PA)
示例6: test_as_dict
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())
示例7: test_as_dict
def test_as_dict(self):
"""Test as dict."""
expected = {
'latitude': None,
'longitude': None,
CONF_UNIT_SYSTEM: METRIC_SYSTEM.as_dict(),
'location_name': None,
'time_zone': 'UTC',
'components': [],
'version': __version__,
}
self.assertEqual(expected, self.config.as_dict())
示例8: test_as_dict
def test_as_dict(self):
"""Test as dict."""
self.config.config_dir = '/tmp/ha-config'
expected = {
'latitude': None,
'longitude': None,
'elevation': None,
CONF_UNIT_SYSTEM: METRIC_SYSTEM.as_dict(),
'location_name': None,
'time_zone': 'UTC',
'components': set(),
'config_dir': '/tmp/ha-config',
'whitelist_external_dirs': set(),
'version': __version__,
}
assert expected == self.config.as_dict()
示例9: test_length_unknown_unit
def test_length_unknown_unit(self):
"""Test length conversion with unknown from unit."""
with self.assertRaises(ValueError):
METRIC_SYSTEM.length(5, 'fr')
示例10: test_temperature_unknown_unit
def test_temperature_unknown_unit(self):
"""Test no conversion happens if unknown unit."""
with self.assertRaises(ValueError):
METRIC_SYSTEM.temperature(5, 'K')
示例11: test_temperature_same_unit
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))
示例12: test_invalid_value
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)
示例13: celsius
def celsius(deg: Optional[float]) -> Optional[float]:
"""Convert a float to Celsius and rounds to one decimal place."""
if deg is None:
return None
return round(METRIC_SYSTEM.temperature(deg, units.temperature_unit), 1)
示例14: test_pressure_unknown_unit
def test_pressure_unknown_unit(self):
"""Test no conversion happens if unknown unit."""
with pytest.raises(ValueError):
METRIC_SYSTEM.pressure(5, 'K')
示例15: test_pressure_same_unit
def test_pressure_same_unit(self):
"""Test no conversion happens if to unit is same as from unit."""
assert 5 == \
METRIC_SYSTEM.pressure(5, METRIC_SYSTEM.pressure_unit)