mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Enable Ruff RUF018 (#115485)
This commit is contained in:
parent
1a9ff8c8fa
commit
223fefbbfa
@ -284,7 +284,8 @@ class APIEntityStateView(HomeAssistantView):
|
|||||||
|
|
||||||
# Read the state back for our response
|
# Read the state back for our response
|
||||||
status_code = HTTPStatus.CREATED if is_new_state else HTTPStatus.OK
|
status_code = HTTPStatus.CREATED if is_new_state else HTTPStatus.OK
|
||||||
assert (state := hass.states.get(entity_id))
|
state = hass.states.get(entity_id)
|
||||||
|
assert state
|
||||||
resp = self.json(state.as_dict(), status_code)
|
resp = self.json(state.as_dict(), status_code)
|
||||||
|
|
||||||
resp.headers.add("Location", f"/api/states/{entity_id}")
|
resp.headers.add("Location", f"/api/states/{entity_id}")
|
||||||
|
@ -517,13 +517,13 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa:
|
|||||||
params[ATTR_COLOR_TEMP_KELVIN]
|
params[ATTR_COLOR_TEMP_KELVIN]
|
||||||
)
|
)
|
||||||
elif ATTR_RGB_COLOR in params and ColorMode.RGB not in supported_color_modes:
|
elif ATTR_RGB_COLOR in params and ColorMode.RGB not in supported_color_modes:
|
||||||
assert (rgb_color := params.pop(ATTR_RGB_COLOR)) is not None
|
rgb_color = params.pop(ATTR_RGB_COLOR)
|
||||||
|
assert rgb_color is not None
|
||||||
if ColorMode.RGBW in supported_color_modes:
|
if ColorMode.RGBW in supported_color_modes:
|
||||||
params[ATTR_RGBW_COLOR] = color_util.color_rgb_to_rgbw(*rgb_color)
|
params[ATTR_RGBW_COLOR] = color_util.color_rgb_to_rgbw(*rgb_color)
|
||||||
elif ColorMode.RGBWW in supported_color_modes:
|
elif ColorMode.RGBWW in supported_color_modes:
|
||||||
# https://github.com/python/mypy/issues/13673
|
|
||||||
params[ATTR_RGBWW_COLOR] = color_util.color_rgb_to_rgbww(
|
params[ATTR_RGBWW_COLOR] = color_util.color_rgb_to_rgbww(
|
||||||
*rgb_color, # type: ignore[call-arg]
|
*rgb_color,
|
||||||
light.min_color_temp_kelvin,
|
light.min_color_temp_kelvin,
|
||||||
light.max_color_temp_kelvin,
|
light.max_color_temp_kelvin,
|
||||||
)
|
)
|
||||||
@ -584,9 +584,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa:
|
|||||||
elif (
|
elif (
|
||||||
ATTR_RGBWW_COLOR in params and ColorMode.RGBWW not in supported_color_modes
|
ATTR_RGBWW_COLOR in params and ColorMode.RGBWW not in supported_color_modes
|
||||||
):
|
):
|
||||||
assert (rgbww_color := params.pop(ATTR_RGBWW_COLOR)) is not None
|
rgbww_color = params.pop(ATTR_RGBWW_COLOR)
|
||||||
# https://github.com/python/mypy/issues/13673
|
assert rgbww_color is not None
|
||||||
rgb_color = color_util.color_rgbww_to_rgb( # type: ignore[call-arg]
|
rgb_color = color_util.color_rgbww_to_rgb(
|
||||||
*rgbww_color, light.min_color_temp_kelvin, light.max_color_temp_kelvin
|
*rgbww_color, light.min_color_temp_kelvin, light.max_color_temp_kelvin
|
||||||
)
|
)
|
||||||
if ColorMode.RGB in supported_color_modes:
|
if ColorMode.RGB in supported_color_modes:
|
||||||
|
@ -57,7 +57,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
|
|
||||||
async def _state_publisher(evt: Event[EventStateChangedData]) -> None:
|
async def _state_publisher(evt: Event[EventStateChangedData]) -> None:
|
||||||
entity_id = evt.data["entity_id"]
|
entity_id = evt.data["entity_id"]
|
||||||
assert (new_state := evt.data["new_state"])
|
new_state = evt.data["new_state"]
|
||||||
|
assert new_state
|
||||||
|
|
||||||
payload = new_state.state
|
payload = new_state.state
|
||||||
|
|
||||||
|
@ -167,7 +167,8 @@ class RingCam(RingEntity[RingDoorBell], Camera):
|
|||||||
def _get_video(self) -> str | None:
|
def _get_video(self) -> str | None:
|
||||||
if self._last_event is None:
|
if self._last_event is None:
|
||||||
return None
|
return None
|
||||||
assert (event_id := self._last_event.get("id")) and isinstance(event_id, int)
|
event_id = self._last_event.get("id")
|
||||||
|
assert event_id and isinstance(event_id, int)
|
||||||
return self._device.recording_url(event_id)
|
return self._device.recording_url(event_id)
|
||||||
|
|
||||||
@exception_wrap
|
@exception_wrap
|
||||||
|
@ -151,7 +151,8 @@ async def async_get_device_diagnostics(
|
|||||||
client: Client = hass.data[DOMAIN][config_entry.entry_id][DATA_CLIENT]
|
client: Client = hass.data[DOMAIN][config_entry.entry_id][DATA_CLIENT]
|
||||||
identifiers = get_home_and_node_id_from_device_entry(device)
|
identifiers = get_home_and_node_id_from_device_entry(device)
|
||||||
node_id = identifiers[1] if identifiers else None
|
node_id = identifiers[1] if identifiers else None
|
||||||
assert (driver := client.driver)
|
driver = client.driver
|
||||||
|
assert driver
|
||||||
if node_id is None or node_id not in driver.controller.nodes:
|
if node_id is None or node_id not in driver.controller.nodes:
|
||||||
raise ValueError(f"Node for device {device.id} can't be found")
|
raise ValueError(f"Node for device {device.id} can't be found")
|
||||||
node = driver.controller.nodes[node_id]
|
node = driver.controller.nodes[node_id]
|
||||||
|
@ -701,6 +701,7 @@ select = [
|
|||||||
"RUF005", # Consider iterable unpacking instead of concatenation
|
"RUF005", # Consider iterable unpacking instead of concatenation
|
||||||
"RUF006", # Store a reference to the return value of asyncio.create_task
|
"RUF006", # Store a reference to the return value of asyncio.create_task
|
||||||
"RUF013", # PEP 484 prohibits implicit Optional
|
"RUF013", # PEP 484 prohibits implicit Optional
|
||||||
|
"RUF018", # Avoid assignment expressions in assert statements
|
||||||
# "RUF100", # Unused `noqa` directive; temporarily every now and then to clean them up
|
# "RUF100", # Unused `noqa` directive; temporarily every now and then to clean them up
|
||||||
"S102", # Use of exec detected
|
"S102", # Use of exec detected
|
||||||
"S103", # bad-file-permissions
|
"S103", # bad-file-permissions
|
||||||
|
@ -6,6 +6,7 @@ extend = "../pyproject.toml"
|
|||||||
extend-ignore = [
|
extend-ignore = [
|
||||||
"B904", # Use raise from to specify exception cause
|
"B904", # Use raise from to specify exception cause
|
||||||
"N815", # Variable {name} in class scope should not be mixedCase
|
"N815", # Variable {name} in class scope should not be mixedCase
|
||||||
|
"RUF018", # Avoid assignment expressions in assert statements
|
||||||
]
|
]
|
||||||
|
|
||||||
[lint.isort]
|
[lint.isort]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user