Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8c99311

Browse files
authored
Enable Ruff SIM401 (home-assistant#86790)
* Enable Ruff SIM401 * Adjust found cases
1 parent bfbf9b9 commit 8c99311

File tree

8 files changed

+14
-39
lines changed

8 files changed

+14
-39
lines changed

‎homeassistant/components/blackbird/media_player.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,7 @@ def update(self) -> None:
164164
return
165165
self._attr_state = MediaPlayerState.ON if state.power else MediaPlayerState.OFF
166166
idx = state.av
167-
if idx in self._source_id_name:
168-
self._attr_source = self._source_id_name[idx]
169-
else:
170-
self._attr_source = None
167+
self._attr_source = self._source_id_name.get(idx)
171168

172169
@property
173170
def media_title(self):

‎homeassistant/components/blinksticklight/light.py‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,14 @@ def turn_on(self, **kwargs: Any) -> None:
7171
"""Turn the device on."""
7272
if ATTR_HS_COLOR in kwargs:
7373
self._attr_hs_color = kwargs[ATTR_HS_COLOR]
74-
if ATTR_BRIGHTNESS in kwargs:
75-
self._attr_brightness = kwargs[ATTR_BRIGHTNESS]
76-
else:
77-
self._attr_brightness = 255
78-
assert self.brightness is not None
79-
self._attr_is_on = self.brightness > 0
74+
75+
brightness: int = kwargs.get(ATTR_BRIGHTNESS, 255)
76+
self._attr_brightness = brightness
77+
self._attr_is_on = bool(brightness)
8078

8179
assert self.hs_color
8280
rgb_color = color_util.color_hsv_to_RGB(
83-
self.hs_color[0], self.hs_color[1], self.brightness / 255 * 100
81+
self.hs_color[0], self.hs_color[1], brightness / 255 * 100
8482
)
8583
self._stick.set_color(red=rgb_color[0], green=rgb_color[1], blue=rgb_color[2])
8684

‎homeassistant/components/google_assistant/trait.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,10 +1333,7 @@ def sync_attributes(self):
13331333

13341334
def query_attributes(self):
13351335
"""Return ArmDisarm query attributes."""
1336-
if "next_state" in self.state.attributes:
1337-
armed_state = self.state.attributes["next_state"]
1338-
else:
1339-
armed_state = self.state.state
1336+
armed_state = self.state.attributes.get("next_state", self.state.state)
13401337
response = {"isArmed": armed_state in self.state_to_service}
13411338
if response["isArmed"]:
13421339
response.update({"currentArmLevel": armed_state})

‎homeassistant/components/hdmi_cec/__init__.py‎

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,8 @@ def _tx(call: ServiceCall) -> None:
261261
if ATTR_RAW in data:
262262
command = CecCommand(data[ATTR_RAW])
263263
else:
264-
if ATTR_SRC in data:
265-
src = data[ATTR_SRC]
266-
else:
267-
src = ADDR_UNREGISTERED
268-
if ATTR_DST in data:
269-
dst = data[ATTR_DST]
270-
else:
271-
dst = ADDR_BROADCAST
264+
src = data.get(ATTR_SRC, ADDR_UNREGISTERED)
265+
dst = data.get(ATTR_DST, ADDR_BROADCAST)
272266
if ATTR_CMD in data:
273267
cmd = data[ATTR_CMD]
274268
else:
@@ -374,10 +368,7 @@ def __init__(self, device, logical) -> None:
374368
self._logical_address = logical
375369
self.entity_id = "%s.%d" % (DOMAIN, self._logical_address)
376370
self._set_attr_name()
377-
if self._device.type in ICONS_BY_TYPE:
378-
self._attr_icon = ICONS_BY_TYPE[self._device.type]
379-
else:
380-
self._attr_icon = ICON_UNKNOWN
371+
self._attr_icon = ICONS_BY_TYPE.get(self._device.type, ICON_UNKNOWN)
381372

382373
def _set_attr_name(self):
383374
"""Set name."""

‎homeassistant/components/light/device_action.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,7 @@ async def async_call_action_from_config(
7777
data[ATTR_BRIGHTNESS_PCT] = config[ATTR_BRIGHTNESS_PCT]
7878

7979
if config[CONF_TYPE] == TYPE_FLASH:
80-
if ATTR_FLASH in config:
81-
data[ATTR_FLASH] = config[ATTR_FLASH]
82-
else:
83-
data[ATTR_FLASH] = FLASH_SHORT
80+
data[ATTR_FLASH] = config.get(ATTR_FLASH, FLASH_SHORT)
8481

8582
await hass.services.async_call(
8683
DOMAIN, SERVICE_TURN_ON, data, blocking=True, context=context

‎homeassistant/components/monoprice/media_player.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,7 @@ def update(self) -> None:
165165
self._attr_volume_level = state.volume / MAX_VOLUME
166166
self._attr_is_volume_muted = state.mute
167167
idx = state.source
168-
if idx in self._source_id_name:
169-
self._attr_source = self._source_id_name[idx]
170-
else:
171-
self._attr_source = None
168+
self._attr_source = self._source_id_name.get(idx)
172169

173170
@property
174171
def entity_registry_enabled_default(self) -> bool:

‎homeassistant/components/owntracks/messages.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,7 @@ async def async_handle_waypoints_message(hass, context, message):
332332
if user not in context.waypoint_whitelist:
333333
return
334334

335-
if "waypoints" in message:
336-
wayps = message["waypoints"]
337-
else:
338-
wayps = [message]
335+
wayps = message.get("waypoints", [message])
339336

340337
_LOGGER.info("Got %d waypoints from %s", len(wayps), message["topic"])
341338

‎pyproject.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ select = [
252252
"PGH004", # Use specific rule codes when using noqa
253253
"SIM105", # Use contextlib.suppress({exception}) instead of try-except-pass
254254
"SIM117", # Merge with-statements that use the same scope
255+
"SIM401", # Use get from dict with default instead of an if block
255256
"T20", # flake8-print
256257
"UP", # pyupgrade
257258
"W", # pycodestyle

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /