Update ruff to v0.0.280 (#97102)

This commit is contained in:
Franck Nijhof 2023-07-23 22:00:26 +02:00 committed by GitHub
parent bdd253328d
commit 86708b5590
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 25 additions and 60 deletions

View File

@ -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:

View File

@ -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]:

View File

@ -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"])

View File

@ -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}"

View File

@ -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",
)

View File

@ -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")
)

View File

@ -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)

View File

@ -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 "

View File

@ -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

View File

@ -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]

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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"]

View File

@ -2,5 +2,5 @@
black==23.7.0
codespell==2.2.2
ruff==0.0.277
ruff==0.0.280
yamllint==1.32.0

View File

@ -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

View File

@ -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(

View File

@ -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": []}',
)

View File

@ -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", ""])

View File

@ -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",