Inverse parallel updates default check, follow sync "update" method (#71720)
This commit is contained in:
parent
1a6ccdbf59
commit
3b88c6c012
2 changed files with 22 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Add table
Reference in a new issue