Cleanup ESPHome update tests to avoid accessing integration internals (#141786)

We should not access DomainData directly in the test
This commit is contained in:
J. Nick Koston
2025-03-29 22:30:06 -10:00
committed by GitHub
parent 29219afb7f
commit d4970f81aa

View File

@@ -2,7 +2,7 @@
from collections.abc import Awaitable, Callable
from typing import Any
from unittest.mock import Mock, patch
from unittest.mock import patch
from aioesphomeapi import (
APIClient,
@@ -374,17 +374,22 @@ async def test_update_entity_dashboard_discovered_after_startup_but_update_faile
async def test_update_entity_not_present_without_dashboard(
hass: HomeAssistant, stub_reconnect, mock_config_entry, mock_device_info
hass: HomeAssistant,
mock_client: APIClient,
mock_esphome_device: Callable[
[APIClient, list[EntityInfo], list[UserService], list[EntityState]],
Awaitable[MockESPHomeDevice],
],
) -> None:
"""Test ESPHome update entity does not get created if there is no dashboard."""
with patch(
"homeassistant.components.esphome.update.DomainData.get_entry_data",
return_value=Mock(available=True, device_info=mock_device_info, info={}),
):
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
await mock_esphome_device(
mock_client=mock_client,
entity_info=[],
user_service=[],
states=[],
)
state = hass.states.get("update.none_firmware")
state = hass.states.get("update.test_firmware")
assert state is None