Merge of nested IF-IF cases - Core (#48364)

This commit is contained in:
Franck Nijhof 2021-03-27 09:23:32 +01:00 committed by GitHub
parent ad13a9295e
commit 45f77ccccf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 25 deletions

View File

@ -77,17 +77,11 @@ class InsecureExampleModule(MultiFactorAuthModule):
async def async_is_user_setup(self, user_id: str) -> bool:
"""Return whether user is setup."""
for data in self._data:
if data["user_id"] == user_id:
return True
return False
return any(data["user_id"] == user_id for data in self._data)
async def async_validate(self, user_id: str, user_input: dict[str, Any]) -> bool:
"""Return True if validation passed."""
for data in self._data:
if data["user_id"] == user_id:
# user_input has been validate in caller
if data["pin"] == user_input["pin"]:
return True
return False
return any(
data["user_id"] == user_id and data["pin"] == user_input["pin"]
for data in self._data
)

View File

@ -134,11 +134,8 @@ class AreaRegistry:
normalized_name = normalize_area_name(name)
if normalized_name != old.normalized_name:
if self.async_get_area_by_name(name):
raise ValueError(
f"The name {name} ({normalized_name}) is already in use"
)
if normalized_name != old.normalized_name and self.async_get_area_by_name(name):
raise ValueError(f"The name {name} ({normalized_name}) is already in use")
changes["name"] = name
changes["normalized_name"] = normalized_name

View File

@ -315,10 +315,11 @@ async def async_prepare_setup_platform(
log_error(f"Unable to import the component ({exc}).")
return None
if hasattr(component, "setup") or hasattr(component, "async_setup"):
if not await async_setup_component(hass, integration.domain, hass_config):
log_error("Unable to set up component.")
return None
if (
hasattr(component, "setup") or hasattr(component, "async_setup")
) and not await async_setup_component(hass, integration.domain, hass_config):
log_error("Unable to set up component.")
return None
return platform

View File

@ -261,11 +261,10 @@ def color_xy_brightness_to_RGB(
vX: float, vY: float, ibrightness: int, Gamut: GamutType | None = None
) -> tuple[int, int, int]:
"""Convert from XYZ to RGB."""
if Gamut:
if not check_point_in_lamps_reach((vX, vY), Gamut):
xy_closest = get_closest_point_to_point((vX, vY), Gamut)
vX = xy_closest[0]
vY = xy_closest[1]
if Gamut and not check_point_in_lamps_reach((vX, vY), Gamut):
xy_closest = get_closest_point_to_point((vX, vY), Gamut)
vX = xy_closest[0]
vY = xy_closest[1]
brightness = ibrightness / 255.0
if brightness == 0.0: