mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Switch on/off all lights, and wait for the result (#27078)
* Switch on/off all lights, and wait for the result
Reuses the parallel_updates semaphore.
This is a small crutch which serializes platforms which already do tis
for updates. Platforms which can parallelize everything, this makes it
go faster
* Fix broken unittest
With manual validation, with help from @frenck, we found out that the
assertions are wrong and the test should be failing.
The sequence requested is
OFF
ON
without cancelation, this code should result in:
off,off,off,on,on,on
testable, by adding a `await hass.async_block_till_done()` between the
off and on call.
with cancelation. there should be less off call's so
off,on,on,on
* Adding tests for async_request_call
* Process review feedback
* Switch gather with wait
* 👕 running black
This commit is contained in:
committed by
Paulus Schoutsen
parent
c7c88b2b68
commit
7a156059e9
@@ -551,6 +551,19 @@ class Entity:
|
||||
"""Return the representation."""
|
||||
return "<Entity {}: {}>".format(self.name, self.state)
|
||||
|
||||
# call an requests
|
||||
async def async_request_call(self, coro):
|
||||
"""Process request batched."""
|
||||
|
||||
if self.parallel_updates:
|
||||
await self.parallel_updates.acquire()
|
||||
|
||||
try:
|
||||
await coro
|
||||
finally:
|
||||
if self.parallel_updates:
|
||||
self.parallel_updates.release()
|
||||
|
||||
|
||||
class ToggleEntity(Entity):
|
||||
"""An abstract class for entities that can be turned on and off."""
|
||||
|
||||
Reference in New Issue
Block a user