mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Reverse component path (#104087)
* Reverse component path * Update translations helper * Fix * Revert incorrect change of PLATFORM_FORMAT * Fix use of PLATFORM_FORMAT in tts * Fix ios
This commit is contained in:
parent
a9381d2590
commit
84e74e4c74
@ -287,7 +287,7 @@ class DeviceTrackerPlatform:
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up a legacy platform."""
|
"""Set up a legacy platform."""
|
||||||
assert self.type == PLATFORM_TYPE_LEGACY
|
assert self.type == PLATFORM_TYPE_LEGACY
|
||||||
full_name = f"{DOMAIN}.{self.name}"
|
full_name = f"{self.name}.{DOMAIN}"
|
||||||
LOGGER.info("Setting up %s", full_name)
|
LOGGER.info("Setting up %s", full_name)
|
||||||
with async_start_setup(hass, [full_name]):
|
with async_start_setup(hass, [full_name]):
|
||||||
try:
|
try:
|
||||||
|
@ -52,9 +52,9 @@ def get_service(
|
|||||||
discovery_info: DiscoveryInfoType | None = None,
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
) -> iOSNotificationService | None:
|
) -> iOSNotificationService | None:
|
||||||
"""Get the iOS notification service."""
|
"""Get the iOS notification service."""
|
||||||
if "notify.ios" not in hass.config.components:
|
if "ios.notify" not in hass.config.components:
|
||||||
# Need this to enable requirements checking in the app.
|
# Need this to enable requirements checking in the app.
|
||||||
hass.config.components.add("notify.ios")
|
hass.config.components.add("ios.notify")
|
||||||
|
|
||||||
if not ios.devices_with_push(hass):
|
if not ios.devices_with_push(hass):
|
||||||
return None
|
return None
|
||||||
|
@ -126,7 +126,7 @@ def async_setup_legacy(
|
|||||||
hass.data[NOTIFY_SERVICES].setdefault(integration_name, []).append(
|
hass.data[NOTIFY_SERVICES].setdefault(integration_name, []).append(
|
||||||
notify_service
|
notify_service
|
||||||
)
|
)
|
||||||
hass.config.components.add(f"{DOMAIN}.{integration_name}")
|
hass.config.components.add(f"{integration_name}.{DOMAIN}")
|
||||||
|
|
||||||
async def async_platform_discovered(
|
async def async_platform_discovered(
|
||||||
platform: str, info: DiscoveryInfoType | None
|
platform: str, info: DiscoveryInfoType | None
|
||||||
|
@ -545,7 +545,7 @@ class SpeechManager:
|
|||||||
self.providers[engine] = provider
|
self.providers[engine] = provider
|
||||||
|
|
||||||
self.hass.config.components.add(
|
self.hass.config.components.add(
|
||||||
PLATFORM_FORMAT.format(domain=engine, platform=DOMAIN)
|
PLATFORM_FORMAT.format(domain=DOMAIN, platform=engine)
|
||||||
)
|
)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -304,7 +304,7 @@ class EntityPlatform:
|
|||||||
current_platform.set(self)
|
current_platform.set(self)
|
||||||
logger = self.logger
|
logger = self.logger
|
||||||
hass = self.hass
|
hass = self.hass
|
||||||
full_name = f"{self.domain}.{self.platform_name}"
|
full_name = f"{self.platform_name}.{self.domain}"
|
||||||
object_id_language = (
|
object_id_language = (
|
||||||
hass.config.language
|
hass.config.language
|
||||||
if hass.config.language in languages.NATIVE_ENTITY_IDS
|
if hass.config.language in languages.NATIVE_ENTITY_IDS
|
||||||
|
@ -48,7 +48,7 @@ def component_translation_path(
|
|||||||
If component is just a single file, will return None.
|
If component is just a single file, will return None.
|
||||||
"""
|
"""
|
||||||
parts = component.split(".")
|
parts = component.split(".")
|
||||||
domain = parts[-1]
|
domain = parts[0]
|
||||||
is_platform = len(parts) == 2
|
is_platform = len(parts) == 2
|
||||||
|
|
||||||
# If it's a component that is just one file, we don't support translations
|
# If it's a component that is just one file, we don't support translations
|
||||||
@ -57,7 +57,7 @@ def component_translation_path(
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
if is_platform:
|
if is_platform:
|
||||||
filename = f"{parts[0]}.{language}.json"
|
filename = f"{parts[1]}.{language}.json"
|
||||||
else:
|
else:
|
||||||
filename = f"{language}.json"
|
filename = f"{language}.json"
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ def _merge_resources(
|
|||||||
# Build response
|
# Build response
|
||||||
resources: dict[str, dict[str, Any]] = {}
|
resources: dict[str, dict[str, Any]] = {}
|
||||||
for component in components:
|
for component in components:
|
||||||
domain = component.partition(".")[0]
|
domain = component.rpartition(".")[-1]
|
||||||
|
|
||||||
domain_resources = resources.setdefault(domain, {})
|
domain_resources = resources.setdefault(domain, {})
|
||||||
|
|
||||||
@ -154,7 +154,7 @@ async def _async_get_component_strings(
|
|||||||
# Determine paths of missing components/platforms
|
# Determine paths of missing components/platforms
|
||||||
files_to_load = {}
|
files_to_load = {}
|
||||||
for loaded in components:
|
for loaded in components:
|
||||||
domain = loaded.rpartition(".")[-1]
|
domain = loaded.partition(".")[0]
|
||||||
integration = integrations[domain]
|
integration = integrations[domain]
|
||||||
|
|
||||||
path = component_translation_path(loaded, language, integration)
|
path = component_translation_path(loaded, language, integration)
|
||||||
@ -225,7 +225,7 @@ class _TranslationCache:
|
|||||||
languages = [LOCALE_EN] if language == LOCALE_EN else [LOCALE_EN, language]
|
languages = [LOCALE_EN] if language == LOCALE_EN else [LOCALE_EN, language]
|
||||||
|
|
||||||
integrations: dict[str, Integration] = {}
|
integrations: dict[str, Integration] = {}
|
||||||
domains = list({loaded.rpartition(".")[-1] for loaded in components})
|
domains = list({loaded.partition(".")[0] for loaded in components})
|
||||||
ints_or_excs = await async_get_integrations(self.hass, domains)
|
ints_or_excs = await async_get_integrations(self.hass, domains)
|
||||||
for domain, int_or_exc in ints_or_excs.items():
|
for domain, int_or_exc in ints_or_excs.items():
|
||||||
if isinstance(int_or_exc, Exception):
|
if isinstance(int_or_exc, Exception):
|
||||||
|
@ -538,7 +538,7 @@ def async_get_loaded_integrations(hass: core.HomeAssistant) -> set[str]:
|
|||||||
if "." not in component:
|
if "." not in component:
|
||||||
integrations.add(component)
|
integrations.add(component)
|
||||||
continue
|
continue
|
||||||
domain, _, platform = component.partition(".")
|
platform, _, domain = component.partition(".")
|
||||||
if domain in BASE_PLATFORMS:
|
if domain in BASE_PLATFORMS:
|
||||||
integrations.add(platform)
|
integrations.add(platform)
|
||||||
return integrations
|
return integrations
|
||||||
@ -563,7 +563,7 @@ def async_start_setup(
|
|||||||
time_taken = dt_util.utcnow() - started
|
time_taken = dt_util.utcnow() - started
|
||||||
for unique, domain in unique_components.items():
|
for unique, domain in unique_components.items():
|
||||||
del setup_started[unique]
|
del setup_started[unique]
|
||||||
integration = domain.rpartition(".")[-1]
|
integration = domain.partition(".")[0]
|
||||||
if integration in setup_time:
|
if integration in setup_time:
|
||||||
setup_time[integration] += time_taken
|
setup_time[integration] += time_taken
|
||||||
else:
|
else:
|
||||||
|
@ -259,7 +259,7 @@ async def test_connected_device_registered(
|
|||||||
|
|
||||||
assert await entity_platform.async_setup_entry(config_entry)
|
assert await entity_platform.async_setup_entry(config_entry)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
full_name = f"{entity_platform.domain}.{config_entry.domain}"
|
full_name = f"{config_entry.domain}.{entity_platform.domain}"
|
||||||
assert full_name in hass.config.components
|
assert full_name in hass.config.components
|
||||||
assert len(hass.states.async_entity_ids()) == 0 # should be disabled
|
assert len(hass.states.async_entity_ids()) == 0 # should be disabled
|
||||||
assert len(entity_registry.entities) == 3
|
assert len(entity_registry.entities) == 3
|
||||||
|
@ -123,7 +123,7 @@ async def test_reading_yaml_config(
|
|||||||
assert device.config_picture == config.config_picture
|
assert device.config_picture == config.config_picture
|
||||||
assert device.consider_home == config.consider_home
|
assert device.consider_home == config.consider_home
|
||||||
assert device.icon == config.icon
|
assert device.icon == config.icon
|
||||||
assert f"{device_tracker.DOMAIN}.test" in hass.config.components
|
assert f"test.{device_tracker.DOMAIN}" in hass.config.components
|
||||||
|
|
||||||
|
|
||||||
@patch("homeassistant.components.device_tracker.const.LOGGER.warning")
|
@patch("homeassistant.components.device_tracker.const.LOGGER.warning")
|
||||||
@ -603,7 +603,7 @@ async def test_bad_platform(hass: HomeAssistant) -> None:
|
|||||||
with assert_setup_component(0, device_tracker.DOMAIN):
|
with assert_setup_component(0, device_tracker.DOMAIN):
|
||||||
assert await async_setup_component(hass, device_tracker.DOMAIN, config)
|
assert await async_setup_component(hass, device_tracker.DOMAIN, config)
|
||||||
|
|
||||||
assert f"{device_tracker.DOMAIN}.bad_platform" not in hass.config.components
|
assert f"bad_platform.{device_tracker.DOMAIN}" not in hass.config.components
|
||||||
|
|
||||||
|
|
||||||
async def test_adding_unknown_device_to_config(
|
async def test_adding_unknown_device_to_config(
|
||||||
|
@ -150,7 +150,7 @@ async def test_restore_state(
|
|||||||
async def test_setup_component(hass: HomeAssistant, setup: str) -> None:
|
async def test_setup_component(hass: HomeAssistant, setup: str) -> None:
|
||||||
"""Set up a TTS platform with defaults."""
|
"""Set up a TTS platform with defaults."""
|
||||||
assert hass.services.has_service(tts.DOMAIN, "clear_cache")
|
assert hass.services.has_service(tts.DOMAIN, "clear_cache")
|
||||||
assert f"{tts.DOMAIN}.test" in hass.config.components
|
assert f"test.{tts.DOMAIN}" in hass.config.components
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("init_tts_cache_dir_side_effect", [OSError(2, "No access")])
|
@pytest.mark.parametrize("init_tts_cache_dir_side_effect", [OSError(2, "No access")])
|
||||||
|
@ -1286,7 +1286,7 @@ async def test_issue_forecast_deprecated_no_logging(
|
|||||||
|
|
||||||
assert weather_entity.state == ATTR_CONDITION_SUNNY
|
assert weather_entity.state == ATTR_CONDITION_SUNNY
|
||||||
|
|
||||||
assert "Setting up weather.test" in caplog.text
|
assert "Setting up test.weather" in caplog.text
|
||||||
assert (
|
assert (
|
||||||
"custom_components.test_weather.weather::weather.test is using a forecast attribute on an instance of WeatherEntity"
|
"custom_components.test_weather.weather::weather.test is using a forecast attribute on an instance of WeatherEntity"
|
||||||
not in caplog.text
|
not in caplog.text
|
||||||
|
@ -215,7 +215,7 @@ async def test_platform_not_ready(hass: HomeAssistant) -> None:
|
|||||||
await component.async_setup({DOMAIN: {"platform": "mod1"}})
|
await component.async_setup({DOMAIN: {"platform": "mod1"}})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(platform1_setup.mock_calls) == 1
|
assert len(platform1_setup.mock_calls) == 1
|
||||||
assert "test_domain.mod1" not in hass.config.components
|
assert "mod1.test_domain" not in hass.config.components
|
||||||
|
|
||||||
# Should not trigger attempt 2
|
# Should not trigger attempt 2
|
||||||
async_fire_time_changed(hass, utcnow + timedelta(seconds=29))
|
async_fire_time_changed(hass, utcnow + timedelta(seconds=29))
|
||||||
@ -226,7 +226,7 @@ async def test_platform_not_ready(hass: HomeAssistant) -> None:
|
|||||||
async_fire_time_changed(hass, utcnow + timedelta(seconds=30))
|
async_fire_time_changed(hass, utcnow + timedelta(seconds=30))
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(platform1_setup.mock_calls) == 2
|
assert len(platform1_setup.mock_calls) == 2
|
||||||
assert "test_domain.mod1" not in hass.config.components
|
assert "mod1.test_domain" not in hass.config.components
|
||||||
|
|
||||||
# This should not trigger attempt 3
|
# This should not trigger attempt 3
|
||||||
async_fire_time_changed(hass, utcnow + timedelta(seconds=59))
|
async_fire_time_changed(hass, utcnow + timedelta(seconds=59))
|
||||||
@ -237,7 +237,7 @@ async def test_platform_not_ready(hass: HomeAssistant) -> None:
|
|||||||
async_fire_time_changed(hass, utcnow + timedelta(seconds=60))
|
async_fire_time_changed(hass, utcnow + timedelta(seconds=60))
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(platform1_setup.mock_calls) == 3
|
assert len(platform1_setup.mock_calls) == 3
|
||||||
assert "test_domain.mod1" in hass.config.components
|
assert "mod1.test_domain" in hass.config.components
|
||||||
|
|
||||||
|
|
||||||
async def test_extract_from_service_fails_if_no_entity_id(hass: HomeAssistant) -> None:
|
async def test_extract_from_service_fails_if_no_entity_id(hass: HomeAssistant) -> None:
|
||||||
@ -317,7 +317,7 @@ async def test_setup_dependencies_platform(hass: HomeAssistant) -> None:
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert "test_component" in hass.config.components
|
assert "test_component" in hass.config.components
|
||||||
assert "test_component2" in hass.config.components
|
assert "test_component2" in hass.config.components
|
||||||
assert "test_domain.test_component" in hass.config.components
|
assert "test_component.test_domain" in hass.config.components
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_entry(hass: HomeAssistant) -> None:
|
async def test_setup_entry(hass: HomeAssistant) -> None:
|
||||||
@ -680,7 +680,7 @@ async def test_platforms_shutdown_on_stop(hass: HomeAssistant) -> None:
|
|||||||
await component.async_setup({DOMAIN: {"platform": "mod1"}})
|
await component.async_setup({DOMAIN: {"platform": "mod1"}})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(platform1_setup.mock_calls) == 1
|
assert len(platform1_setup.mock_calls) == 1
|
||||||
assert "test_domain.mod1" not in hass.config.components
|
assert "mod1.test_domain" not in hass.config.components
|
||||||
|
|
||||||
with patch.object(
|
with patch.object(
|
||||||
component._platforms[DOMAIN], "async_shutdown"
|
component._platforms[DOMAIN], "async_shutdown"
|
||||||
|
@ -268,7 +268,7 @@ async def test_platform_error_slow_setup(
|
|||||||
await component.async_setup({DOMAIN: {"platform": "test_platform"}})
|
await component.async_setup({DOMAIN: {"platform": "test_platform"}})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(called) == 1
|
assert len(called) == 1
|
||||||
assert "test_domain.test_platform" not in hass.config.components
|
assert "test_platform.test_domain" not in hass.config.components
|
||||||
assert "test_platform is taking longer than 0 seconds" in caplog.text
|
assert "test_platform is taking longer than 0 seconds" in caplog.text
|
||||||
|
|
||||||
# Cleanup lingering (setup_platform) task after test is done
|
# Cleanup lingering (setup_platform) task after test is done
|
||||||
@ -833,7 +833,7 @@ async def test_setup_entry(
|
|||||||
|
|
||||||
assert await entity_platform.async_setup_entry(config_entry)
|
assert await entity_platform.async_setup_entry(config_entry)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
full_name = f"{entity_platform.domain}.{config_entry.domain}"
|
full_name = f"{config_entry.domain}.{entity_platform.domain}"
|
||||||
assert full_name in hass.config.components
|
assert full_name in hass.config.components
|
||||||
assert len(hass.states.async_entity_ids()) == 1
|
assert len(hass.states.async_entity_ids()) == 1
|
||||||
assert len(entity_registry.entities) == 1
|
assert len(entity_registry.entities) == 1
|
||||||
@ -856,7 +856,7 @@ async def test_setup_entry_platform_not_ready(
|
|||||||
with patch.object(entity_platform, "async_call_later") as mock_call_later:
|
with patch.object(entity_platform, "async_call_later") as mock_call_later:
|
||||||
assert not await ent_platform.async_setup_entry(config_entry)
|
assert not await ent_platform.async_setup_entry(config_entry)
|
||||||
|
|
||||||
full_name = f"{ent_platform.domain}.{config_entry.domain}"
|
full_name = f"{config_entry.domain}.{ent_platform.domain}"
|
||||||
assert full_name not in hass.config.components
|
assert full_name not in hass.config.components
|
||||||
assert len(async_setup_entry.mock_calls) == 1
|
assert len(async_setup_entry.mock_calls) == 1
|
||||||
assert "Platform test not ready yet" in caplog.text
|
assert "Platform test not ready yet" in caplog.text
|
||||||
@ -877,7 +877,7 @@ async def test_setup_entry_platform_not_ready_with_message(
|
|||||||
with patch.object(entity_platform, "async_call_later") as mock_call_later:
|
with patch.object(entity_platform, "async_call_later") as mock_call_later:
|
||||||
assert not await ent_platform.async_setup_entry(config_entry)
|
assert not await ent_platform.async_setup_entry(config_entry)
|
||||||
|
|
||||||
full_name = f"{ent_platform.domain}.{config_entry.domain}"
|
full_name = f"{config_entry.domain}.{ent_platform.domain}"
|
||||||
assert full_name not in hass.config.components
|
assert full_name not in hass.config.components
|
||||||
assert len(async_setup_entry.mock_calls) == 1
|
assert len(async_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
@ -904,7 +904,7 @@ async def test_setup_entry_platform_not_ready_from_exception(
|
|||||||
with patch.object(entity_platform, "async_call_later") as mock_call_later:
|
with patch.object(entity_platform, "async_call_later") as mock_call_later:
|
||||||
assert not await ent_platform.async_setup_entry(config_entry)
|
assert not await ent_platform.async_setup_entry(config_entry)
|
||||||
|
|
||||||
full_name = f"{ent_platform.domain}.{config_entry.domain}"
|
full_name = f"{config_entry.domain}.{ent_platform.domain}"
|
||||||
assert full_name not in hass.config.components
|
assert full_name not in hass.config.components
|
||||||
assert len(async_setup_entry.mock_calls) == 1
|
assert len(async_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
@ -1669,7 +1669,7 @@ async def test_setup_entry_with_entities_that_block_forever(
|
|||||||
):
|
):
|
||||||
assert await platform.async_setup_entry(config_entry)
|
assert await platform.async_setup_entry(config_entry)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
full_name = f"{platform.domain}.{config_entry.domain}"
|
full_name = f"{config_entry.domain}.{platform.domain}"
|
||||||
assert full_name in hass.config.components
|
assert full_name in hass.config.components
|
||||||
assert len(hass.states.async_entity_ids()) == 0
|
assert len(hass.states.async_entity_ids()) == 0
|
||||||
assert len(entity_registry.entities) == 1
|
assert len(entity_registry.entities) == 1
|
||||||
|
@ -53,7 +53,7 @@ async def test_reload_platform(hass: HomeAssistant) -> None:
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert component_setup.called
|
assert component_setup.called
|
||||||
|
|
||||||
assert f"{DOMAIN}.{PLATFORM}" in hass.config.components
|
assert f"{PLATFORM}.{DOMAIN}" in hass.config.components
|
||||||
assert len(setup_called) == 1
|
assert len(setup_called) == 1
|
||||||
|
|
||||||
platform = async_get_platform_without_config_entry(hass, PLATFORM, DOMAIN)
|
platform = async_get_platform_without_config_entry(hass, PLATFORM, DOMAIN)
|
||||||
@ -93,7 +93,7 @@ async def test_setup_reload_service(hass: HomeAssistant) -> None:
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert component_setup.called
|
assert component_setup.called
|
||||||
|
|
||||||
assert f"{DOMAIN}.{PLATFORM}" in hass.config.components
|
assert f"{PLATFORM}.{DOMAIN}" in hass.config.components
|
||||||
assert len(setup_called) == 1
|
assert len(setup_called) == 1
|
||||||
|
|
||||||
await async_setup_reload_service(hass, PLATFORM, [DOMAIN])
|
await async_setup_reload_service(hass, PLATFORM, [DOMAIN])
|
||||||
@ -134,7 +134,7 @@ async def test_setup_reload_service_when_async_process_component_config_fails(
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert component_setup.called
|
assert component_setup.called
|
||||||
|
|
||||||
assert f"{DOMAIN}.{PLATFORM}" in hass.config.components
|
assert f"{PLATFORM}.{DOMAIN}" in hass.config.components
|
||||||
assert len(setup_called) == 1
|
assert len(setup_called) == 1
|
||||||
|
|
||||||
await async_setup_reload_service(hass, PLATFORM, [DOMAIN])
|
await async_setup_reload_service(hass, PLATFORM, [DOMAIN])
|
||||||
@ -186,7 +186,7 @@ async def test_setup_reload_service_with_platform_that_provides_async_reset_plat
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert component_setup.called
|
assert component_setup.called
|
||||||
|
|
||||||
assert f"{DOMAIN}.{PLATFORM}" in hass.config.components
|
assert f"{PLATFORM}.{DOMAIN}" in hass.config.components
|
||||||
assert len(setup_called) == 1
|
assert len(setup_called) == 1
|
||||||
|
|
||||||
await async_setup_reload_service(hass, PLATFORM, [DOMAIN])
|
await async_setup_reload_service(hass, PLATFORM, [DOMAIN])
|
||||||
|
@ -508,7 +508,7 @@ async def test_restore_entity_end_to_end(
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert component_setup.called
|
assert component_setup.called
|
||||||
|
|
||||||
assert f"{DOMAIN}.{PLATFORM}" in hass.config.components
|
assert f"{PLATFORM}.{DOMAIN}" in hass.config.components
|
||||||
assert len(setup_called) == 1
|
assert len(setup_called) == 1
|
||||||
|
|
||||||
platform = async_get_platform_without_config_entry(hass, PLATFORM, DOMAIN)
|
platform = async_get_platform_without_config_entry(hass, PLATFORM, DOMAIN)
|
||||||
|
@ -56,14 +56,14 @@ async def test_component_translation_path(
|
|||||||
)
|
)
|
||||||
|
|
||||||
assert path.normpath(
|
assert path.normpath(
|
||||||
translation.component_translation_path("switch.test", "en", int_test)
|
translation.component_translation_path("test.switch", "en", int_test)
|
||||||
) == path.normpath(
|
) == path.normpath(
|
||||||
hass.config.path("custom_components", "test", "translations", "switch.en.json")
|
hass.config.path("custom_components", "test", "translations", "switch.en.json")
|
||||||
)
|
)
|
||||||
|
|
||||||
assert path.normpath(
|
assert path.normpath(
|
||||||
translation.component_translation_path(
|
translation.component_translation_path(
|
||||||
"switch.test_embedded", "en", int_test_embedded
|
"test_embedded.switch", "en", int_test_embedded
|
||||||
)
|
)
|
||||||
) == path.normpath(
|
) == path.normpath(
|
||||||
hass.config.path(
|
hass.config.path(
|
||||||
@ -255,7 +255,7 @@ async def test_translation_merging(
|
|||||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test we merge translations of two integrations."""
|
"""Test we merge translations of two integrations."""
|
||||||
hass.config.components.add("sensor.moon")
|
hass.config.components.add("moon.sensor")
|
||||||
hass.config.components.add("sensor")
|
hass.config.components.add("sensor")
|
||||||
|
|
||||||
orig_load_translations = translation.load_translations_files
|
orig_load_translations = translation.load_translations_files
|
||||||
@ -263,7 +263,7 @@ async def test_translation_merging(
|
|||||||
def mock_load_translations_files(files):
|
def mock_load_translations_files(files):
|
||||||
"""Mock loading."""
|
"""Mock loading."""
|
||||||
result = orig_load_translations(files)
|
result = orig_load_translations(files)
|
||||||
result["sensor.moon"] = {
|
result["moon.sensor"] = {
|
||||||
"state": {"moon__phase": {"first_quarter": "First Quarter"}}
|
"state": {"moon__phase": {"first_quarter": "First Quarter"}}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
@ -276,13 +276,13 @@ async def test_translation_merging(
|
|||||||
|
|
||||||
assert "component.sensor.state.moon__phase.first_quarter" in translations
|
assert "component.sensor.state.moon__phase.first_quarter" in translations
|
||||||
|
|
||||||
hass.config.components.add("sensor.season")
|
hass.config.components.add("season.sensor")
|
||||||
|
|
||||||
# Patch in some bad translation data
|
# Patch in some bad translation data
|
||||||
def mock_load_bad_translations_files(files):
|
def mock_load_bad_translations_files(files):
|
||||||
"""Mock loading."""
|
"""Mock loading."""
|
||||||
result = orig_load_translations(files)
|
result = orig_load_translations(files)
|
||||||
result["sensor.season"] = {"state": "bad data"}
|
result["season.sensor"] = {"state": "bad data"}
|
||||||
return result
|
return result
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
@ -308,7 +308,7 @@ async def test_translation_merging_loaded_apart(
|
|||||||
def mock_load_translations_files(files):
|
def mock_load_translations_files(files):
|
||||||
"""Mock loading."""
|
"""Mock loading."""
|
||||||
result = orig_load_translations(files)
|
result = orig_load_translations(files)
|
||||||
result["sensor.moon"] = {
|
result["moon.sensor"] = {
|
||||||
"state": {"moon__phase": {"first_quarter": "First Quarter"}}
|
"state": {"moon__phase": {"first_quarter": "First Quarter"}}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
@ -323,7 +323,7 @@ async def test_translation_merging_loaded_apart(
|
|||||||
|
|
||||||
assert "component.sensor.state.moon__phase.first_quarter" not in translations
|
assert "component.sensor.state.moon__phase.first_quarter" not in translations
|
||||||
|
|
||||||
hass.config.components.add("sensor.moon")
|
hass.config.components.add("moon.sensor")
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.helpers.translation.load_translations_files",
|
"homeassistant.helpers.translation.load_translations_files",
|
||||||
|
@ -672,7 +672,7 @@ async def test_async_get_loaded_integrations(hass: HomeAssistant) -> None:
|
|||||||
hass.config.components.add("notbase.switch")
|
hass.config.components.add("notbase.switch")
|
||||||
hass.config.components.add("myintegration")
|
hass.config.components.add("myintegration")
|
||||||
hass.config.components.add("device_tracker")
|
hass.config.components.add("device_tracker")
|
||||||
hass.config.components.add("device_tracker.other")
|
hass.config.components.add("other.device_tracker")
|
||||||
hass.config.components.add("myintegration.light")
|
hass.config.components.add("myintegration.light")
|
||||||
assert setup.async_get_loaded_integrations(hass) == {
|
assert setup.async_get_loaded_integrations(hass) == {
|
||||||
"other",
|
"other",
|
||||||
@ -729,9 +729,9 @@ async def test_async_start_setup(hass: HomeAssistant) -> None:
|
|||||||
|
|
||||||
async def test_async_start_setup_platforms(hass: HomeAssistant) -> None:
|
async def test_async_start_setup_platforms(hass: HomeAssistant) -> None:
|
||||||
"""Test setup started context manager keeps track of setup times for platforms."""
|
"""Test setup started context manager keeps track of setup times for platforms."""
|
||||||
with setup.async_start_setup(hass, ["sensor.august"]):
|
with setup.async_start_setup(hass, ["august.sensor"]):
|
||||||
assert isinstance(
|
assert isinstance(
|
||||||
hass.data[setup.DATA_SETUP_STARTED]["sensor.august"], datetime.datetime
|
hass.data[setup.DATA_SETUP_STARTED]["august.sensor"], datetime.datetime
|
||||||
)
|
)
|
||||||
|
|
||||||
assert "august" not in hass.data[setup.DATA_SETUP_STARTED]
|
assert "august" not in hass.data[setup.DATA_SETUP_STARTED]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user