Use more f-strings [ruff] (#112695)

This commit is contained in:
Marc Mueller 2024-03-08 18:44:42 +01:00 committed by GitHub
parent f416d67d21
commit cb8c14496c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 38 additions and 34 deletions

View File

@ -742,8 +742,9 @@ class BrSensor(SensorEntity):
"""Initialize the sensor.""" """Initialize the sensor."""
self.entity_description = description self.entity_description = description
self._measured = None self._measured = None
self._attr_unique_id = "{:2.6f}{:2.6f}{}".format( self._attr_unique_id = (
coordinates[CONF_LATITUDE], coordinates[CONF_LONGITUDE], description.key f"{coordinates[CONF_LATITUDE]:2.6f}{coordinates[CONF_LONGITUDE]:2.6f}"
f"{description.key}"
) )
# All continuous sensors should be forced to be updated # All continuous sensors should be forced to be updated

View File

@ -134,8 +134,8 @@ class BrWeather(WeatherEntity):
self._stationname = config.get(CONF_NAME, "Buienradar") self._stationname = config.get(CONF_NAME, "Buienradar")
self._attr_name = self._stationname or f"BR {'(unknown station)'}" self._attr_name = self._stationname or f"BR {'(unknown station)'}"
self._attr_unique_id = "{:2.6f}{:2.6f}".format( self._attr_unique_id = (
coordinates[CONF_LATITUDE], coordinates[CONF_LONGITUDE] f"{coordinates[CONF_LATITUDE]:2.6f}{coordinates[CONF_LONGITUDE]:2.6f}"
) )
@callback @callback

View File

@ -165,8 +165,8 @@ class SignalNotificationService(BaseNotificationService):
size += len(chunk) size += len(chunk)
if size > attachment_size_limit: if size > attachment_size_limit:
raise ValueError( raise ValueError(
"Attachment too large (Stream reports {}). Max size: {}" f"Attachment too large (Stream reports {size}). "
" bytes".format(size, CONF_MAX_ALLOWED_DOWNLOAD_SIZE_BYTES) f"Max size: {CONF_MAX_ALLOWED_DOWNLOAD_SIZE_BYTES} bytes"
) )
chunks.extend(chunk) chunks.extend(chunk)

View File

@ -84,11 +84,9 @@ async def validate_installed_app(api, installed_app_id: str):
installed_app = await api.installed_app(installed_app_id) installed_app = await api.installed_app(installed_app_id)
if installed_app.installed_app_status != InstalledAppStatus.AUTHORIZED: if installed_app.installed_app_status != InstalledAppStatus.AUTHORIZED:
raise RuntimeWarning( raise RuntimeWarning(
"Installed SmartApp instance '{}' ({}) is not AUTHORIZED but instead {}".format( f"Installed SmartApp instance '{installed_app.display_name}' "
installed_app.display_name, f"({installed_app.installed_app_id}) is not AUTHORIZED "
installed_app.installed_app_id, f"but instead {installed_app.installed_app_status}"
installed_app.installed_app_status,
)
) )
return installed_app return installed_app

View File

@ -204,8 +204,8 @@ def valid_state_characteristic_configuration(config: dict[str, Any]) -> dict[str
not is_binary and characteristic not in STATS_NUMERIC_SUPPORT not is_binary and characteristic not in STATS_NUMERIC_SUPPORT
): ):
raise vol.ValueInvalid( raise vol.ValueInvalid(
"The configured characteristic '{}' is not supported for the configured" f"The configured characteristic '{characteristic}' is not supported "
" source sensor".format(characteristic) "for the configured source sensor"
) )
return config return config

View File

@ -130,8 +130,8 @@ def setup_platform(
sensor_name = str(tellcore_sensor.id) sensor_name = str(tellcore_sensor.id)
else: else:
proto_id = f"{tellcore_sensor.protocol}{tellcore_sensor.id}" proto_id = f"{tellcore_sensor.protocol}{tellcore_sensor.id}"
proto_model_id = "{}{}{}".format( proto_model_id = (
tellcore_sensor.protocol, tellcore_sensor.model, tellcore_sensor.id f"{tellcore_sensor.protocol}{tellcore_sensor.model}{tellcore_sensor.id}"
) )
if tellcore_sensor.id in named_sensors: if tellcore_sensor.id in named_sensors:
sensor_name = named_sensors[tellcore_sensor.id] sensor_name = named_sensors[tellcore_sensor.id]

View File

@ -164,9 +164,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
) )
) )
hass.data[DATA_UTILITY][meter][CONF_TARIFF_ENTITY] = "{}.{}".format( hass.data[DATA_UTILITY][meter][
SELECT_DOMAIN, meter CONF_TARIFF_ENTITY
) ] = f"{SELECT_DOMAIN}.{meter}"
# add one meter for each tariff # add one meter for each tariff
tariff_confs = {} tariff_confs = {}

View File

