Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Ruff RET504 #114528

Merged
merged 6 commits into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions homeassistant/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@ def get_arguments() -> argparse.Namespace:
help="Skips validation of operating system",
)

arguments = parser.parse_args()

return arguments
return parser.parse_args()


def check_threads() -> None:
Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/accuweather/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ async def async_get_config_entry_diagnostics(
config_entry.entry_id
]

diagnostics_data = {
return {
"config_entry_data": async_redact_data(dict(config_entry.data), TO_REDACT),
"coordinator_data": coordinator.data,
}

return diagnostics_data
4 changes: 1 addition & 3 deletions homeassistant/components/airly/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ async def async_get_config_entry_diagnostics(
"""Return diagnostics for a config entry."""
coordinator: AirlyDataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]

diagnostics_data = {
return {
"config_entry": async_redact_data(config_entry.as_dict(), TO_REDACT),
"coordinator_data": coordinator.data,
}

return diagnostics_data
4 changes: 1 addition & 3 deletions homeassistant/components/aladdin_connect/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ async def async_get_config_entry_diagnostics(

acc: AladdinConnectClient = hass.data[DOMAIN][config_entry.entry_id]

diagnostics_data = {
return {
"doors": async_redact_data(acc.doors, TO_REDACT),
}

return diagnostics_data
5 changes: 1 addition & 4 deletions homeassistant/components/alexa/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -1764,10 +1764,7 @@ def get_property(self, name: str) -> Any:
speed_list = self.entity.attributes.get(vacuum.ATTR_FAN_SPEED_LIST)
speed = self.entity.attributes.get(vacuum.ATTR_FAN_SPEED)
if speed_list is not None and speed is not None:
speed_index = next(
(i for i, v in enumerate(speed_list) if v == speed), None
)
return speed_index
return next((i for i, v in enumerate(speed_list) if v == speed), None)

# Valve Position
if self.instance == f"{valve.DOMAIN}.{valve.ATTR_POSITION}":
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/amcrest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@ def command(self, *args: Any, **kwargs: Any) -> Any:
async def async_command(self, *args: Any, **kwargs: Any) -> httpx.Response:
"""amcrest.ApiWrapper.command wrapper to catch errors."""
async with self._async_command_wrapper():
ret = await super().async_command(*args, **kwargs)
return ret
return await super().async_command(*args, **kwargs)

@asynccontextmanager
async def async_stream_command(
Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/aprilaire/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ def supported_features(self) -> ClimateEntityFeature:

features = features | ClimateEntityFeature.PRESET_MODE

features = features | ClimateEntityFeature.FAN_MODE

return features
return features | ClimateEntityFeature.FAN_MODE

@property
def current_humidity(self) -> int | None:
Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/arcam_fmj/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ async def async_browse_media(
for preset in presets.values()
]

root = BrowseMedia(
return BrowseMedia(
title="Arcam FMJ Receiver",
media_class=MediaClass.DIRECTORY,
media_content_id="root",
Expand All @@ -267,8 +267,6 @@ async def async_browse_media(
children=radio,
)

return root

@convert_exception
async def async_play_media(
self, media_type: MediaType | str, media_id: str, **kwargs: Any
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/arris_tg2492lg/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ def scan_devices(self) -> list[str]:

def get_device_name(self, device: str) -> str | None:
"""Return the name of the given device or None if we don't know."""
name = next(
return next(
(result.hostname for result in self.last_results if result.mac == device),
None,
)
return name

def _update_info(self) -> None:
"""Ensure the information from the Arris TG2492LG router is up to date."""
Expand Down
6 changes: 2 additions & 4 deletions homeassistant/components/asuswrt/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ async def _get_model(self) -> None:
async def async_get_available_sensors(self) -> dict[str, dict[str, Any]]:
"""Return a dictionary of available sensors for this bridge."""
sensors_temperatures = await self._get_available_temperature_sensors()
sensors_types = {
return {
SENSORS_TYPE_BYTES: {
KEY_SENSORS: SENSORS_BYTES,
KEY_METHOD: self._get_bytes,
Expand All @@ -272,7 +272,6 @@ async def async_get_available_sensors(self) -> dict[str, dict[str, Any]]:
KEY_METHOD: self._get_temperatures,
},
}
return sensors_types

async def _get_available_temperature_sensors(self) -> list[str]:
"""Check which temperature information is available on the router."""
Expand Down Expand Up @@ -351,7 +350,7 @@ async def async_get_available_sensors(self) -> dict[str, dict[str, Any]]:
"""Return a dictionary of available sensors for this bridge."""
sensors_temperatures = await self._get_available_temperature_sensors()
sensors_loadavg = await self._get_loadavg_sensors_availability()
sensors_types = {
return {
SENSORS_TYPE_BYTES: {
KEY_SENSORS: SENSORS_BYTES,
KEY_METHOD: self._get_bytes,
Expand All @@ -369,7 +368,6 @@ async def async_get_available_sensors(self) -> dict[str, dict[str, Any]]:
KEY_METHOD: self._get_temperatures,
},
}
return sensors_types

async def _get_available_temperature_sensors(self) -> list[str]:
"""Check which temperature information is available on the router."""
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/auth/mfa_setup_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ def _prepare_result_json(
) -> data_entry_flow.FlowResult:
"""Convert result to JSON."""
if result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY:
data = result.copy()
return data
return result.copy()

if result["type"] != data_entry_flow.FlowResultType.FORM:
return result
Expand Down
6 changes: 1 addition & 5 deletions homeassistant/components/bluesound/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,23 +863,19 @@ def rebuild_bluesound_group(self):
if self._group_name is None:
return None

bluesound_group = []

device_group = self._group_name.split("+")

sorted_entities = sorted(
self._hass.data[DATA_BLUESOUND],
key=lambda entity: entity.is_master,
reverse=True,
)
bluesound_group = [
return [
entity.name
for entity in sorted_entities
if entity.bluesound_device_name in device_group
]

return bluesound_group

async def async_unjoin(self):
"""Unjoin the player from a group."""
if self._master is None:
Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/braviatv/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ async def async_get_config_entry_diagnostics(

device_info = await coordinator.client.get_system_info()

diagnostics_data = {
return {
"config_entry": async_redact_data(config_entry.as_dict(), TO_REDACT),
"device_info": async_redact_data(device_info, TO_REDACT),
}

return diagnostics_data
4 changes: 1 addition & 3 deletions homeassistant/components/brother/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ async def async_get_config_entry_diagnostics(
config_entry.entry_id
]

diagnostics_data = {
return {
"info": dict(config_entry.data),
"data": asdict(coordinator.data),
"model": coordinator.brother.model,
"firmware": coordinator.brother.firmware,
}

return diagnostics_data
4 changes: 1 addition & 3 deletions homeassistant/components/canary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,8 @@ async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry) -> Non

def _get_canary_api_instance(entry: ConfigEntry) -> Api:
"""Initialize a new instance of CanaryApi."""
canary = Api(
return Api(
entry.data[CONF_USERNAME],
entry.data[CONF_PASSWORD],
entry.options.get(CONF_TIMEOUT, DEFAULT_TIMEOUT),
)

return canary
3 changes: 1 addition & 2 deletions homeassistant/components/channels/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@ def update(self) -> None:
@property
def source_list(self):
"""List of favorite channels."""
sources = [channel["name"] for channel in self.favorite_channels]
return sources
return [channel["name"] for channel in self.favorite_channels]

@property
def is_volume_muted(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,10 @@ def scan_devices(self):

def get_device_name(self, device):
"""Return the name of the given device or None if we don't know."""
name = next(
return next(
(result.clId for result in self.last_results if result.macaddr == device),
None,
)
return name

def get_extra_attributes(self, device):
"""Get extra attributes of a device.
Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,4 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:

async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)

return unload_ok
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
2 changes: 1 addition & 1 deletion homeassistant/components/cloud/account_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async def _get_services(hass: HomeAssistant) -> list[dict[str, Any]]:
services: list[dict[str, Any]]
if DATA_SERVICES in hass.data:
services = hass.data[DATA_SERVICES]
return services
return services # noqa: RET504

try:
services = await account_link.async_fetch_available_services(hass.data[DOMAIN])
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/coinbase/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@
def get_user_from_client(api_key, api_token):
"""Get the user name from Coinbase API credentials."""
client = Client(api_key, api_token)
user = client.get_current_user()
return user
return client.get_current_user()


async def validate_api(hass: HomeAssistant, data):
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/conversation/agent_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async def async_converse(
language = hass.config.language

_LOGGER.debug("Processing in %s: %s", language, text)
result = await method(
return await method(
ConversationInput(
text=text,
context=context,
Expand All @@ -93,7 +93,6 @@ async def async_converse(
language=language,
)
)
return result


class AgentManager:
Expand Down
7 changes: 2 additions & 5 deletions homeassistant/components/conversation/default_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ async def async_recognize(
slot_lists = self._make_slot_lists()
intent_context = self._make_intent_context(user_input)

result = await self.hass.async_add_executor_job(
return await self.hass.async_add_executor_job(
self._recognize,
user_input,
lang_intents,
Expand All @@ -249,8 +249,6 @@ async def async_recognize(
language,
)

return result

async def async_process(self, user_input: ConversationInput) -> ConversationResult:
"""Process a sentence."""
language = user_input.language or self.hass.config.language
Expand Down Expand Up @@ -901,8 +899,7 @@ def register_trigger(
# Force rebuild on next use
self._trigger_intents = None

unregister = functools.partial(self._unregister_trigger, trigger_data)
return unregister
return functools.partial(self._unregister_trigger, trigger_data)

def _rebuild_trigger_intents(self) -> None:
"""Rebuild the HassIL intents object from the current trigger sentences."""
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/cppm_tracker/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ def scan_devices(self):

def get_device_name(self, device):
"""Retrieve device name."""
name = next(
return next(
(result["name"] for result in self.results if result["mac"] == device), None
)
return name

def get_cppm_data(self):
"""Retrieve data from Aruba Clearpass and return parsed result."""
Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/daikin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ async def daikin_api_setup(
_LOGGER.error("Unexpected error creating device %s", host)
return None

api = DaikinApi(device)

return api
return DaikinApi(device)


class DaikinApi:
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/device_tracker/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,7 @@ async def get_tracker(hass: HomeAssistant, config: ConfigType) -> DeviceTracker:
track_new = defaults.get(CONF_TRACK_NEW, DEFAULT_TRACK_NEW)

devices = await async_load_config(yaml_path, hass, consider_home)
tracker = DeviceTracker(hass, consider_home, track_new, defaults, devices)
return tracker
return DeviceTracker(hass, consider_home, track_new, defaults, devices)


class DeviceTracker:
Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/devolo_home_control/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ async def async_get_config_entry_diagnostics(
for gateway in gateways
]

diag_data = {
return {
"entry": async_redact_data(entry.as_dict(), TO_REDACT),
"device_info": device_info,
}

return diag_data
4 changes: 1 addition & 3 deletions homeassistant/components/dlink/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,11 @@ def extra_state_attributes(self) -> dict[str, Any]:
except ValueError:
total_consumption = None

attrs = {
return {
ATTR_TOTAL_CONSUMPTION: total_consumption,
ATTR_TEMPERATURE: temperature,
}

return attrs

@property
def is_on(self) -> bool:
"""Return true if switch is on."""
Expand Down
6 changes: 1 addition & 5 deletions homeassistant/components/dlna_dmr/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,7 @@ async def _async_get_discoveries(self) -> list[ssdp.SsdpServiceInfo]:
entry.unique_id
for entry in self._async_current_entries(include_ignore=False)
}
discoveries = [
disc for disc in discoveries if disc.ssdp_udn not in current_unique_ids
]

return discoveries
return [disc for disc in discoveries if disc.ssdp_udn not in current_unique_ids]


class DlnaDmrOptionsFlowHandler(OptionsFlow):
Expand Down
6 changes: 1 addition & 5 deletions homeassistant/components/dlna_dms/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,4 @@ async def _async_get_discoveries(self) -> list[ssdp.SsdpServiceInfo]:
entry.unique_id
for entry in self._async_current_entries(include_ignore=False)
}
discoveries = [
disc for disc in discoveries if disc.ssdp_udn not in current_unique_ids
]

return discoveries
return [disc for disc in discoveries if disc.ssdp_udn not in current_unique_ids]
Loading