From 3b88c6c0126c8b019322fecd9e8547cc2b6e8b60 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 16 May 2022 17:10:34 -0700 Subject: [PATCH] Inverse parallel updates default check, follow sync "update" method (#71720) --- homeassistant/helpers/entity_platform.py | 6 +++--- tests/helpers/test_entity_platform.py | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/homeassistant/helpers/entity_platform.py b/homeassistant/helpers/entity_platform.py index 3d57a9c3dc0..ecf2125962a 100644 --- a/homeassistant/helpers/entity_platform.py +++ b/homeassistant/helpers/entity_platform.py @@ -120,7 +120,7 @@ class EntityPlatform: @callback def _get_parallel_updates_semaphore( - self, entity_has_async_update: bool + self, entity_has_sync_update: bool ) -> asyncio.Semaphore | None: """Get or create a semaphore for parallel updates. @@ -138,7 +138,7 @@ class EntityPlatform: parallel_updates = getattr(self.platform, "PARALLEL_UPDATES", None) - if parallel_updates is None and not entity_has_async_update: + if parallel_updates is None and entity_has_sync_update: parallel_updates = 1 if parallel_updates == 0: @@ -422,7 +422,7 @@ class EntityPlatform: entity.add_to_platform_start( self.hass, self, - self._get_parallel_updates_semaphore(hasattr(entity, "async_update")), + self._get_parallel_updates_semaphore(hasattr(entity, "update")), ) # Update properties before we generate the entity_id diff --git a/tests/helpers/test_entity_platform.py b/tests/helpers/test_entity_platform.py index 3f18d565e83..933669ebc53 100644 --- a/tests/helpers/test_entity_platform.py +++ b/tests/helpers/test_entity_platform.py @@ -332,6 +332,25 @@ async def test_parallel_updates_sync_platform(hass): assert entity.parallel_updates._value == 1 +async def test_parallel_updates_no_update_method(hass): + """Test platform parallel_updates default set to 0.""" + platform = MockPlatform() + + mock_entity_platform(hass, "test_domain.platform", platform) + + component = EntityComponent(_LOGGER, DOMAIN, hass) + component._platforms = {} + + await component.async_setup({DOMAIN: {"platform": "platform"}}) + await hass.async_block_till_done() + + handle = list(component._platforms.values())[-1] + + entity = MockEntity() + await handle.async_add_entities([entity]) + assert entity.parallel_updates is None + + async def test_parallel_updates_sync_platform_with_constant(hass): """Test sync platform can set parallel_updates limit.""" platform = MockPlatform()