Enable Ruff RUF019 (#115396)

* Enable Ruff RUF019

* fix tado tests

* review comments
This commit is contained in:
Sid 2024-04-24 07:23:24 +02:00 committed by GitHub
parent 4a59ee978c
commit b37f7b1ff0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 11 additions and 13 deletions

View file

@ -934,7 +934,7 @@ class BluesoundPlayer(MediaPlayerEntity):
selected_source = items[0] selected_source = items[0]
url = f"Play?url={selected_source['url']}&preset_id&image={selected_source['image']}" url = f"Play?url={selected_source['url']}&preset_id&image={selected_source['image']}"
if "is_raw_url" in selected_source and selected_source["is_raw_url"]: if selected_source.get("is_raw_url"):
url = selected_source["url"] url = selected_source["url"]
return await self.send_bluesound_command(url) return await self.send_bluesound_command(url)

View file

@ -114,8 +114,5 @@ class ISYLightEntity(ISYNodeEntity, LightEntity, RestoreEntity):
if not (last_state := await self.async_get_last_state()): if not (last_state := await self.async_get_last_state()):
return return
if ( if last_brightness := last_state.attributes.get(ATTR_LAST_BRIGHTNESS):
ATTR_LAST_BRIGHTNESS in last_state.attributes self._last_brightness = last_brightness
and last_state.attributes[ATTR_LAST_BRIGHTNESS]
):
self._last_brightness = last_state.attributes[ATTR_LAST_BRIGHTNESS]

View file

@ -221,7 +221,7 @@ class TadoConnector:
# Errors are planned to be converted to exceptions # Errors are planned to be converted to exceptions
# in PyTado library, so this can be removed # in PyTado library, so this can be removed
if "errors" in mobile_devices and mobile_devices["errors"]: if isinstance(mobile_devices, dict) and mobile_devices.get("errors"):
_LOGGER.error( _LOGGER.error(
"Error for home ID %s while updating mobile devices: %s", "Error for home ID %s while updating mobile devices: %s",
self.home_id, self.home_id,
@ -256,7 +256,7 @@ class TadoConnector:
# Errors are planned to be converted to exceptions # Errors are planned to be converted to exceptions
# in PyTado library, so this can be removed # in PyTado library, so this can be removed
if "errors" in devices and devices["errors"]: if isinstance(devices, dict) and devices.get("errors"):
_LOGGER.error( _LOGGER.error(
"Error for home ID %s while updating devices: %s", "Error for home ID %s while updating devices: %s",
self.home_id, self.home_id,

View file

@ -145,7 +145,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Handle a clear cache service call.""" """Handle a clear cache service call."""
# clear the cache # clear the cache
with suppress(FileNotFoundError): with suppress(FileNotFoundError):
if CONF_ADDRESS in call.data and call.data[CONF_ADDRESS]: if call.data.get(CONF_ADDRESS):
await hass.async_add_executor_job( await hass.async_add_executor_job(
os.unlink, os.unlink,
hass.config.path( hass.config.path(

View file

@ -138,8 +138,8 @@ async def async_setup_platform(
message = await hass.async_add_executor_job(device.read, slot) message = await hass.async_add_executor_job(device.read, slot)
_LOGGER.debug("Message received from device: '%s'", message) _LOGGER.debug("Message received from device: '%s'", message)
if "code" in message and message["code"]: if code := message.get("code"):
log_msg = "Received command is: {}".format(message["code"]) log_msg = f"Received command is: {code}"
_LOGGER.info(log_msg) _LOGGER.info(log_msg)
persistent_notification.async_create( persistent_notification.async_create(
hass, log_msg, title="Xiaomi Miio Remote" hass, log_msg, title="Xiaomi Miio Remote"

View file

@ -1106,7 +1106,7 @@ def empty_config_schema(domain: str) -> Callable[[dict], dict]:
"""Return a config schema which logs if there are configuration parameters.""" """Return a config schema which logs if there are configuration parameters."""
def validator(config: dict) -> dict: def validator(config: dict) -> dict:
if domain in config and config[domain]: if config_domain := config.get(domain):
get_integration_logger(__name__).error( get_integration_logger(__name__).error(
( (
"The %s integration does not support any configuration parameters, " "The %s integration does not support any configuration parameters, "
@ -1114,7 +1114,7 @@ def empty_config_schema(domain: str) -> Callable[[dict], dict]:
"configuration." "configuration."
), ),
domain, domain,
config[domain], config_domain,
) )
return config return config

View file

@ -705,6 +705,7 @@ select = [
"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 "RUF018", # Avoid assignment expressions in assert statements
"RUF019", # Unnecessary key check before dictionary access
# "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