Create entities directly on setup in Meater (#146953)

* Don't wait an update when adding devices in Meater

* Fix
This commit is contained in:
Joost Lekkerkerker 2025-06-16 18:23:20 +02:00 committed by GitHub
parent dffaf49eca
commit 9ae0cfc7e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 5 additions and 17 deletions

View File

@ -170,6 +170,7 @@ async def async_setup_entry(
# Add a subscriber to the coordinator to discover new temperature probes # Add a subscriber to the coordinator to discover new temperature probes
coordinator.async_add_listener(async_update_data) coordinator.async_add_listener(async_update_data)
async_update_data()
class MeaterProbeTemperature(SensorEntity, CoordinatorEntity[MeaterCoordinator]): class MeaterProbeTemperature(SensorEntity, CoordinatorEntity[MeaterCoordinator]):

View File

@ -303,7 +303,7 @@
'last_changed': <ANY>, 'last_changed': <ANY>,
'last_reported': <ANY>, 'last_reported': <ANY>,
'last_updated': <ANY>, 'last_updated': <ANY>,
'state': '2023-10-20T23:59:58+00:00', 'state': '2023-10-20T23:59:28+00:00',
}) })
# --- # ---
# name: test_entities[sensor.meater_40a72384fa80349314dfd97c84b73a5c1c9da57b59e26d67b573d618fe0d6e58_cook_time_remaining-entry] # name: test_entities[sensor.meater_40a72384fa80349314dfd97c84b73a5c1c9da57b59e26d67b573d618fe0d6e58_cook_time_remaining-entry]
@ -351,7 +351,7 @@
'last_changed': <ANY>, 'last_changed': <ANY>,
'last_reported': <ANY>, 'last_reported': <ANY>,
'last_updated': <ANY>, 'last_updated': <ANY>,
'state': '2023-10-21T00:01:02+00:00', 'state': '2023-10-21T00:00:32+00:00',
}) })
# --- # ---
# name: test_entities[sensor.meater_40a72384fa80349314dfd97c84b73a5c1c9da57b59e26d67b573d618fe0d6e58_internal-entry] # name: test_entities[sensor.meater_40a72384fa80349314dfd97c84b73a5c1c9da57b59e26d67b573d618fe0d6e58_internal-entry]

View File

@ -1,9 +1,7 @@
"""Tests for the Meater integration.""" """Tests for the Meater integration."""
from datetime import timedelta
from unittest.mock import AsyncMock from unittest.mock import AsyncMock
from freezegun.api import FrozenDateTimeFactory
from syrupy.assertion import SnapshotAssertion from syrupy.assertion import SnapshotAssertion
from homeassistant.components.meater.const import DOMAIN from homeassistant.components.meater.const import DOMAIN
@ -13,7 +11,7 @@ from homeassistant.helpers import device_registry as dr
from . import setup_integration from . import setup_integration
from .const import PROBE_ID from .const import PROBE_ID
from tests.common import MockConfigEntry, async_fire_time_changed from tests.common import MockConfigEntry
async def test_device_info( async def test_device_info(
@ -22,13 +20,9 @@ async def test_device_info(
mock_meater_client: AsyncMock, mock_meater_client: AsyncMock,
mock_config_entry: MockConfigEntry, mock_config_entry: MockConfigEntry,
device_registry: dr.DeviceRegistry, device_registry: dr.DeviceRegistry,
freezer: FrozenDateTimeFactory,
) -> None: ) -> None:
"""Test device registry integration.""" """Test device registry integration."""
await setup_integration(hass, mock_config_entry) await setup_integration(hass, mock_config_entry)
freezer.tick(timedelta(seconds=30))
async_fire_time_changed(hass)
await hass.async_block_till_done()
device_entry = device_registry.async_get_device(identifiers={(DOMAIN, PROBE_ID)}) device_entry = device_registry.async_get_device(identifiers={(DOMAIN, PROBE_ID)})
assert device_entry is not None assert device_entry is not None
assert device_entry == snapshot assert device_entry == snapshot

View File

@ -1,9 +1,7 @@
"""Tests for the Meater sensors.""" """Tests for the Meater sensors."""
from datetime import timedelta
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
from freezegun.api import FrozenDateTimeFactory
import pytest import pytest
from syrupy.assertion import SnapshotAssertion from syrupy.assertion import SnapshotAssertion
@ -13,7 +11,7 @@ from homeassistant.helpers import entity_registry as er
from . import setup_integration from . import setup_integration
from tests.common import MockConfigEntry, async_fire_time_changed, snapshot_platform from tests.common import MockConfigEntry, snapshot_platform
@pytest.mark.freeze_time("2023-10-21") @pytest.mark.freeze_time("2023-10-21")
@ -23,14 +21,9 @@ async def test_entities(
entity_registry: er.EntityRegistry, entity_registry: er.EntityRegistry,
mock_meater_client: AsyncMock, mock_meater_client: AsyncMock,
mock_config_entry: MockConfigEntry, mock_config_entry: MockConfigEntry,
freezer: FrozenDateTimeFactory,
) -> None: ) -> None:
"""Test the sensor entities.""" """Test the sensor entities."""
with patch("homeassistant.components.meater.PLATFORMS", [Platform.SENSOR]): with patch("homeassistant.components.meater.PLATFORMS", [Platform.SENSOR]):
await setup_integration(hass, mock_config_entry) await setup_integration(hass, mock_config_entry)
freezer.tick(timedelta(seconds=30))
async_fire_time_changed(hass)
await hass.async_block_till_done()
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id) await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)