Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync async_test_home_assistant with core #3971

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import asyncio
from collections.abc import AsyncGenerator, Iterable, Mapping, Sequence
from contextlib import asynccontextmanager, contextmanager
from contextlib import asynccontextmanager, contextmanager, suppress
from contextvars import ContextVar
import functools as ft
from inspect import currentframe
Expand Down Expand Up @@ -419,7 +419,7 @@ async def async_test_home_assistant_dev(
"""Return a Home Assistant object pointing at test config dir.

This should be copied from latest Home Assistant version,
currently Home Assistant Core 2024.6.0dev0 (2024-05-21).
currently Home Assistant Core 2024.9.0dev0 (2024-08-14).
https://github.com/home-assistant/core/blob/dev/tests/common.py
"""
hass = HomeAssistant(config_dir or get_test_config_dir())
Expand Down Expand Up @@ -486,7 +486,12 @@ def async_create_task_internal(coroutine, name=None, eager_start=True):

hass.config_entries = config_entries.ConfigEntries(
hass,
{"_": ("Not empty or else some bad checks for hass config in discovery.py breaks")},
{
"_": (
"Not empty or else some bad checks for hass config in discovery.py"
" breaks"
)
},
)
hass.bus.async_listen_once(
EVENT_HOMEASSISTANT_STOP,
Expand All @@ -498,10 +503,13 @@ def async_create_task_internal(coroutine, name=None, eager_start=True):
loader.async_setup(hass)

# setup translation cache instead of calling translation.async_setup(hass)
hass.data[translation.TRANSLATION_FLATTEN_CACHE] = translation._TranslationCache(hass)
hass.data[translation.TRANSLATION_FLATTEN_CACHE] = translation._TranslationCache(
hass
)
if load_registries:
with (
patch.object(StoreWithoutWriteLoad, "async_load", return_value=None),
patch.object(StoreWithoutWriteLoad,
"async_load", return_value=None),
patch(
"homeassistant.helpers.area_registry.AreaRegistryStore",
StoreWithoutWriteLoad,
Expand Down Expand Up @@ -550,10 +558,14 @@ def clear_instance(event):

hass.bus.async_listen_once(EVENT_HOMEASSISTANT_CLOSE, clear_instance)

yield hass

# Restore timezone, it is set when creating the hass object
dt_util.set_default_time_zone(orig_tz)
try:
yield hass
finally:
# Restore timezone, it is set when creating the hass object
dt_util.set_default_time_zone(orig_tz)
# Remove loop shutdown indicator to not interfere with additional hass objects
with suppress(AttributeError):
delattr(hass.loop, "_shutdown_run_callback_threadsafe")


@ha.callback
Expand Down