Enable Ruff SIM401 (#86790)

* Enable Ruff SIM401

* Adjust found cases
This commit is contained in:
Franck Nijhof 2023-01-27 13:08:44 +01:00 committed by GitHub
parent bfbf9b9751
commit 8c993116e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 14 additions and 39 deletions

View file

@ -164,10 +164,7 @@ class BlackbirdZone(MediaPlayerEntity):
return return
self._attr_state = MediaPlayerState.ON if state.power else MediaPlayerState.OFF self._attr_state = MediaPlayerState.ON if state.power else MediaPlayerState.OFF
idx = state.av idx = state.av
if idx in self._source_id_name: self._attr_source = self._source_id_name.get(idx)
self._attr_source = self._source_id_name[idx]
else:
self._attr_source = None
@property @property
def media_title(self): def media_title(self):

View file

@ -71,16 +71,14 @@ class BlinkStickLight(LightEntity):
"""Turn the device on.""" """Turn the device on."""
if ATTR_HS_COLOR in kwargs: if ATTR_HS_COLOR in kwargs:
self._attr_hs_color = kwargs[ATTR_HS_COLOR] self._attr_hs_color = kwargs[ATTR_HS_COLOR]
if ATTR_BRIGHTNESS in kwargs:
self._attr_brightness = kwargs[ATTR_BRIGHTNESS] brightness: int = kwargs.get(ATTR_BRIGHTNESS, 255)
else: self._attr_brightness = brightness
self._attr_brightness = 255 self._attr_is_on = bool(brightness)
assert self.brightness is not None
self._attr_is_on = self.brightness > 0
assert self.hs_color assert self.hs_color
rgb_color = color_util.color_hsv_to_RGB( rgb_color = color_util.color_hsv_to_RGB(
self.hs_color[0], self.hs_color[1], self.brightness / 255 * 100 self.hs_color[0], self.hs_color[1], brightness / 255 * 100
) )
self._stick.set_color(red=rgb_color[0], green=rgb_color[1], blue=rgb_color[2]) self._stick.set_color(red=rgb_color[0], green=rgb_color[1], blue=rgb_color[2])

View file

@ -1333,10 +1333,7 @@ class ArmDisArmTrait(_Trait):
def query_attributes(self): def query_attributes(self):
"""Return ArmDisarm query attributes.""" """Return ArmDisarm query attributes."""
if "next_state" in self.state.attributes: armed_state = self.state.attributes.get("next_state", self.state.state)
armed_state = self.state.attributes["next_state"]
else:
armed_state = self.state.state
response = {"isArmed": armed_state in self.state_to_service} response = {"isArmed": armed_state in self.state_to_service}
if response["isArmed"]: if response["isArmed"]:
response.update({"currentArmLevel": armed_state}) response.update({"currentArmLevel": armed_state})

View file

@ -261,14 +261,8 @@ def setup(hass: HomeAssistant, base_config: ConfigType) -> bool: # noqa: C901
if ATTR_RAW in data: if ATTR_RAW in data:
command = CecCommand(data[ATTR_RAW]) command = CecCommand(data[ATTR_RAW])
else: else:
if ATTR_SRC in data: src = data.get(ATTR_SRC, ADDR_UNREGISTERED)
src = data[ATTR_SRC] dst = data.get(ATTR_DST, ADDR_BROADCAST)
else:
src = ADDR_UNREGISTERED
if ATTR_DST in data:
dst = data[ATTR_DST]
else:
dst = ADDR_BROADCAST
if ATTR_CMD in data: if ATTR_CMD in data:
cmd = data[ATTR_CMD] cmd = data[ATTR_CMD]
else: else:
@ -374,10 +368,7 @@ class CecEntity(Entity):
self._logical_address = logical self._logical_address = logical
self.entity_id = "%s.%d" % (DOMAIN, self._logical_address) self.entity_id = "%s.%d" % (DOMAIN, self._logical_address)
self._set_attr_name() self._set_attr_name()
if self._device.type in ICONS_BY_TYPE: self._attr_icon = ICONS_BY_TYPE.get(self._device.type, ICON_UNKNOWN)
self._attr_icon = ICONS_BY_TYPE[self._device.type]
else:
self._attr_icon = ICON_UNKNOWN
def _set_attr_name(self): def _set_attr_name(self):
"""Set name.""" """Set name."""

View file

@ -77,10 +77,7 @@ async def async_call_action_from_config(
data[ATTR_BRIGHTNESS_PCT] = config[ATTR_BRIGHTNESS_PCT] data[ATTR_BRIGHTNESS_PCT] = config[ATTR_BRIGHTNESS_PCT]
if config[CONF_TYPE] == TYPE_FLASH: if config[CONF_TYPE] == TYPE_FLASH:
if ATTR_FLASH in config: data[ATTR_FLASH] = config.get(ATTR_FLASH, FLASH_SHORT)
data[ATTR_FLASH] = config[ATTR_FLASH]
else:
data[ATTR_FLASH] = FLASH_SHORT
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_TURN_ON, data, blocking=True, context=context DOMAIN, SERVICE_TURN_ON, data, blocking=True, context=context

View file

@ -165,10 +165,7 @@ class MonopriceZone(MediaPlayerEntity):
self._attr_volume_level = state.volume / MAX_VOLUME self._attr_volume_level = state.volume / MAX_VOLUME
self._attr_is_volume_muted = state.mute self._attr_is_volume_muted = state.mute
idx = state.source idx = state.source
if idx in self._source_id_name: self._attr_source = self._source_id_name.get(idx)
self._attr_source = self._source_id_name[idx]
else:
self._attr_source = None
@property @property
def entity_registry_enabled_default(self) -> bool: def entity_registry_enabled_default(self) -> bool:

View file

@ -332,10 +332,7 @@ async def async_handle_waypoints_message(hass, context, message):
if user not in context.waypoint_whitelist: if user not in context.waypoint_whitelist:
return return
if "waypoints" in message: wayps = message.get("waypoints", [message])
wayps = message["waypoints"]
else:
wayps = [message]
_LOGGER.info("Got %d waypoints from %s", len(wayps), message["topic"]) _LOGGER.info("Got %d waypoints from %s", len(wayps), message["topic"])

View file

@ -252,6 +252,7 @@ select = [
"PGH004", # Use specific rule codes when using noqa "PGH004", # Use specific rule codes when using noqa
"SIM105", # Use contextlib.suppress({exception}) instead of try-except-pass "SIM105", # Use contextlib.suppress({exception}) instead of try-except-pass
"SIM117", # Merge with-statements that use the same scope "SIM117", # Merge with-statements that use the same scope
"SIM401", # Use get from dict with default instead of an if block
"T20", # flake8-print "T20", # flake8-print
"UP", # pyupgrade "UP", # pyupgrade
"W", # pycodestyle "W", # pycodestyle