diff --git a/homeassistant/components/hue/bridge.py b/homeassistant/components/hue/bridge.py index 9b7559a4efe..5a5e55773a5 100644 --- a/homeassistant/components/hue/bridge.py +++ b/homeassistant/components/hue/bridge.py @@ -33,6 +33,7 @@ class HueBridge: self.available = True self.authorized = False self.api = None + self.parallel_updates_semaphore = None @property def host(self): @@ -78,9 +79,19 @@ class HueBridge: DOMAIN, SERVICE_HUE_SCENE, self.hue_activate_scene, schema=SCENE_SCHEMA ) + self.parallel_updates_semaphore = asyncio.Semaphore( + 3 if self.api.config.modelid == "BSB001" else 10 + ) + self.authorized = True return True + async def async_request_call(self, coro): + """Process request batched.""" + + async with self.parallel_updates_semaphore: + return await coro + async def async_reset(self): """Reset this bridge to default state. diff --git a/homeassistant/components/hue/light.py b/homeassistant/components/hue/light.py index d58e4608b65..ad511639d57 100644 --- a/homeassistant/components/hue/light.py +++ b/homeassistant/components/hue/light.py @@ -202,7 +202,7 @@ async def async_update_items( try: start = monotonic() with async_timeout.timeout(4): - await api.update() + await bridge.async_request_call(api.update()) except aiohue.Unauthorized: await bridge.handle_unauthorized_error() return @@ -434,9 +434,9 @@ class HueLight(Light): command["effect"] = "none" if self.is_group: - await self.light.set_action(**command) + await self.bridge.async_request_call(self.light.set_action(**command)) else: - await self.light.set_state(**command) + await self.bridge.async_request_call(self.light.set_state(**command)) async def async_turn_off(self, **kwargs): """Turn the specified or all lights off.""" @@ -457,9 +457,9 @@ class HueLight(Light): command["alert"] = "none" if self.is_group: - await self.light.set_action(**command) + await self.bridge.async_request_call(self.light.set_action(**command)) else: - await self.light.set_state(**command) + await self.bridge.async_request_call(self.light.set_state(**command)) async def async_update(self): """Synchronize state with bridge.""" diff --git a/homeassistant/components/hue/sensor_base.py b/homeassistant/components/hue/sensor_base.py index bf64fed0c95..f7882b102c0 100644 --- a/homeassistant/components/hue/sensor_base.py +++ b/homeassistant/components/hue/sensor_base.py @@ -101,7 +101,7 @@ class SensorManager: try: start = monotonic() with async_timeout.timeout(4): - await api.update() + await self.bridge.async_request_call(api.update()) except Unauthorized: await self.bridge.handle_unauthorized_error() return diff --git a/tests/components/hue/test_light.py b/tests/components/hue/test_light.py index 88c527a50ca..5b10ff9446c 100644 --- a/tests/components/hue/test_light.py +++ b/tests/components/hue/test_light.py @@ -204,6 +204,10 @@ def mock_bridge(hass): return bridge.mock_group_responses.popleft() return None + async def async_request_call(coro): + await coro + + bridge.async_request_call = async_request_call bridge.api.config.apiversion = "9.9.9" bridge.api.lights = Lights({}, mock_request) bridge.api.groups = Groups({}, mock_request) diff --git a/tests/components/hue/test_sensor_base.py b/tests/components/hue/test_sensor_base.py index ba259dccf71..ad927767c30 100644 --- a/tests/components/hue/test_sensor_base.py +++ b/tests/components/hue/test_sensor_base.py @@ -277,6 +277,10 @@ def create_mock_bridge(): return bridge.mock_sensor_responses.popleft() return None + async def async_request_call(coro): + await coro + + bridge.async_request_call = async_request_call bridge.api.config.apiversion = "9.9.9" bridge.api.sensors = Sensors({}, mock_request) return bridge