mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Limit parallel requests to Philips Hue (#29189)
* Limit parallel requests to Philips Hue * Fix tests * Remove loop * Update homeassistant/components/hue/bridge.py Co-Authored-By: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
parent
a9baa24fda
commit
d91dd68b31
@ -33,6 +33,7 @@ class HueBridge:
|
|||||||
self.available = True
|
self.available = True
|
||||||
self.authorized = False
|
self.authorized = False
|
||||||
self.api = None
|
self.api = None
|
||||||
|
self.parallel_updates_semaphore = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def host(self):
|
def host(self):
|
||||||
@ -78,9 +79,19 @@ class HueBridge:
|
|||||||
DOMAIN, SERVICE_HUE_SCENE, self.hue_activate_scene, schema=SCENE_SCHEMA
|
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
|
self.authorized = True
|
||||||
return 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):
|
async def async_reset(self):
|
||||||
"""Reset this bridge to default state.
|
"""Reset this bridge to default state.
|
||||||
|
|
||||||
|
@ -202,7 +202,7 @@ async def async_update_items(
|
|||||||
try:
|
try:
|
||||||
start = monotonic()
|
start = monotonic()
|
||||||
with async_timeout.timeout(4):
|
with async_timeout.timeout(4):
|
||||||
await api.update()
|
await bridge.async_request_call(api.update())
|
||||||
except aiohue.Unauthorized:
|
except aiohue.Unauthorized:
|
||||||
await bridge.handle_unauthorized_error()
|
await bridge.handle_unauthorized_error()
|
||||||
return
|
return
|
||||||
@ -434,9 +434,9 @@ class HueLight(Light):
|
|||||||
command["effect"] = "none"
|
command["effect"] = "none"
|
||||||
|
|
||||||
if self.is_group:
|
if self.is_group:
|
||||||
await self.light.set_action(**command)
|
await self.bridge.async_request_call(self.light.set_action(**command))
|
||||||
else:
|
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):
|
async def async_turn_off(self, **kwargs):
|
||||||
"""Turn the specified or all lights off."""
|
"""Turn the specified or all lights off."""
|
||||||
@ -457,9 +457,9 @@ class HueLight(Light):
|
|||||||
command["alert"] = "none"
|
command["alert"] = "none"
|
||||||
|
|
||||||
if self.is_group:
|
if self.is_group:
|
||||||
await self.light.set_action(**command)
|
await self.bridge.async_request_call(self.light.set_action(**command))
|
||||||
else:
|
else:
|
||||||
await self.light.set_state(**command)
|
await self.bridge.async_request_call(self.light.set_state(**command))
|
||||||
|
|
||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Synchronize state with bridge."""
|
"""Synchronize state with bridge."""
|
||||||
|
@ -101,7 +101,7 @@ class SensorManager:
|
|||||||
try:
|
try:
|
||||||
start = monotonic()
|
start = monotonic()
|
||||||
with async_timeout.timeout(4):
|
with async_timeout.timeout(4):
|
||||||
await api.update()
|
await self.bridge.async_request_call(api.update())
|
||||||
except Unauthorized:
|
except Unauthorized:
|
||||||
await self.bridge.handle_unauthorized_error()
|
await self.bridge.handle_unauthorized_error()
|
||||||
return
|
return
|
||||||
|
@ -204,6 +204,10 @@ def mock_bridge(hass):
|
|||||||
return bridge.mock_group_responses.popleft()
|
return bridge.mock_group_responses.popleft()
|
||||||
return None
|
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.config.apiversion = "9.9.9"
|
||||||
bridge.api.lights = Lights({}, mock_request)
|
bridge.api.lights = Lights({}, mock_request)
|
||||||
bridge.api.groups = Groups({}, mock_request)
|
bridge.api.groups = Groups({}, mock_request)
|
||||||
|
@ -277,6 +277,10 @@ def create_mock_bridge():
|
|||||||
return bridge.mock_sensor_responses.popleft()
|
return bridge.mock_sensor_responses.popleft()
|
||||||
return None
|
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.config.apiversion = "9.9.9"
|
||||||
bridge.api.sensors = Sensors({}, mock_request)
|
bridge.api.sensors = Sensors({}, mock_request)
|
||||||
return bridge
|
return bridge
|
||||||
|
Loading…
x
Reference in New Issue
Block a user