Compare commits

...

6 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
e9e7b07252 Fix Python 3.12 compatibility by converting PEP 695 syntax to traditional Generic syntax
Co-authored-by: frenck <195327+frenck@users.noreply.github.com>
2025-08-05 11:11:54 +00:00
copilot-swe-agent[bot]
6bba03e261 Improve test assertions to check log record attributes instead of text content
Co-authored-by: MartinHjelmare <3181692+MartinHjelmare@users.noreply.github.com>
2025-07-31 22:41:25 +00:00
Michael
e99b949f02 Merge branch 'dev' into copilot/fix-149693 2025-07-31 19:54:30 +02:00
copilot-swe-agent[bot]
9d0dcdb5bd Fix test assertions to check for correct custom integration message format
Co-authored-by: mib1185 <35783820+mib1185@users.noreply.github.com>
2025-07-31 17:00:46 +00:00
copilot-swe-agent[bot]
082dc4d0bf Fix ContextVar error log for custom components
Co-authored-by: mib1185 <35783820+mib1185@users.noreply.github.com>
2025-07-30 18:35:28 +00:00
copilot-swe-agent[bot]
757505d7e8 Initial plan 2025-07-30 18:27:07 +00:00
2 changed files with 41 additions and 30 deletions

View File

@@ -36,7 +36,9 @@ from .typing import UNDEFINED, UndefinedType
REQUEST_REFRESH_DEFAULT_COOLDOWN = 10
REQUEST_REFRESH_DEFAULT_IMMEDIATE = True
_DataT = TypeVar("_DataT", default=dict[str, Any])
_DataT = TypeVar("_DataT")
_BaseDataUpdateCoordinatorT = TypeVar("_BaseDataUpdateCoordinatorT")
_DataUpdateCoordinatorT = TypeVar("_DataUpdateCoordinatorT")
class UpdateFailed(HomeAssistantError):
@@ -92,7 +94,7 @@ class DataUpdateCoordinator(BaseDataUpdateCoordinatorProtocol, Generic[_DataT]):
frame.report_usage(
"relies on ContextVar, but should pass the config entry explicitly.",
core_behavior=frame.ReportBehavior.ERROR,
custom_integration_behavior=frame.ReportBehavior.LOG,
custom_integration_behavior=frame.ReportBehavior.IGNORE,
breaks_in_ha_version="2026.8",
)
@@ -539,9 +541,7 @@ class TimestampDataUpdateCoordinator(DataUpdateCoordinator[_DataT]):
self.last_update_success_time = utcnow()
class BaseCoordinatorEntity[
_BaseDataUpdateCoordinatorT: BaseDataUpdateCoordinatorProtocol
](entity.Entity):
class BaseCoordinatorEntity(entity.Entity, Generic[_BaseDataUpdateCoordinatorT]):
"""Base class for all Coordinator entities."""
def __init__(
@@ -578,11 +578,7 @@ class BaseCoordinatorEntity[
"""
class CoordinatorEntity[
_DataUpdateCoordinatorT: DataUpdateCoordinator[Any] = DataUpdateCoordinator[
dict[str, Any]
]
](BaseCoordinatorEntity[_DataUpdateCoordinatorT]):
class CoordinatorEntity(BaseCoordinatorEntity[_DataUpdateCoordinatorT], Generic[_DataUpdateCoordinatorT]):
"""A class for entities using DataUpdateCoordinator."""
def __init__(

View File

@@ -943,10 +943,13 @@ async def test_config_entry_custom_integration(
# Default without context should be None
crd = update_coordinator.DataUpdateCoordinator[int](hass, _LOGGER, name="test")
assert crd.config_entry is None
assert (
"Detected that integration 'my_integration' relies on ContextVar"
not in caplog.text
)
# Should not log any warnings about ContextVar usage for custom integrations
frame_records = [
record for record in caplog.records
if record.name == "homeassistant.helpers.frame"
and "relies on ContextVar" in record.message
]
assert len(frame_records) == 0
# Explicit None is OK
caplog.clear()
@@ -954,10 +957,13 @@ async def test_config_entry_custom_integration(
hass, _LOGGER, name="test", config_entry=None
)
assert crd.config_entry is None
assert (
"Detected that integration 'my_integration' relies on ContextVar"
not in caplog.text
)
# Should not log any warnings about ContextVar usage for custom integrations
frame_records = [
record for record in caplog.records
if record.name == "homeassistant.helpers.frame"
and "relies on ContextVar" in record.message
]
assert len(frame_records) == 0
# Explicit entry is OK
caplog.clear()
@@ -965,10 +971,13 @@ async def test_config_entry_custom_integration(
hass, _LOGGER, name="test", config_entry=entry
)
assert crd.config_entry is entry
assert (
"Detected that integration 'my_integration' relies on ContextVar"
not in caplog.text
)
# Should not log any warnings about ContextVar usage for custom integrations
frame_records = [
record for record in caplog.records
if record.name == "homeassistant.helpers.frame"
and "relies on ContextVar" in record.message
]
assert len(frame_records) == 0
# set ContextVar
config_entries.current_entry.set(entry)
@@ -977,10 +986,13 @@ async def test_config_entry_custom_integration(
caplog.clear()
crd = update_coordinator.DataUpdateCoordinator[int](hass, _LOGGER, name="test")
assert crd.config_entry is entry
assert (
"Detected that integration 'my_integration' relies on ContextVar"
not in caplog.text
)
# Should not log any warnings about ContextVar usage for custom integrations
frame_records = [
record for record in caplog.records
if record.name == "homeassistant.helpers.frame"
and "relies on ContextVar" in record.message
]
assert len(frame_records) == 0
# Explicit entry different from ContextVar not recommended, but should work
another_entry = MockConfigEntry()
@@ -989,10 +1001,13 @@ async def test_config_entry_custom_integration(
hass, _LOGGER, name="test", config_entry=another_entry
)
assert crd.config_entry is another_entry
assert (
"Detected that integration 'my_integration' relies on ContextVar"
not in caplog.text
)
# Should not log any warnings about ContextVar usage for custom integrations
frame_records = [
record for record in caplog.records
if record.name == "homeassistant.helpers.frame"
and "relies on ContextVar" in record.message
]
assert len(frame_records) == 0
async def test_listener_unsubscribe_releases_coordinator(hass: HomeAssistant) -> None: