コード例 #1
0
 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
0
 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
0
def test_accumulated_precipitation_to_metric():
    """Test accumulated_precipitation conversion to metric system."""
    assert (METRIC_SYSTEM.accumulated_precipitation(
        25, METRIC_SYSTEM.accumulated_precipitation_unit) == 25)
    assert METRIC_SYSTEM.accumulated_precipitation(
        10, IMPERIAL_SYSTEM.accumulated_precipitation_unit) == pytest.approx(
            254, abs=1e-4)
コード例 #4
0
 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)
コード例 #5
0
def test_temperature_to_metric():
    """Test temperature conversion to metric system."""
    assert METRIC_SYSTEM.temperature(25, METRIC_SYSTEM.temperature_unit) == 25
    assert (
        round(METRIC_SYSTEM.temperature(80, IMPERIAL_SYSTEM.temperature_unit), 1)
        == 26.7
    )
コード例 #6
0
 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)
コード例 #7
0
 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))
コード例 #8
0
 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)
コード例 #9
0
 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)
     )
コード例 #10
0
def test_config_as_dict():
    """Test as dict."""
    config = ha.Config(None)
    config.config_dir = "/test/ha-config"
    config.hass = MagicMock()
    type(config.hass.state).value = PropertyMock(return_value="RUNNING")
    expected = {
        "latitude": 0,
        "longitude": 0,
        "elevation": 0,
        CONF_UNIT_SYSTEM: METRIC_SYSTEM.as_dict(),
        "location_name": "Home",
        "time_zone": "UTC",
        "components": set(),
        "config_dir": "/test/ha-config",
        "whitelist_external_dirs": set(),
        "allowlist_external_dirs": set(),
        "allowlist_external_urls": set(),
        "version": __version__,
        "config_source": "default",
        "safe_mode": False,
        "state": "RUNNING",
        "external_url": None,
        "internal_url": None,
    }

    assert expected == config.as_dict()
コード例 #11
0
 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)
コード例 #12
0
def test_invalid_value():
    """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)
コード例 #13
0
    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())
コード例 #14
0
    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
        }

        assert expected == METRIC_SYSTEM.as_dict()
コード例 #15
0
def test_as_dict():
    """Test that the as_dict() method returns the expected dictionary."""
    expected = {
        LENGTH: LENGTH_KILOMETERS,
        WIND_SPEED: SPEED_METERS_PER_SECOND,
        TEMPERATURE: TEMP_CELSIUS,
        VOLUME: VOLUME_LITERS,
        MASS: MASS_GRAMS,
        PRESSURE: PRESSURE_PA,
        ACCUMULATED_PRECIPITATION: LENGTH_MILLIMETERS,
    }

    assert expected == METRIC_SYSTEM.as_dict()
コード例 #16
0
ファイル: test_core.py プロジェクト: jawilson/home-assistant
    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())
コード例 #17
0
ファイル: test_core.py プロジェクト: syphernl/home-assistant
    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())
コード例 #18
0
ファイル: __init__.py プロジェクト: jbouwh/core
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
    """Set up the GeoNet NZ Quakes component as config entry."""
    hass.data.setdefault(DOMAIN, {})
    feeds = hass.data[DOMAIN].setdefault(FEED, {})

    radius = config_entry.data[CONF_RADIUS]
    if hass.config.units.name == CONF_UNIT_SYSTEM_IMPERIAL:
        radius = METRIC_SYSTEM.length(radius, LENGTH_MILES)
    # Create feed entity manager for all platforms.
    manager = GeonetnzQuakesFeedEntityManager(hass, config_entry, radius)
    feeds[config_entry.entry_id] = manager
    _LOGGER.debug("Feed entity manager added for %s", config_entry.entry_id)
    await manager.async_init()
    return True
コード例 #19
0
    def set_temperature(self, **kwargs):
        mode = kwargs.get(ATTR_HVAC_MODE)
        if mode != None:
            self.set_hvac_mode(mode)

        temp = kwargs.get(ATTR_TEMPERATURE)
        if self._device.units.temperature_unit != TEMP_FAHRENHEIT:
            if self._device.force_fahrenheit:
                # undo HA's conversion
                temp = METRIC_SYSTEM.temperature(temp, TEMP_FAHRENHEIT)
            else:
                temp = IMPERIAL_SYSTEM.temperature(
                    temp, self._device.units.temperature_unit)
        self._device.dps(DPS_TARGET, int(temp + 0.5))
コード例 #20
0
ファイル: __init__.py プロジェクト: zt17521/home-assistant
async def async_setup_entry(hass, config_entry):
    """Set up the GeoNet NZ Volcano component as config entry."""
    hass.data.setdefault(DOMAIN, {})
    hass.data[DOMAIN].setdefault(FEED, {})

    radius = config_entry.data[CONF_RADIUS]
    unit_system = config_entry.data[CONF_UNIT_SYSTEM]
    if unit_system == CONF_UNIT_SYSTEM_IMPERIAL:
        radius = METRIC_SYSTEM.length(radius, LENGTH_MILES)
    # Create feed entity manager for all platforms.
    manager = GeonetnzVolcanoFeedEntityManager(hass, config_entry, radius, unit_system)
    hass.data[DOMAIN][FEED][config_entry.entry_id] = manager
    _LOGGER.debug("Feed entity manager added for %s", config_entry.entry_id)
    await manager.async_init()
    return True
コード例 #21
0
    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()
コード例 #22
0
    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()
コード例 #23
0
ファイル: test_core.py プロジェクト: bhchew/hass
    def test_as_dict(self):
        """Test as dict."""
        self.config.config_dir = "/test/ha-config"
        expected = {
            "latitude": 0,
            "longitude": 0,
            "elevation": 0,
            CONF_UNIT_SYSTEM: METRIC_SYSTEM.as_dict(),
            "location_name": "Home",
            "time_zone": "UTC",
            "components": set(),
            "config_dir": "/test/ha-config",
            "whitelist_external_dirs": set(),
            "version": __version__,
            "config_source": "default",
        }

        assert expected == self.config.as_dict()
コード例 #24
0
def test_pressure_same_unit():
    """Test no conversion happens if to unit is same as from unit."""
    assert METRIC_SYSTEM.pressure(5, METRIC_SYSTEM.pressure_unit) == 5
コード例 #25
0
def test_length_to_metric():
    """Test length conversion to metric system."""
    assert METRIC_SYSTEM.length(100, METRIC_SYSTEM.length_unit) == 100
    assert METRIC_SYSTEM.length(5, IMPERIAL_SYSTEM.length_unit) == 8.04672
コード例 #26
0
def test_length_unknown_unit():
    """Test length conversion with unknown from unit."""
    with pytest.raises(ValueError):
        METRIC_SYSTEM.length(5, "fr")
コード例 #27
0
 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))
コード例 #28
0
 def test_length_to_metric(self):
     """Test length conversion to metric system."""
     assert 100 == \
         METRIC_SYSTEM.length(100, METRIC_SYSTEM.length_unit)
     assert 8.04672 == \
         METRIC_SYSTEM.length(5, IMPERIAL_SYSTEM.length_unit)
コード例 #29
0
 def test_length_unknown_unit(self):
     """Test length conversion with unknown from unit."""
     with self.assertRaises(ValueError):
         METRIC_SYSTEM.length(5, 'fr')
コード例 #30
0
def test_accumulated_precipitation_same_unit():
    """Test no conversion happens if to unit is same as from unit."""
    assert (METRIC_SYSTEM.accumulated_precipitation(
        5, METRIC_SYSTEM.accumulated_precipitation_unit) == 5)
コード例 #31
0
 def test_pressure_unknown_unit(self):
     """Test no conversion happens if unknown unit."""
     with pytest.raises(ValueError):
         METRIC_SYSTEM.pressure(5, 'K')
コード例 #32
0
 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)
コード例 #33
0
 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)
コード例 #34
0
def test_accumulated_precipitation_unknown_unit():
    """Test no conversion happens if unknown unit."""
    with pytest.raises(ValueError):
        METRIC_SYSTEM.accumulated_precipitation(5, "K")
コード例 #35
0
def test_pressure_unknown_unit():
    """Test no conversion happens if unknown unit."""
    with pytest.raises(ValueError):
        METRIC_SYSTEM.pressure(5, "K")
コード例 #36
0
 def test_length_unknown_unit(self):
     """Test length conversion with unknown from unit."""
     with self.assertRaises(ValueError):
         METRIC_SYSTEM.length(5, 'fr')
コード例 #37
0
def test_pressure_to_metric():
    """Test pressure conversion to metric system."""
    assert METRIC_SYSTEM.pressure(25, METRIC_SYSTEM.pressure_unit) == 25
    assert METRIC_SYSTEM.pressure(
        14.7, IMPERIAL_SYSTEM.pressure_unit) == pytest.approx(101352.932,
                                                              abs=1e-1)
コード例 #38
0
 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)
コード例 #39
0
 def test_temperature_unknown_unit(self):
     """Test no conversion happens if unknown unit."""
     with self.assertRaises(ValueError):
         METRIC_SYSTEM.temperature(5, 'K')
コード例 #40
0
def test_temperature_unknown_unit():
    """Test no conversion happens if unknown unit."""
    with pytest.raises(ValueError):
        METRIC_SYSTEM.temperature(5, "abc")
コード例 #41
0
 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))
コード例 #42
0
 def test_temperature_same_unit(self):
     """Test no conversion happens if to unit is same as from unit."""
     assert 5 == \
         METRIC_SYSTEM.temperature(5,
                                   METRIC_SYSTEM.temperature_unit)
コード例 #43
0
 def test_temperature_unknown_unit(self):
     """Test no conversion happens if unknown unit."""
     with self.assertRaises(ValueError):
         METRIC_SYSTEM.temperature(5, 'K')
コード例 #44
0
 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)
コード例 #45
0
ファイル: smart_home.py プロジェクト: oliverbl4/Anassistant
 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)
コード例 #46
0
 def test_length_to_metric(self):
     """Test length conversion to metric system."""
     assert 100 == \
         METRIC_SYSTEM.length(100, METRIC_SYSTEM.length_unit)
     assert 8.04672 == \
         METRIC_SYSTEM.length(5, IMPERIAL_SYSTEM.length_unit)