當前位置: 首頁>>代碼示例>>Python>>正文


Python unit_system.METRIC_SYSTEM類代碼示例

本文整理匯總了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)
開發者ID:fbradyirl,項目名稱:home-assistant,代碼行數:7,代碼來源:test_unit_system.py

示例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)
開發者ID:fbradyirl,項目名稱:home-assistant,代碼行數:7,代碼來源:test_unit_system.py

示例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))
開發者ID:Bart274,項目名稱:home-assistant,代碼行數:8,代碼來源:test_unit_system.py

示例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)
     )
開發者ID:Bart274,項目名稱:home-assistant,代碼行數:10,代碼來源:test_unit_system.py

示例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)
開發者ID:fbradyirl,項目名稱:home-assistant,代碼行數:10,代碼來源:test_unit_system.py

示例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())
開發者ID:Bart274,項目名稱:home-assistant,代碼行數:10,代碼來源:test_unit_system.py

示例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())
開發者ID:jawilson,項目名稱:home-assistant,代碼行數:13,代碼來源:test_core.py

示例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()
開發者ID:chilicheech,項目名稱:home-assistant,代碼行數:17,代碼來源:test_core.py

示例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')
開發者ID:Bart274,項目名稱:home-assistant,代碼行數:4,代碼來源:test_unit_system.py

示例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')
開發者ID:Bart274,項目名稱:home-assistant,代碼行數:4,代碼來源:test_unit_system.py

示例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))
開發者ID:Bart274,項目名稱:home-assistant,代碼行數:6,代碼來源:test_unit_system.py

示例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)
開發者ID:Bart274,項目名稱:home-assistant,代碼行數:6,代碼來源:test_unit_system.py

示例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)
開發者ID:JiShangShiDai,項目名稱:home-assistant,代碼行數:5,代碼來源:smart_home.py

示例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')
開發者ID:fbradyirl,項目名稱:home-assistant,代碼行數:4,代碼來源:test_unit_system.py

示例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)
開發者ID:fbradyirl,項目名稱:home-assistant,代碼行數:4,代碼來源:test_unit_system.py


注:本文中的homeassistant.util.unit_system.METRIC_SYSTEM類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。