diff --git a/homeassistant/components/bluesound/media_player.py b/homeassistant/components/bluesound/media_player.py index cb6f013dbf8..6c63067a1c1 100644 --- a/homeassistant/components/bluesound/media_player.py +++ b/homeassistant/components/bluesound/media_player.py @@ -934,7 +934,7 @@ class BluesoundPlayer(MediaPlayerEntity): selected_source = items[0] 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"] return await self.send_bluesound_command(url) diff --git a/homeassistant/components/isy994/light.py b/homeassistant/components/isy994/light.py index 69701534840..b9b269d9ca3 100644 --- a/homeassistant/components/isy994/light.py +++ b/homeassistant/components/isy994/light.py @@ -114,8 +114,5 @@ class ISYLightEntity(ISYNodeEntity, LightEntity, RestoreEntity): if not (last_state := await self.async_get_last_state()): return - if ( - ATTR_LAST_BRIGHTNESS in last_state.attributes - and last_state.attributes[ATTR_LAST_BRIGHTNESS] - ): - self._last_brightness = last_state.attributes[ATTR_LAST_BRIGHTNESS] + if last_brightness := last_state.attributes.get(ATTR_LAST_BRIGHTNESS): + self._last_brightness = last_brightness diff --git a/homeassistant/components/tado/__init__.py b/homeassistant/components/tado/__init__.py index 5ab7a6f67b8..8f69ccdaffb 100644 --- a/homeassistant/components/tado/__init__.py +++ b/homeassistant/components/tado/__init__.py @@ -221,7 +221,7 @@ class TadoConnector: # Errors are planned to be converted to exceptions # 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( "Error for home ID %s while updating mobile devices: %s", self.home_id, @@ -256,7 +256,7 @@ class TadoConnector: # Errors are planned to be converted to exceptions # 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( "Error for home ID %s while updating devices: %s", self.home_id, diff --git a/homeassistant/components/velbus/__init__.py b/homeassistant/components/velbus/__init__.py index ea03c4b15f1..479b7f02024 100644 --- a/homeassistant/components/velbus/__init__.py +++ b/homeassistant/components/velbus/__init__.py @@ -145,7 +145,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Handle a clear cache service call.""" # clear the cache 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( os.unlink, hass.config.path( diff --git a/homeassistant/components/xiaomi_miio/remote.py b/homeassistant/components/xiaomi_miio/remote.py index cd3b3192520..5baaf614b01 100644 --- a/homeassistant/components/xiaomi_miio/remote.py +++ b/homeassistant/components/xiaomi_miio/remote.py @@ -138,8 +138,8 @@ async def async_setup_platform( message = await hass.async_add_executor_job(device.read, slot) _LOGGER.debug("Message received from device: '%s'", message) - if "code" in message and message["code"]: - log_msg = "Received command is: {}".format(message["code"]) + if code := message.get("code"): + log_msg = f"Received command is: {code}" _LOGGER.info(log_msg) persistent_notification.async_create( hass, log_msg, title="Xiaomi Miio Remote" diff --git a/homeassistant/helpers/config_validation.py b/homeassistant/helpers/config_validation.py index 38287eb6722..bf20a2d7f5f 100644 --- a/homeassistant/helpers/config_validation.py +++ b/homeassistant/helpers/config_validation.py @@ -1106,7 +1106,7 @@ def empty_config_schema(domain: str) -> Callable[[dict], dict]: """Return a config schema which logs if there are configuration parameters.""" def validator(config: dict) -> dict: - if domain in config and config[domain]: + if config_domain := config.get(domain): get_integration_logger(__name__).error( ( "The %s integration does not support any configuration parameters, " @@ -1114,7 +1114,7 @@ def empty_config_schema(domain: str) -> Callable[[dict], dict]: "configuration." ), domain, - config[domain], + config_domain, ) return config diff --git a/pyproject.toml b/pyproject.toml index d3487d50a17..7e3038f6ee2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -705,6 +705,7 @@ select = [ "RUF006", # Store a reference to the return value of asyncio.create_task "RUF013", # PEP 484 prohibits implicit Optional "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 "S102", # Use of exec detected "S103", # bad-file-permissions