diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9db1f2ae2e7..d1cae2b0fad 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.277 + rev: v0.0.280 hooks: - id: ruff args: diff --git a/homeassistant/components/assist_pipeline/websocket_api.py b/homeassistant/components/assist_pipeline/websocket_api.py index ea3aacf43a4..4e6d44a8868 100644 --- a/homeassistant/components/assist_pipeline/websocket_api.py +++ b/homeassistant/components/assist_pipeline/websocket_api.py @@ -111,7 +111,7 @@ async def websocket_run( if start_stage == PipelineStage.STT: # Audio pipeline that will receive audio as binary websocket messages - audio_queue: "asyncio.Queue[bytes]" = asyncio.Queue() + audio_queue: asyncio.Queue[bytes] = asyncio.Queue() incoming_sample_rate = msg["input"]["sample_rate"] async def stt_stream() -> AsyncGenerator[bytes, None]: diff --git a/homeassistant/components/bluesound/media_player.py b/homeassistant/components/bluesound/media_player.py index 69e115470ad..91984cf6247 100644 --- a/homeassistant/components/bluesound/media_player.py +++ b/homeassistant/components/bluesound/media_player.py @@ -694,7 +694,7 @@ class BluesoundPlayer(MediaPlayerEntity): for source in [ x for x in self._services_items - if x["type"] == "LocalMusic" or x["type"] == "RadioService" + if x["type"] in ("LocalMusic", "RadioService") ]: sources.append(source["title"]) diff --git a/homeassistant/components/calendar/__init__.py b/homeassistant/components/calendar/__init__.py index d56b2b0ddfa..c85f0d2bff1 100644 --- a/homeassistant/components/calendar/__init__.py +++ b/homeassistant/components/calendar/__init__.py @@ -455,7 +455,7 @@ def extract_offset(summary: str, offset_prefix: str) -> tuple[str, datetime.time if search and search.group(1): time = search.group(1) if ":" not in time: - if time[0] == "+" or time[0] == "-": + if time[0] in ("+", "-"): time = f"{time[0]}0:{time[1:]}" else: time = f"0:{time}" diff --git a/homeassistant/components/flipr/binary_sensor.py b/homeassistant/components/flipr/binary_sensor.py index 76385167d38..0597145c2da 100644 --- a/homeassistant/components/flipr/binary_sensor.py +++ b/homeassistant/components/flipr/binary_sensor.py @@ -47,7 +47,7 @@ class FliprBinarySensor(FliprEntity, BinarySensorEntity): @property def is_on(self) -> bool: """Return true if the binary sensor is on in case of a Problem is detected.""" - return ( - self.coordinator.data[self.entity_description.key] == "TooLow" - or self.coordinator.data[self.entity_description.key] == "TooHigh" + return self.coordinator.data[self.entity_description.key] in ( + "TooLow", + "TooHigh", ) diff --git a/homeassistant/components/freedompro/switch.py b/homeassistant/components/freedompro/switch.py index 97f0a968cff..7313be1920c 100644 --- a/homeassistant/components/freedompro/switch.py +++ b/homeassistant/components/freedompro/switch.py @@ -26,7 +26,7 @@ async def async_setup_entry( async_add_entities( Device(hass, api_key, device, coordinator) for device in coordinator.data - if device["type"] == "switch" or device["type"] == "outlet" + if device["type"] in ("switch", "outlet") ) diff --git a/homeassistant/components/homematicip_cloud/generic_entity.py b/homeassistant/components/homematicip_cloud/generic_entity.py index 7a6e7c18e13..199cbacfa15 100644 --- a/homeassistant/components/homematicip_cloud/generic_entity.py +++ b/homeassistant/components/homematicip_cloud/generic_entity.py @@ -161,10 +161,10 @@ class HomematicipGenericEntity(Entity): if device_id in device_registry.devices: # This will also remove associated entities from entity registry. device_registry.async_remove_device(device_id) - else: + else: # noqa: PLR5501 # Remove from entity registry. # Only relevant for entities that do not belong to a device. - if entity_id := self.registry_entry.entity_id: # noqa: PLR5501 + if entity_id := self.registry_entry.entity_id: entity_registry = er.async_get(self.hass) if entity_id in entity_registry.entities: entity_registry.async_remove(entity_id) diff --git a/homeassistant/components/motioneye/__init__.py b/homeassistant/components/motioneye/__init__.py index b936497cfc6..2876a4d49a1 100644 --- a/homeassistant/components/motioneye/__init__.py +++ b/homeassistant/components/motioneye/__init__.py @@ -169,10 +169,7 @@ def async_generate_motioneye_webhook( ) -> str | None: """Generate the full local URL for a webhook_id.""" try: - return "{}{}".format( - get_url(hass, allow_cloud=False), - async_generate_path(webhook_id), - ) + return f"{get_url(hass, allow_cloud=False)}{async_generate_path(webhook_id)}" except NoURLAvailableError: _LOGGER.warning( "Unable to get Home Assistant URL. Have you set the internal and/or " diff --git a/homeassistant/components/netatmo/camera.py b/homeassistant/components/netatmo/camera.py index 01c459acaea..7fab99a6f39 100644 --- a/homeassistant/components/netatmo/camera.py +++ b/homeassistant/components/netatmo/camera.py @@ -200,9 +200,7 @@ class NetatmoCamera(NetatmoBase, Camera): await self._camera.async_update_camera_urls() if self._camera.local_url: - return "{}/live/files/{}/index.m3u8".format( - self._camera.local_url, self._quality - ) + return f"{self._camera.local_url}/live/files/{self._quality}/index.m3u8" return f"{self._camera.vpn_url}/live/files/{self._quality}/index.m3u8" @callback diff --git a/homeassistant/components/plex/services.py b/homeassistant/components/plex/services.py index 10d005d1043..39d41369a4b 100644 --- a/homeassistant/components/plex/services.py +++ b/homeassistant/components/plex/services.py @@ -143,9 +143,9 @@ def process_plex_payload( content = plex_url.path server_id = plex_url.host plex_server = get_plex_server(hass, plex_server_id=server_id) - else: + else: # noqa: PLR5501 # Handle legacy payloads without server_id in URL host position - if plex_url.host == "search": # noqa: PLR5501 + if plex_url.host == "search": content = {} else: content = int(plex_url.host) # type: ignore[arg-type] diff --git a/homeassistant/components/rachio/binary_sensor.py b/homeassistant/components/rachio/binary_sensor.py index 294931b7538..f1c515d37f7 100644 --- a/homeassistant/components/rachio/binary_sensor.py +++ b/homeassistant/components/rachio/binary_sensor.py @@ -109,10 +109,7 @@ class RachioControllerOnlineBinarySensor(RachioControllerBinarySensor): @callback def _async_handle_update(self, *args, **kwargs) -> None: """Handle an update to the state of this sensor.""" - if ( - args[0][0][KEY_SUBTYPE] == SUBTYPE_ONLINE - or args[0][0][KEY_SUBTYPE] == SUBTYPE_COLD_REBOOT - ): + if args[0][0][KEY_SUBTYPE] in (SUBTYPE_ONLINE, SUBTYPE_COLD_REBOOT): self._state = True elif args[0][0][KEY_SUBTYPE] == SUBTYPE_OFFLINE: self._state = False diff --git a/homeassistant/components/recorder/migration.py b/homeassistant/components/recorder/migration.py index 33d8c7b5e67..8fe1d0482e9 100644 --- a/homeassistant/components/recorder/migration.py +++ b/homeassistant/components/recorder/migration.py @@ -423,13 +423,7 @@ def _add_columns( with session_scope(session=session_maker()) as session: try: connection = session.connection() - connection.execute( - text( - "ALTER TABLE {table} {column_def}".format( - table=table_name, column_def=column_def - ) - ) - ) + connection.execute(text(f"ALTER TABLE {table_name} {column_def}")) except (InternalError, OperationalError, ProgrammingError) as err: raise_if_exception_missing_str(err, ["already exists", "duplicate"]) _LOGGER.warning( @@ -498,13 +492,7 @@ def _modify_columns( with session_scope(session=session_maker()) as session: try: connection = session.connection() - connection.execute( - text( - "ALTER TABLE {table} {column_def}".format( - table=table_name, column_def=column_def - ) - ) - ) + connection.execute(text(f"ALTER TABLE {table_name} {column_def}")) except (InternalError, OperationalError): _LOGGER.exception( "Could not modify column %s in table %s", column_def, table_name diff --git a/homeassistant/components/thermoworks_smoke/sensor.py b/homeassistant/components/thermoworks_smoke/sensor.py index fbbfdef6f02..4b4878fa1c8 100644 --- a/homeassistant/components/thermoworks_smoke/sensor.py +++ b/homeassistant/components/thermoworks_smoke/sensor.py @@ -111,9 +111,7 @@ class ThermoworksSmokeSensor(SensorEntity): self.type = sensor_type self.serial = serial self.mgr = mgr - self._attr_name = "{name} {sensor}".format( - name=mgr.name(serial), sensor=SENSOR_TYPES[sensor_type] - ) + self._attr_name = f"{mgr.name(serial)} {SENSOR_TYPES[sensor_type]}" self._attr_native_unit_of_measurement = UnitOfTemperature.FAHRENHEIT self._attr_unique_id = f"{serial}-{sensor_type}" self._attr_device_class = SensorDeviceClass.TEMPERATURE diff --git a/homeassistant/components/wemo/wemo_device.py b/homeassistant/components/wemo/wemo_device.py index abb8aa186c9..c85bc9fd473 100644 --- a/homeassistant/components/wemo/wemo_device.py +++ b/homeassistant/components/wemo/wemo_device.py @@ -35,7 +35,7 @@ from .models import async_wemo_data _LOGGER = logging.getLogger(__name__) # Literal values must match options.error keys from strings.json. -ErrorStringKey = Literal["long_press_requires_subscription"] +ErrorStringKey = Literal["long_press_requires_subscription"] # noqa: F821 # Literal values must match options.step.init.data keys from strings.json. OptionsFieldKey = Literal["enable_subscription", "enable_long_press"] diff --git a/requirements_test_pre_commit.txt b/requirements_test_pre_commit.txt index 28b51fcb447..e91cbe1ff62 100644 --- a/requirements_test_pre_commit.txt +++ b/requirements_test_pre_commit.txt @@ -2,5 +2,5 @@ black==23.7.0 codespell==2.2.2 -ruff==0.0.277 +ruff==0.0.280 yamllint==1.32.0 diff --git a/tests/components/mqtt/test_discovery.py b/tests/components/mqtt/test_discovery.py index d3b8a145df7..f51d469bde7 100644 --- a/tests/components/mqtt/test_discovery.py +++ b/tests/components/mqtt/test_discovery.py @@ -1304,9 +1304,7 @@ async def test_missing_discover_abbreviations( and match[0] not in ABBREVIATIONS_WHITE_LIST ): missing.append( - "{}: no abbreviation for {} ({})".format( - fil, match[1], match[0] - ) + f"{fil}: no abbreviation for {match[1]} ({match[0]})" ) assert not missing diff --git a/tests/components/python_script/test_init.py b/tests/components/python_script/test_init.py index 767b0bca742..9326869b272 100644 --- a/tests/components/python_script/test_init.py +++ b/tests/components/python_script/test_init.py @@ -357,9 +357,7 @@ async def test_service_descriptions(hass: HomeAssistant) -> None: " example: 'This is a test of python_script.hello'" ) services_yaml1 = { - "{}/{}/services.yaml".format( - hass.config.config_dir, FOLDER - ): service_descriptions1 + f"{hass.config.config_dir}/{FOLDER}/services.yaml": service_descriptions1 } with patch( @@ -408,9 +406,7 @@ async def test_service_descriptions(hass: HomeAssistant) -> None: " example: 'This is a test of python_script.hello2'" ) services_yaml2 = { - "{}/{}/services.yaml".format( - hass.config.config_dir, FOLDER - ): service_descriptions2 + f"{hass.config.config_dir}/{FOLDER}/services.yaml": service_descriptions2 } with patch( diff --git a/tests/components/starline/test_config_flow.py b/tests/components/starline/test_config_flow.py index c659ca5c585..4277f01037f 100644 --- a/tests/components/starline/test_config_flow.py +++ b/tests/components/starline/test_config_flow.py @@ -37,9 +37,7 @@ async def test_flow_works(hass: HomeAssistant) -> None: cookies={"slnet": TEST_APP_SLNET}, ) mock.get( - "https://developer.starline.ru/json/v2/user/{}/user_info".format( - TEST_APP_UID - ), + f"https://developer.starline.ru/json/v2/user/{TEST_APP_UID}/user_info", text='{"code": 200, "devices": [{"device_id": "123", "imei": "123", "alias": "123", "battery": "123", "ctemp": "123", "etemp": "123", "fw_version": "123", "gsm_lvl": "123", "phone": "123", "status": "1", "ts_activity": "123", "typename": "123", "balance": {}, "car_state": {}, "car_alr_state": {}, "functions": [], "position": {}}], "shared_devices": []}', ) diff --git a/tests/components/tellduslive/test_config_flow.py b/tests/components/tellduslive/test_config_flow.py index 0eaadae4931..de284bb8c16 100644 --- a/tests/components/tellduslive/test_config_flow.py +++ b/tests/components/tellduslive/test_config_flow.py @@ -261,4 +261,4 @@ async def test_discovery_already_configured( flow.context = {"source": SOURCE_DISCOVERY} with pytest.raises(data_entry_flow.AbortFlow): - result = await flow.async_step_discovery(["some-host", ""]) + await flow.async_step_discovery(["some-host", ""]) diff --git a/tests/components/zha/zha_devices_list.py b/tests/components/zha/zha_devices_list.py index 4ccf7323148..bba5ee124ba 100644 --- a/tests/components/zha/zha_devices_list.py +++ b/tests/components/zha/zha_devices_list.py @@ -3013,11 +3013,6 @@ DEVICES = [ DEV_SIG_ENT_MAP_CLASS: "Illuminance", DEV_SIG_ENT_MAP_ID: "sensor.lumi_lumi_sensor_motion_aq2_illuminance", }, - ("sensor", "00:11:22:33:44:55:66:77-1-1"): { - DEV_SIG_CLUSTER_HANDLERS: ["power"], - DEV_SIG_ENT_MAP_CLASS: "Battery", - DEV_SIG_ENT_MAP_ID: "sensor.lumi_lumi_sensor_motion_aq2_battery", - }, ("sensor", "00:11:22:33:44:55:66:77-1-2"): { DEV_SIG_CLUSTER_HANDLERS: ["device_temperature"], DEV_SIG_ENT_MAP_CLASS: "DeviceTemperature",