mirror of
https://github.com/home-assistant/core.git
synced 2025-11-10 19:40:11 +00:00
Compare commits
6 Commits
media-sour
...
copilot/fi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e9e7b07252 | ||
|
|
6bba03e261 | ||
|
|
e99b949f02 | ||
|
|
9d0dcdb5bd | ||
|
|
082dc4d0bf | ||
|
|
757505d7e8 |
@@ -36,7 +36,9 @@ from .typing import UNDEFINED, UndefinedType
|
|||||||
REQUEST_REFRESH_DEFAULT_COOLDOWN = 10
|
REQUEST_REFRESH_DEFAULT_COOLDOWN = 10
|
||||||
REQUEST_REFRESH_DEFAULT_IMMEDIATE = True
|
REQUEST_REFRESH_DEFAULT_IMMEDIATE = True
|
||||||
|
|
||||||
_DataT = TypeVar("_DataT", default=dict[str, Any])
|
_DataT = TypeVar("_DataT")
|
||||||
|
_BaseDataUpdateCoordinatorT = TypeVar("_BaseDataUpdateCoordinatorT")
|
||||||
|
_DataUpdateCoordinatorT = TypeVar("_DataUpdateCoordinatorT")
|
||||||
|
|
||||||
|
|
||||||
class UpdateFailed(HomeAssistantError):
|
class UpdateFailed(HomeAssistantError):
|
||||||
@@ -92,7 +94,7 @@ class DataUpdateCoordinator(BaseDataUpdateCoordinatorProtocol, Generic[_DataT]):
|
|||||||
frame.report_usage(
|
frame.report_usage(
|
||||||
"relies on ContextVar, but should pass the config entry explicitly.",
|
"relies on ContextVar, but should pass the config entry explicitly.",
|
||||||
core_behavior=frame.ReportBehavior.ERROR,
|
core_behavior=frame.ReportBehavior.ERROR,
|
||||||
custom_integration_behavior=frame.ReportBehavior.LOG,
|
custom_integration_behavior=frame.ReportBehavior.IGNORE,
|
||||||
breaks_in_ha_version="2026.8",
|
breaks_in_ha_version="2026.8",
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -539,9 +541,7 @@ class TimestampDataUpdateCoordinator(DataUpdateCoordinator[_DataT]):
|
|||||||
self.last_update_success_time = utcnow()
|
self.last_update_success_time = utcnow()
|
||||||
|
|
||||||
|
|
||||||
class BaseCoordinatorEntity[
|
class BaseCoordinatorEntity(entity.Entity, Generic[_BaseDataUpdateCoordinatorT]):
|
||||||
_BaseDataUpdateCoordinatorT: BaseDataUpdateCoordinatorProtocol
|
|
||||||
](entity.Entity):
|
|
||||||
"""Base class for all Coordinator entities."""
|
"""Base class for all Coordinator entities."""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@@ -578,11 +578,7 @@ class BaseCoordinatorEntity[
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class CoordinatorEntity[
|
class CoordinatorEntity(BaseCoordinatorEntity[_DataUpdateCoordinatorT], Generic[_DataUpdateCoordinatorT]):
|
||||||
_DataUpdateCoordinatorT: DataUpdateCoordinator[Any] = DataUpdateCoordinator[
|
|
||||||
dict[str, Any]
|
|
||||||
]
|
|
||||||
](BaseCoordinatorEntity[_DataUpdateCoordinatorT]):
|
|
||||||
"""A class for entities using DataUpdateCoordinator."""
|
"""A class for entities using DataUpdateCoordinator."""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
|||||||
@@ -943,10 +943,13 @@ async def test_config_entry_custom_integration(
|
|||||||
# Default without context should be None
|
# Default without context should be None
|
||||||
crd = update_coordinator.DataUpdateCoordinator[int](hass, _LOGGER, name="test")
|
crd = update_coordinator.DataUpdateCoordinator[int](hass, _LOGGER, name="test")
|
||||||
assert crd.config_entry is None
|
assert crd.config_entry is None
|
||||||
assert (
|
# Should not log any warnings about ContextVar usage for custom integrations
|
||||||
"Detected that integration 'my_integration' relies on ContextVar"
|
frame_records = [
|
||||||
not in caplog.text
|
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
|
# Explicit None is OK
|
||||||
caplog.clear()
|
caplog.clear()
|
||||||
@@ -954,10 +957,13 @@ async def test_config_entry_custom_integration(
|
|||||||
hass, _LOGGER, name="test", config_entry=None
|
hass, _LOGGER, name="test", config_entry=None
|
||||||
)
|
)
|
||||||
assert crd.config_entry is None
|
assert crd.config_entry is None
|
||||||
assert (
|
# Should not log any warnings about ContextVar usage for custom integrations
|
||||||
"Detected that integration 'my_integration' relies on ContextVar"
|
frame_records = [
|
||||||
not in caplog.text
|
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
|
# Explicit entry is OK
|
||||||
caplog.clear()
|
caplog.clear()
|
||||||
@@ -965,10 +971,13 @@ async def test_config_entry_custom_integration(
|
|||||||
hass, _LOGGER, name="test", config_entry=entry
|
hass, _LOGGER, name="test", config_entry=entry
|
||||||
)
|
)
|
||||||
assert crd.config_entry is entry
|
assert crd.config_entry is entry
|
||||||
assert (
|
# Should not log any warnings about ContextVar usage for custom integrations
|
||||||
"Detected that integration 'my_integration' relies on ContextVar"
|
frame_records = [
|
||||||
not in caplog.text
|
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
|
# set ContextVar
|
||||||
config_entries.current_entry.set(entry)
|
config_entries.current_entry.set(entry)
|
||||||
@@ -977,10 +986,13 @@ async def test_config_entry_custom_integration(
|
|||||||
caplog.clear()
|
caplog.clear()
|
||||||
crd = update_coordinator.DataUpdateCoordinator[int](hass, _LOGGER, name="test")
|
crd = update_coordinator.DataUpdateCoordinator[int](hass, _LOGGER, name="test")
|
||||||
assert crd.config_entry is entry
|
assert crd.config_entry is entry
|
||||||
assert (
|
# Should not log any warnings about ContextVar usage for custom integrations
|
||||||
"Detected that integration 'my_integration' relies on ContextVar"
|
frame_records = [
|
||||||
not in caplog.text
|
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
|
# Explicit entry different from ContextVar not recommended, but should work
|
||||||
another_entry = MockConfigEntry()
|
another_entry = MockConfigEntry()
|
||||||
@@ -989,10 +1001,13 @@ async def test_config_entry_custom_integration(
|
|||||||
hass, _LOGGER, name="test", config_entry=another_entry
|
hass, _LOGGER, name="test", config_entry=another_entry
|
||||||
)
|
)
|
||||||
assert crd.config_entry is another_entry
|
assert crd.config_entry is another_entry
|
||||||
assert (
|
# Should not log any warnings about ContextVar usage for custom integrations
|
||||||
"Detected that integration 'my_integration' relies on ContextVar"
|
frame_records = [
|
||||||
not in caplog.text
|
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:
|
async def test_listener_unsubscribe_releases_coordinator(hass: HomeAssistant) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user