Rename IMPERIAL_SYSTEM to US_CUSTOMARY_SYSTEM (#80253)

* Rename IMPERIAL_SYSTEM

* Deprecate is_metric property and adjust tests

* Adjust unit_system config validation

* Add yaml tests

* Add tests for private name

* Fix incorrect rebase

* Adjust docstring

* Add store migration

* Update unit_system.py

* Minimise test tweaks

* Fix tests

* Add conversion to migration

* Rename new key and adjust tests

* Adjust websocket_detect_config

* Move original_unit_system tracking to subclass
This commit is contained in:
epenet 2022-10-19 13:31:08 +02:00 committed by GitHub
parent f4951a4f31
commit 67d1dde69f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 125 additions and 22 deletions

View file

@ -27,11 +27,17 @@ from homeassistant.const import (
CONF_UNIT_SYSTEM_METRIC,
__version__,
)
from homeassistant.core import ConfigSource, HomeAssistantError
from homeassistant.core import ConfigSource, HomeAssistant, HomeAssistantError
from homeassistant.helpers import config_validation as cv
import homeassistant.helpers.check_config as check_config
from homeassistant.helpers.entity import Entity
from homeassistant.loader import async_get_integration
from homeassistant.util.unit_system import (
_CONF_UNIT_SYSTEM_US_CUSTOMARY,
METRIC_SYSTEM,
US_CUSTOMARY_SYSTEM,
UnitSystem,
)
from homeassistant.util.yaml import SECRET_YAML
from tests.common import get_test_config_dir, patch_yaml_files
@ -439,7 +445,7 @@ async def test_loading_configuration_from_storage_with_yaml_only(hass, hass_stor
assert hass.config.config_source is ConfigSource.STORAGE
async def test_updating_configuration(hass, hass_storage):
async def test_igration_and_updating_configuration(hass, hass_storage):
"""Test updating configuration stores the new configuration."""
core_data = {
"data": {
@ -448,7 +454,7 @@ async def test_updating_configuration(hass, hass_storage):
"location_name": "Home",
"longitude": 13,
"time_zone": "Europe/Copenhagen",
"unit_system": "metric",
"unit_system": "imperial",
"external_url": "https://www.example.com",
"internal_url": "http://example.local",
"currency": "BTC",
@ -463,10 +469,14 @@ async def test_updating_configuration(hass, hass_storage):
)
await hass.config.async_update(latitude=50, currency="USD")
new_core_data = copy.deepcopy(core_data)
new_core_data["data"]["latitude"] = 50
new_core_data["data"]["currency"] = "USD"
assert hass_storage["core.config"] == new_core_data
expected_new_core_data = copy.deepcopy(core_data)
# From async_update above
expected_new_core_data["data"]["latitude"] = 50
expected_new_core_data["data"]["currency"] = "USD"
# 1.1 -> 1.2 store migration with migrated unit system
expected_new_core_data["data"]["unit_system_v2"] = "us_customary"
expected_new_core_data["minor_version"] = 2
assert hass_storage["core.config"] == expected_new_core_data
assert hass.config.latitude == 50
assert hass.config.currency == "USD"
@ -593,6 +603,35 @@ async def test_loading_configuration_from_packages(hass):
)
@pytest.mark.parametrize(
"unit_system_name, expected_unit_system",
[
(CONF_UNIT_SYSTEM_METRIC, METRIC_SYSTEM),
(CONF_UNIT_SYSTEM_IMPERIAL, US_CUSTOMARY_SYSTEM),
(_CONF_UNIT_SYSTEM_US_CUSTOMARY, US_CUSTOMARY_SYSTEM),
],
)
async def test_loading_configuration_unit_system(
hass: HomeAssistant, unit_system_name: str, expected_unit_system: UnitSystem
) -> None:
"""Test backward compatibility when loading core config."""
await config_util.async_process_ha_core_config(
hass,
{
"latitude": 60,
"longitude": 50,
"elevation": 25,
"name": "Huis",
"unit_system": unit_system_name,
"time_zone": "America/New_York",
"external_url": "https://www.example.com",
"internal_url": "http://example.local",
},
)
assert hass.config.units is expected_unit_system
@patch("homeassistant.helpers.check_config.async_check_ha_config_file")
async def test_check_ha_config_file_correct(mock_check, hass):
"""Check that restart propagates to stop."""