本文整理汇总了Python中homeassistant.util.unit_system.METRIC_SYSTEM.temperature方法的典型用法代码示例。如果您正苦于以下问题:Python METRIC_SYSTEM.temperature方法的具体用法?Python METRIC_SYSTEM.temperature怎么用?Python METRIC_SYSTEM.temperature使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类homeassistant.util.unit_system.METRIC_SYSTEM
的用法示例。
在下文中一共展示了METRIC_SYSTEM.temperature方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_temperature_to_metric
# 需要导入模块: from homeassistant.util.unit_system import METRIC_SYSTEM [as 别名]
# 或者: from homeassistant.util.unit_system.METRIC_SYSTEM import temperature [as 别名]
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_temperature_to_metric
# 需要导入模块: from homeassistant.util.unit_system import METRIC_SYSTEM [as 别名]
# 或者: from homeassistant.util.unit_system.METRIC_SYSTEM import temperature [as 别名]
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))
示例3: test_invalid_value
# 需要导入模块: from homeassistant.util.unit_system import METRIC_SYSTEM [as 别名]
# 或者: from homeassistant.util.unit_system.METRIC_SYSTEM import temperature [as 别名]
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)
示例4: test_temperature_unknown_unit
# 需要导入模块: from homeassistant.util.unit_system import METRIC_SYSTEM [as 别名]
# 或者: from homeassistant.util.unit_system.METRIC_SYSTEM import temperature [as 别名]
def test_temperature_unknown_unit(self):
"""Test no conversion happens if unknown unit."""
with self.assertRaises(ValueError):
METRIC_SYSTEM.temperature(5, 'K')
示例5: test_temperature_same_unit
# 需要导入模块: from homeassistant.util.unit_system import METRIC_SYSTEM [as 别名]
# 或者: from homeassistant.util.unit_system.METRIC_SYSTEM import temperature [as 别名]
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))
示例6: test_invalid_value
# 需要导入模块: from homeassistant.util.unit_system import METRIC_SYSTEM [as 别名]
# 或者: from homeassistant.util.unit_system.METRIC_SYSTEM import temperature [as 别名]
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)
示例7: celsius
# 需要导入模块: from homeassistant.util.unit_system import METRIC_SYSTEM [as 别名]
# 或者: from homeassistant.util.unit_system.METRIC_SYSTEM import temperature [as 别名]
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)