Skip to content

Commit

Permalink
Enable ruff RUF005 and fix occurrences (home-assistant#113589)
Browse files Browse the repository at this point in the history
  • Loading branch information
autinerd authored Mar 16, 2024
1 parent 2a5c85a commit ccd2e98
Show file tree
Hide file tree
Showing 58 changed files with 150 additions and 128 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/advantage_air/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
HVACMode.FAN_ONLY,
HVACMode.DRY,
]
HVAC_MODES_MYAUTO = HVAC_MODES + [HVACMode.HEAT_COOL]
HVAC_MODES_MYAUTO = [*HVAC_MODES, HVACMode.HEAT_COOL]
SUPPORTED_FEATURES = (
ClimateEntityFeature.FAN_MODE
| ClimateEntityFeature.TURN_OFF
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/android_ip_webcam/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ async def async_setup_entry(
sensor
for sensor in SENSOR_TYPES
if sensor.key
in coordinator.cam.enabled_sensors + ["audio_connections", "video_connections"]
in [*coordinator.cam.enabled_sensors, "audio_connections", "video_connections"]
]
async_add_entities(
IPWebcamSensor(coordinator, description) for description in sensor_types
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/androidtv/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def _async_init_form(self) -> ConfigFlowResult:
apps = [SelectOptionDict(value=APPS_NEW_ID, label="Add new")] + [
SelectOptionDict(value=k, label=v) for k, v in apps_list.items()
]
rules = [RULES_NEW_ID] + list(self._state_det_rules)
rules = [RULES_NEW_ID, *self._state_det_rules]
options = self.options

data_schema = vol.Schema(
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ async def get(self, request: web.Request) -> web.StreamResponse:

restrict: list[str] | None = None
if restrict_str := request.query.get("restrict"):
restrict = restrict_str.split(",") + [EVENT_HOMEASSISTANT_STOP]
restrict = [*restrict_str.split(","), EVENT_HOMEASSISTANT_STOP]

async def forward_events(event: Event) -> None:
"""Forward events to the open request."""
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/aussie_broadband/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
)

# Ignore services that don't support usage data
ignore_types = FETCH_TYPES + ["Hardware"]
ignore_types = [*FETCH_TYPES, "Hardware"]

try:
await client.login()
Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/demo/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,7 @@ def set_repeat(self, repeat: RepeatMode) -> None:

def join_players(self, group_members: list[str]) -> None:
"""Join `group_members` as a player group with the current player."""
self._attr_group_members = [
self.entity_id,
] + group_members
self._attr_group_members = [self.entity_id, *group_members]
self.schedule_update_ha_state()

def unjoin_player(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/generic_thermostat/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def __init__(
)
if len(presets):
self._attr_supported_features |= ClimateEntityFeature.PRESET_MODE
self._attr_preset_modes = [PRESET_NONE] + list(presets.keys())
self._attr_preset_modes = [PRESET_NONE, *presets.keys()]
else:
self._attr_preset_modes = [PRESET_NONE]
self._presets = presets
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/google_assistant/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ def sync_serialize(self, agent_user_id, instance_uuid):
if (config_aliases := entity_config.get(CONF_ALIASES, [])) or (
entity_entry and entity_entry.aliases
):
device["name"]["nicknames"] = [name] + config_aliases
device["name"]["nicknames"] = [name, *config_aliases]
if entity_entry:
device["name"]["nicknames"].extend(entity_entry.aliases)

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/harmony/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self, name: str, data: HarmonyData) -> None:
@property
def options(self) -> list[str]:
"""Return a set of selectable options."""
return [TRANSLATABLE_POWER_OFF] + sorted(self._data.activity_names)
return [TRANSLATABLE_POWER_OFF, *sorted(self._data.activity_names)]

@property
def current_option(self) -> str | None:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/hdmi_cec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def parse_mapping(mapping, parents=None):
if isinstance(addr, (str,)) and isinstance(val, (str,)):
yield (addr, PhysicalAddress(val))
else:
cur = parents + [addr]
cur = [*parents, addr]
if isinstance(val, dict):
yield from parse_mapping(val, cur)
elif isinstance(val, str):
Expand Down
6 changes: 4 additions & 2 deletions homeassistant/components/homekit_controller/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ def _async_reconfigure(self) -> None:

def get_characteristic_types(self) -> list[str]:
"""Define the homekit characteristics the entity cares about."""
return super().get_characteristic_types() + [
return [
*super().get_characteristic_types(),
CharacteristicsTypes.ACTIVE,
CharacteristicsTypes.CURRENT_HEATER_COOLER_STATE,
CharacteristicsTypes.TARGET_HEATER_COOLER_STATE,
Expand Down Expand Up @@ -479,7 +480,8 @@ def _async_reconfigure(self) -> None:

def get_characteristic_types(self) -> list[str]:
"""Define the homekit characteristics the entity cares about."""
return super().get_characteristic_types() + [
return [
*super().get_characteristic_types(),
CharacteristicsTypes.HEATING_COOLING_CURRENT,
CharacteristicsTypes.HEATING_COOLING_TARGET,
CharacteristicsTypes.TEMPERATURE_COOLING_THRESHOLD,
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/homekit_controller/humidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ def __init__(self, accessory: HKDevice, devinfo: ConfigType) -> None:

def get_characteristic_types(self) -> list[str]:
"""Define the homekit characteristics the entity cares about."""
return super().get_characteristic_types() + [
CharacteristicsTypes.RELATIVE_HUMIDITY_DEHUMIDIFIER_THRESHOLD
return [
*super().get_characteristic_types(),
CharacteristicsTypes.RELATIVE_HUMIDITY_DEHUMIDIFIER_THRESHOLD,
]

@property
Expand Down
20 changes: 11 additions & 9 deletions homeassistant/components/isy994/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 +214,21 @@
"7.13.",
TYPE_CATEGORY_SAFETY,
], # Does a startswith() match; include the dot
FILTER_ZWAVE_CAT: (["104", "112", "138"] + list(map(str, range(148, 180)))),
FILTER_ZWAVE_CAT: (["104", "112", "138", *map(str, range(148, 180))]),
},
Platform.SENSOR: {
# This is just a more-readable way of including MOST uoms between 1-100
# (Remember that range() is non-inclusive of the stop value)
FILTER_UOM: (
["1"]
+ list(map(str, range(3, 11)))
+ list(map(str, range(12, 51)))
+ list(map(str, range(52, 66)))
+ list(map(str, range(69, 78)))
+ ["79"]
+ list(map(str, range(82, 97)))
[
"1",
*map(str, range(3, 11)),
*map(str, range(12, 51)),
*map(str, range(52, 66)),
*map(str, range(69, 78)),
"79",
*map(str, range(82, 97)),
]
),
FILTER_STATES: [],
FILTER_NODE_DEF_ID: [
Expand All @@ -238,7 +240,7 @@
"RemoteLinc2_ADV",
],
FILTER_INSTEON_TYPE: ["0.16.", "0.17.", "0.18.", "9.0.", "9.7."],
FILTER_ZWAVE_CAT: (["118", "143"] + list(map(str, range(180, 186)))),
FILTER_ZWAVE_CAT: (["118", "143", *map(str, range(180, 186))]),
},
Platform.LOCK: {
FILTER_UOM: ["11"],
Expand Down
11 changes: 6 additions & 5 deletions homeassistant/components/konnected/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,10 @@ async def async_step_options_binary(self, user_input=None):
if user_input is not None:
zone = {"zone": self.active_cfg}
zone.update(user_input)
self.new_opt[CONF_BINARY_SENSORS] = self.new_opt.get(
CONF_BINARY_SENSORS, []
) + [zone]
self.new_opt[CONF_BINARY_SENSORS] = [
*self.new_opt.get(CONF_BINARY_SENSORS, []),
zone,
]
self.io_cfg.pop(self.active_cfg)
self.active_cfg = None

Expand Down Expand Up @@ -645,7 +646,7 @@ async def async_step_options_digital(self, user_input=None):
if user_input is not None:
zone = {"zone": self.active_cfg}
zone.update(user_input)
self.new_opt[CONF_SENSORS] = self.new_opt.get(CONF_SENSORS, []) + [zone]
self.new_opt[CONF_SENSORS] = [*self.new_opt.get(CONF_SENSORS, []), zone]
self.io_cfg.pop(self.active_cfg)
self.active_cfg = None

Expand Down Expand Up @@ -714,7 +715,7 @@ async def async_step_options_switch(self, user_input=None):
zone = {"zone": self.active_cfg}
zone.update(user_input)
del zone[CONF_MORE_STATES]
self.new_opt[CONF_SWITCHES] = self.new_opt.get(CONF_SWITCHES, []) + [zone]
self.new_opt[CONF_SWITCHES] = [*self.new_opt.get(CONF_SWITCHES, []), zone]

# iterate through multiple switch states
if self.current_states:
Expand Down
24 changes: 11 additions & 13 deletions homeassistant/components/ld2410_ble/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,17 @@
for i in range(0, 9)
]

SENSOR_DESCRIPTIONS = (
[
MOVING_TARGET_DISTANCE_DESCRIPTION,
STATIC_TARGET_DISTANCE_DESCRIPTION,
MOVING_TARGET_ENERGY_DESCRIPTION,
STATIC_TARGET_ENERGY_DESCRIPTION,
DETECTION_DISTANCE_DESCRIPTION,
MAX_MOTION_GATES_DESCRIPTION,
MAX_STATIC_GATES_DESCRIPTION,
]
+ MOTION_ENERGY_GATES
+ STATIC_ENERGY_GATES
)
SENSOR_DESCRIPTIONS = [
MOVING_TARGET_DISTANCE_DESCRIPTION,
STATIC_TARGET_DISTANCE_DESCRIPTION,
MOVING_TARGET_ENERGY_DESCRIPTION,
STATIC_TARGET_ENERGY_DESCRIPTION,
DETECTION_DISTANCE_DESCRIPTION,
MAX_MOTION_GATES_DESCRIPTION,
MAX_STATIC_GATES_DESCRIPTION,
*MOTION_ENERGY_GATES,
*STATIC_ENERGY_GATES,
]


async def async_setup_entry(
Expand Down
8 changes: 6 additions & 2 deletions homeassistant/components/light/device_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@
vol.Required(ATTR_ENTITY_ID): cv.entity_id_or_uuid,
vol.Required(CONF_DOMAIN): DOMAIN,
vol.Required(CONF_TYPE): vol.In(
toggle_entity.DEVICE_ACTION_TYPES
+ [TYPE_BRIGHTNESS_INCREASE, TYPE_BRIGHTNESS_DECREASE, TYPE_FLASH]
[
*toggle_entity.DEVICE_ACTION_TYPES,
TYPE_BRIGHTNESS_INCREASE,
TYPE_BRIGHTNESS_DECREASE,
TYPE_FLASH,
]
),
vol.Optional(ATTR_BRIGHTNESS_PCT): VALID_BRIGHTNESS_PCT,
vol.Optional(ATTR_FLASH): VALID_FLASH,
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/mqtt/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ async def _async_validate_broker_settings(
)
schema = vol.Schema({cv.string: cv.template})
schema(validated_user_input[CONF_WS_HEADERS])
except JSON_DECODE_EXCEPTIONS + (vol.MultipleInvalid,):
except (*JSON_DECODE_EXCEPTIONS, vol.MultipleInvalid):
errors["base"] = "bad_ws_headers"
return False
return True
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/network/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ async def async_get_announce_addresses(hass: HomeAssistant) -> list[str]:
if default_ip := await async_get_source_ip(hass, target_ip=MDNS_TARGET_IP):
if default_ip in addresses:
addresses.remove(default_ip)
return [default_ip] + list(addresses)
return [default_ip, *addresses]
return list(addresses)


Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/omnilogic/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def get_item_data(item, item_kind, current_id, data):

if "systemId" in item:
system_id = item["systemId"]
current_id = current_id + (item_kind, system_id)
current_id = (*current_id, item_kind, system_id)
data[current_id] = item

for kind in ALL_ITEM_KINDS:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/person/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ async def async_add_user_device_tracker(

await coll.async_update_item(
person[CONF_ID],
{CONF_DEVICE_TRACKERS: device_trackers + [device_tracker_entity_id]},
{CONF_DEVICE_TRACKERS: [*device_trackers, device_tracker_entity_id]},
)
break

Expand Down
6 changes: 4 additions & 2 deletions homeassistant/components/proximity/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@ async def async_check_tracked_entity_change(
**self.config_entry.data,
CONF_TRACKED_ENTITIES: [
tracked_entity
for tracked_entity in self.tracked_entities
+ [new_tracked_entity_id]
for tracked_entity in (
*self.tracked_entities,
new_tracked_entity_id,
)
if tracked_entity != old_tracked_entity_id
],
},
Expand Down
9 changes: 6 additions & 3 deletions homeassistant/components/roku/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,12 @@ def source(self) -> str | None:
@property
def source_list(self) -> list[str]:
"""List of available input sources."""
return ["Home"] + sorted(
app.name for app in self.coordinator.data.apps if app.name is not None
)
return [
"Home",
*sorted(
app.name for app in self.coordinator.data.apps if app.name is not None
),
]

@roku_exception_handler()
async def search(self, keyword: str) -> None:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/roku/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def _get_application_name(device: RokuDevice) -> str | None:


def _get_applications(device: RokuDevice) -> list[str]:
return ["Home"] + sorted(app.name for app in device.apps if app.name is not None)
return ["Home", *sorted(app.name for app in device.apps if app.name is not None)]


def _get_channel_name(device: RokuDevice) -> str | None:
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/sense/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def __init__(self, name, sensor_type):
SENSOR_VARIANTS = [(PRODUCTION_ID, PRODUCTION_NAME), (CONSUMPTION_ID, CONSUMPTION_NAME)]

# Trend production/consumption variants
TREND_SENSOR_VARIANTS = SENSOR_VARIANTS + [
TREND_SENSOR_VARIANTS = [
*SENSOR_VARIANTS,
(PRODUCTION_PCT_ID, PRODUCTION_PCT_NAME),
(NET_PRODUCTION_ID, NET_PRODUCTION_NAME),
(FROM_GRID_ID, FROM_GRID_NAME),
Expand Down
16 changes: 8 additions & 8 deletions homeassistant/components/seven_segments/image_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ def __init__(self, hass, camera_entity, config, name):
threshold = ["-t", str(config[CONF_THRESHOLD])]
extra_arguments = config[CONF_EXTRA_ARGUMENTS].split(" ")

self._command = (
[config[CONF_SSOCR_BIN]]
+ crop
+ digits
+ threshold
+ rotate
+ extra_arguments
)
self._command = [
config[CONF_SSOCR_BIN],
*crop,
*digits,
*threshold,
*rotate,
*extra_arguments,
]
self._command.append(self.filepath)

@property
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/shell_command/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async def async_service_handler(service: ServiceCall) -> ServiceResponse:
else:
# Template used. Break into list and use create_subprocess_exec
# (which uses shell=False) for security
shlexed_cmd = [prog] + shlex.split(rendered_args)
shlexed_cmd = [prog, *shlex.split(rendered_args)]

create_process = asyncio.create_subprocess_exec(
*shlexed_cmd,
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/smartthings/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def get_capabilities(capabilities: Sequence[str]) -> Sequence[str] | None:
# Must have one of the min_required
if any(capability in capabilities for capability in min_required):
# Return all capabilities supported/consumed
return min_required + [
return [
*min_required,
Capability.battery,
Capability.switch_level,
Capability.window_shade_level,
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/sonos/speaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ def _get_soco_group() -> list[str]:
if p.uid != coordinator_uid and p.is_visible
]

return [coordinator_uid] + joined_uids
return [coordinator_uid, *joined_uids]

async def _async_extract_group(event: SonosEvent | None) -> list[str]:
"""Extract group layout from a topology event."""
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/version/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@
VERSION_SOURCE_PYPI: "pypi",
}

VALID_SOURCES: Final[list[str]] = HA_VERSION_SOURCES + [
VALID_SOURCES: Final[list[str]] = [
*HA_VERSION_SOURCES,
"hassio", # Kept to not break existing configurations
"docker", # Kept to not break existing configurations
]
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/workday/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

LOGGER = logging.getLogger(__package__)

ALLOWED_DAYS = WEEKDAYS + ["holiday"]
ALLOWED_DAYS = [*WEEKDAYS, "holiday"]

DOMAIN = "workday"
PLATFORMS = [Platform.BINARY_SENSOR]
Expand Down
Loading

0 comments on commit ccd2e98

Please sign in to comment.