Use asyncio.timeout [b-e] (#98448)

This commit is contained in:
Marc Mueller 2023-08-15 15:30:20 +02:00 committed by GitHub
parent 346a7292d7
commit e2d2ec8817
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 53 additions and 71 deletions

View file

@ -1,10 +1,9 @@
"""Light platform for Evil Genius Light."""
from __future__ import annotations
import asyncio
from typing import Any, cast
from async_timeout import timeout
from homeassistant.components import light
from homeassistant.components.light import ColorMode, LightEntity, LightEntityFeature
from homeassistant.config_entries import ConfigEntry
@ -89,27 +88,27 @@ class EvilGeniusLight(EvilGeniusEntity, LightEntity):
) -> None:
"""Turn light on."""
if (brightness := kwargs.get(light.ATTR_BRIGHTNESS)) is not None:
async with timeout(5):
async with asyncio.timeout(5):
await self.coordinator.client.set_path_value("brightness", brightness)
# Setting a color will change the effect to "Solid Color" so skip setting effect
if (rgb_color := kwargs.get(light.ATTR_RGB_COLOR)) is not None:
async with timeout(5):
async with asyncio.timeout(5):
await self.coordinator.client.set_rgb_color(*rgb_color)
elif (effect := kwargs.get(light.ATTR_EFFECT)) is not None:
if effect == HA_NO_EFFECT:
effect = FIB_NO_EFFECT
async with timeout(5):
async with asyncio.timeout(5):
await self.coordinator.client.set_path_value(
"pattern", self.coordinator.data["pattern"]["options"].index(effect)
)
async with timeout(5):
async with asyncio.timeout(5):
await self.coordinator.client.set_path_value("power", 1)
@update_when_done
async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn light off."""
async with timeout(5):
async with asyncio.timeout(5):
await self.coordinator.client.set_path_value("power", 0)