mirror of
https://github.com/home-assistant/core.git
synced 2025-08-03 10:38:22 +00:00
Fix ContextVar usage in FirmwareUpdateCoordinator by passing config_entry explicitly
Co-authored-by: joostlek <7083755+joostlek@users.noreply.github.com>
This commit is contained in:
parent
1ebdf2095a
commit
ad648a9dec
@ -12,6 +12,7 @@ from ha_silabs_firmware_client import (
|
|||||||
ManifestMissing,
|
ManifestMissing,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
|
||||||
@ -24,13 +25,20 @@ FIRMWARE_REFRESH_INTERVAL = timedelta(hours=8)
|
|||||||
class FirmwareUpdateCoordinator(DataUpdateCoordinator[FirmwareManifest]):
|
class FirmwareUpdateCoordinator(DataUpdateCoordinator[FirmwareManifest]):
|
||||||
"""Coordinator to manage firmware updates."""
|
"""Coordinator to manage firmware updates."""
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, session: ClientSession, url: str) -> None:
|
def __init__(
|
||||||
|
self,
|
||||||
|
hass: HomeAssistant,
|
||||||
|
session: ClientSession,
|
||||||
|
url: str,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
) -> None:
|
||||||
"""Initialize the firmware update coordinator."""
|
"""Initialize the firmware update coordinator."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
_LOGGER,
|
_LOGGER,
|
||||||
name="firmware update coordinator",
|
name="firmware update coordinator",
|
||||||
update_interval=FIRMWARE_REFRESH_INTERVAL,
|
update_interval=FIRMWARE_REFRESH_INTERVAL,
|
||||||
|
config_entry=config_entry,
|
||||||
)
|
)
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
self.session = session
|
self.session = session
|
||||||
|
@ -126,6 +126,7 @@ def _async_create_update_entity(
|
|||||||
hass,
|
hass,
|
||||||
session,
|
session,
|
||||||
NABU_CASA_FIRMWARE_RELEASES_URL,
|
NABU_CASA_FIRMWARE_RELEASES_URL,
|
||||||
|
config_entry,
|
||||||
),
|
),
|
||||||
entity_description=entity_description,
|
entity_description=entity_description,
|
||||||
)
|
)
|
||||||
|
@ -131,6 +131,7 @@ def _async_create_update_entity(
|
|||||||
hass,
|
hass,
|
||||||
session,
|
session,
|
||||||
NABU_CASA_FIRMWARE_RELEASES_URL,
|
NABU_CASA_FIRMWARE_RELEASES_URL,
|
||||||
|
config_entry,
|
||||||
),
|
),
|
||||||
entity_description=entity_description,
|
entity_description=entity_description,
|
||||||
)
|
)
|
||||||
|
@ -9,6 +9,7 @@ from yarl import URL
|
|||||||
from homeassistant.components.homeassistant_hardware.coordinator import (
|
from homeassistant.components.homeassistant_hardware.coordinator import (
|
||||||
FirmwareUpdateCoordinator,
|
FirmwareUpdateCoordinator,
|
||||||
)
|
)
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
@ -20,6 +21,9 @@ async def test_firmware_update_coordinator_fetching(
|
|||||||
"""Test the firmware update coordinator loads manifests."""
|
"""Test the firmware update coordinator loads manifests."""
|
||||||
session = async_get_clientsession(hass)
|
session = async_get_clientsession(hass)
|
||||||
|
|
||||||
|
# Create a mock config entry
|
||||||
|
mock_config_entry = Mock(spec=ConfigEntry)
|
||||||
|
|
||||||
manifest = FirmwareManifest(
|
manifest = FirmwareManifest(
|
||||||
url=URL("https://example.org/firmware"),
|
url=URL("https://example.org/firmware"),
|
||||||
html_url=URL("https://example.org/release_notes"),
|
html_url=URL("https://example.org/release_notes"),
|
||||||
@ -35,7 +39,7 @@ async def test_firmware_update_coordinator_fetching(
|
|||||||
return_value=mock_client,
|
return_value=mock_client,
|
||||||
):
|
):
|
||||||
coordinator = FirmwareUpdateCoordinator(
|
coordinator = FirmwareUpdateCoordinator(
|
||||||
hass, session, "https://example.org/firmware"
|
hass, session, "https://example.org/firmware", mock_config_entry
|
||||||
)
|
)
|
||||||
|
|
||||||
listener = Mock()
|
listener = Mock()
|
||||||
|
@ -145,6 +145,7 @@ def _mock_async_create_update_entity(
|
|||||||
hass,
|
hass,
|
||||||
session,
|
session,
|
||||||
TEST_FIRMWARE_RELEASES_URL,
|
TEST_FIRMWARE_RELEASES_URL,
|
||||||
|
config_entry,
|
||||||
),
|
),
|
||||||
entity_description=entity_description,
|
entity_description=entity_description,
|
||||||
)
|
)
|
||||||
@ -595,6 +596,7 @@ async def test_update_entity_graceful_firmware_type_callback_errors(
|
|||||||
hass,
|
hass,
|
||||||
session,
|
session,
|
||||||
TEST_FIRMWARE_RELEASES_URL,
|
TEST_FIRMWARE_RELEASES_URL,
|
||||||
|
update_config_entry,
|
||||||
),
|
),
|
||||||
entity_description=TEST_FIRMWARE_ENTITY_DESCRIPTIONS[ApplicationType.EZSP],
|
entity_description=TEST_FIRMWARE_ENTITY_DESCRIPTIONS[ApplicationType.EZSP],
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user