@ -89,9 +89,9 @@ def async_generate_id() -> str:
@bind_hass @bind_hass
def async_generate_url(hass: HomeAssistant, webhook_id: str) -> str: def async_generate_url(hass: HomeAssistant, webhook_id: str) -> str:
"""Generate the full URL for a webhook_id.""" """Generate the full URL for a webhook_id."""
return "{}{}".format( return (
get_url(hass, prefer_external=True, allow_cloud=False), f"{get_url(hass, prefer_external=True, allow_cloud=False)}"
async_generate_path(webhook_id), f"{async_generate_path(webhook_id)}"
) )

View File

@ -90,8 +90,9 @@ class WemoSwitch(WemoBinaryStateEntity, SwitchEntity):
def as_uptime(_seconds: int) -> str: def as_uptime(_seconds: int) -> str:
"""Format seconds into uptime string in the format: 00d 00h 00m 00s.""" """Format seconds into uptime string in the format: 00d 00h 00m 00s."""
uptime = datetime(1, 1, 1) + timedelta(seconds=_seconds) uptime = datetime(1, 1, 1) + timedelta(seconds=_seconds)
return "{:0>2d}d {:0>2d}h {:0>2d}m {:0>2d}s".format( return (
uptime.day - 1, uptime.hour, uptime.minute, uptime.second f"{uptime.day - 1:0>2d}d {uptime.hour:0>2d}h "
f"{uptime.minute:0>2d}m {uptime.second:0>2d}s"
) )
@property @property

View File

@ -32,8 +32,9 @@ if TYPE_CHECKING:
DATA_CONNECTOR = "aiohttp_connector" DATA_CONNECTOR = "aiohttp_connector"
DATA_CLIENTSESSION = "aiohttp_clientsession" DATA_CLIENTSESSION = "aiohttp_clientsession"
SERVER_SOFTWARE = "{0}/{1} aiohttp/{2} Python/{3[0]}.{3[1]}".format( SERVER_SOFTWARE = (
APPLICATION_NAME, __version__, aiohttp.__version__, sys.version_info f"{APPLICATION_NAME}/{__version__} "
f"aiohttp/{aiohttp.__version__} Python/{sys.version_info[0]}.{sys.version_info[1]}"
) )
ENABLE_CLEANUP_CLOSED = not (3, 11, 1) <= sys.version_info < (3, 11, 4) ENABLE_CLEANUP_CLOSED = not (3, 11, 1) <= sys.version_info < (3, 11, 4)

View File

@ -26,8 +26,9 @@ KEEP_ALIVE_TIMEOUT = 15
DATA_ASYNC_CLIENT = "httpx_async_client" DATA_ASYNC_CLIENT = "httpx_async_client"
DATA_ASYNC_CLIENT_NOVERIFY = "httpx_async_client_noverify" DATA_ASYNC_CLIENT_NOVERIFY = "httpx_async_client_noverify"
DEFAULT_LIMITS = limits = httpx.Limits(keepalive_expiry=KEEP_ALIVE_TIMEOUT) DEFAULT_LIMITS = limits = httpx.Limits(keepalive_expiry=KEEP_ALIVE_TIMEOUT)
SERVER_SOFTWARE = "{0}/{1} httpx/{2} Python/{3[0]}.{3[1]}".format( SERVER_SOFTWARE = (
APPLICATION_NAME, __version__, httpx.__version__, sys.version_info f"{APPLICATION_NAME}/{__version__} "
f"httpx/{httpx.__version__} Python/{sys.version_info[0]}.{sys.version_info[1]}"
) )
USER_AGENT = "User-Agent" USER_AGENT = "User-Agent"

View File

@ -1075,9 +1075,9 @@ def assert_setup_component(count, domain=None):
yield config yield config
if domain is None: if domain is None:
assert len(config) == 1, "assert_setup_component requires DOMAIN: {}".format( assert (
list(config.keys()) len(config) == 1
) ), f"assert_setup_component requires DOMAIN: {list(config.keys())}"
domain = list(config.keys())[0] domain = list(config.keys())[0]
res = config.get(domain) res = config.get(domain)

View File

@ -479,6 +479,7 @@ async def test_if_fires_on_state_change_legacy(
hass.states.async_set(entry.entity_id, STATE_OFF) hass.states.async_set(entry.entity_id, STATE_OFF)
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(calls) == 1 assert len(calls) == 1
assert calls[0].data["some"] == "turn_off device - {} - on - off - None".format( assert (
entry.entity_id calls[0].data["some"]
== f"turn_off device - {entry.entity_id} - on - off - None"
) )

View File

@ -214,6 +214,7 @@ async def test_if_fires_on_state_change_with_for(
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(calls) == 1 assert len(calls) == 1
await hass.async_block_till_done() await hass.async_block_till_done()
assert calls[0].data["some"] == "turn_off device - {} - on - off - 0:00:05".format( assert (
entry.entity_id calls[0].data["some"]
== f"turn_off device - {entry.entity_id} - on - off - 0:00:05"
) )