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."""
self.entity_description = description
self._measured = None
self._attr_unique_id = "{:2.6f}{:2.6f}{}".format(
coordinates[CONF_LATITUDE], coordinates[CONF_LONGITUDE], description.key
self._attr_unique_id = (
f"{coordinates[CONF_LATITUDE]:2.6f}{coordinates[CONF_LONGITUDE]:2.6f}"
f"{description.key}"
)
# 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._attr_name = self._stationname or f"BR {'(unknown station)'}"
self._attr_unique_id = "{:2.6f}{:2.6f}".format(
coordinates[CONF_LATITUDE], coordinates[CONF_LONGITUDE]
self._attr_unique_id = (
f"{coordinates[CONF_LATITUDE]:2.6f}{coordinates[CONF_LONGITUDE]:2.6f}"
)
@callback

View file

@ -165,8 +165,8 @@ class SignalNotificationService(BaseNotificationService):
size += len(chunk)
if size > attachment_size_limit:
raise ValueError(
"Attachment too large (Stream reports {}). Max size: {}"
" bytes".format(size, CONF_MAX_ALLOWED_DOWNLOAD_SIZE_BYTES)
f"Attachment too large (Stream reports {size}). "
f"Max size: {CONF_MAX_ALLOWED_DOWNLOAD_SIZE_BYTES} bytes"
)
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)
if installed_app.installed_app_status != InstalledAppStatus.AUTHORIZED:
raise RuntimeWarning(
"Installed SmartApp instance '{}' ({}) is not AUTHORIZED but instead {}".format(
installed_app.display_name,
installed_app.installed_app_id,
installed_app.installed_app_status,
)
f"Installed SmartApp instance '{installed_app.display_name}' "
f"({installed_app.installed_app_id}) is not AUTHORIZED "
f"but instead {installed_app.installed_app_status}"
)
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
):
raise vol.ValueInvalid(
"The configured characteristic '{}' is not supported for the configured"
" source sensor".format(characteristic)
f"The configured characteristic '{characteristic}' is not supported "
"for the configured source sensor"
)
return config

View file

@ -130,8 +130,8 @@ def setup_platform(
sensor_name = str(tellcore_sensor.id)
else:
proto_id = f"{tellcore_sensor.protocol}{tellcore_sensor.id}"
proto_model_id = "{}{}{}".format(
tellcore_sensor.protocol, tellcore_sensor.model, tellcore_sensor.id
proto_model_id = (
f"{tellcore_sensor.protocol}{tellcore_sensor.model}{tellcore_sensor.id}"
)
if tellcore_sensor.id in named_sensors:
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(
SELECT_DOMAIN, meter
)
hass.data[DATA_UTILITY][meter][
CONF_TARIFF_ENTITY
] = f"{SELECT_DOMAIN}.{meter}"
# add one meter for each tariff
tariff_confs = {}

View file

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

View file

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

View file

@ -32,8 +32,9 @@ if TYPE_CHECKING:
DATA_CONNECTOR = "aiohttp_connector"
DATA_CLIENTSESSION = "aiohttp_clientsession"
SERVER_SOFTWARE = "{0}/{1} aiohttp/{2} Python/{3[0]}.{3[1]}".format(
APPLICATION_NAME, __version__, aiohttp.__version__, sys.version_info
SERVER_SOFTWARE = (
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)

View file

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

View file

@ -1075,9 +1075,9 @@ def assert_setup_component(count, domain=None):
yield config
if domain is None:
assert len(config) == 1, "assert_setup_component requires DOMAIN: {}".format(
list(config.keys())
)
assert (
len(config) == 1
), f"assert_setup_component requires DOMAIN: {list(config.keys())}"
domain = list(config.keys())[0]
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)
await hass.async_block_till_done()
assert len(calls) == 1
assert calls[0].data["some"] == "turn_off device - {} - on - off - None".format(
entry.entity_id
assert (
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()
assert len(calls) == 1
await hass.async_block_till_done()
assert calls[0].data["some"] == "turn_off device - {} - on - off - 0:00:05".format(
entry.entity_id
assert (
calls[0].data["some"]
== f"turn_off device - {entry.entity_id} - on - off - 0:00:05"
)