本文整理匯總了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)