From cb8c14496ca3aeccd737131972a393c8a4829b7d Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Fri, 8 Mar 2024 18:44:42 +0100 Subject: [PATCH] Use more f-strings [ruff] (#112695) --- homeassistant/components/buienradar/sensor.py | 5 +++-- homeassistant/components/buienradar/weather.py | 4 ++-- homeassistant/components/signal_messenger/notify.py | 4 ++-- homeassistant/components/smartthings/smartapp.py | 8 +++----- homeassistant/components/statistics/sensor.py | 4 ++-- homeassistant/components/tellstick/sensor.py | 4 ++-- homeassistant/components/utility_meter/__init__.py | 6 +++--- homeassistant/components/webhook/__init__.py | 6 +++--- homeassistant/components/wemo/switch.py | 5 +++-- homeassistant/helpers/aiohttp_client.py | 5 +++-- homeassistant/helpers/httpx_client.py | 5 +++-- tests/common.py | 6 +++--- tests/components/binary_sensor/test_device_trigger.py | 5 +++-- tests/components/device_automation/test_toggle_entity.py | 5 +++-- 14 files changed, 38 insertions(+), 34 deletions(-) diff --git a/homeassistant/components/buienradar/sensor.py b/homeassistant/components/buienradar/sensor.py index a52fca25c87..d0847c111fb 100644 --- a/homeassistant/components/buienradar/sensor.py +++ b/homeassistant/components/buienradar/sensor.py @@ -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 diff --git a/homeassistant/components/buienradar/weather.py b/homeassistant/components/buienradar/weather.py index de00faadd64..c7387857da5 100644 --- a/homeassistant/components/buienradar/weather.py +++ b/homeassistant/components/buienradar/weather.py @@ -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 diff --git a/homeassistant/components/signal_messenger/notify.py b/homeassistant/components/signal_messenger/notify.py index 3659864efd7..58cd85fb26e 100644 --- a/homeassistant/components/signal_messenger/notify.py +++ b/homeassistant/components/signal_messenger/notify.py @@ -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) diff --git a/homeassistant/components/smartthings/smartapp.py b/homeassistant/components/smartthings/smartapp.py index 78c0bfa86b1..11446771130 100644 --- a/homeassistant/components/smartthings/smartapp.py +++ b/homeassistant/components/smartthings/smartapp.py @@ -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 diff --git a/homeassistant/components/statistics/sensor.py b/homeassistant/components/statistics/sensor.py index 0a88e9d93af..e1e530e60ed 100644 --- a/homeassistant/components/statistics/sensor.py +++ b/homeassistant/components/statistics/sensor.py @@ -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 diff --git a/homeassistant/components/tellstick/sensor.py b/homeassistant/components/tellstick/sensor.py index 2469ee49aa2..a2cba41b028 100644 --- a/homeassistant/components/tellstick/sensor.py +++ b/homeassistant/components/tellstick/sensor.py @@ -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] diff --git a/homeassistant/components/utility_meter/__init__.py b/homeassistant/components/utility_meter/__init__.py index 0e3e864461d..aeed9885872 100644 --- a/homeassistant/components/utility_meter/__init__.py +++ b/homeassistant/components/utility_meter/__init__.py @@ -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 = {} diff --git a/homeassistant/components/webhook/__init__.py b/homeassistant/components/webhook/__init__.py index 09b7541cbea..081147cc7f0 100644 --- a/homeassistant/components/webhook/__init__.py +++ b/homeassistant/components/webhook/__init__.py @@ -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)}" ) diff --git a/homeassistant/components/wemo/switch.py b/homeassistant/components/wemo/switch.py index 8cc95325c7e..14e3013afc1 100644 --- a/homeassistant/components/wemo/switch.py +++ b/homeassistant/components/wemo/switch.py @@ -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 diff --git a/homeassistant/helpers/aiohttp_client.py b/homeassistant/helpers/aiohttp_client.py index 70546e54bcc..17784d12aa2 100644 --- a/homeassistant/helpers/aiohttp_client.py +++ b/homeassistant/helpers/aiohttp_client.py @@ -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) diff --git a/homeassistant/helpers/httpx_client.py b/homeassistant/helpers/httpx_client.py index 306d9899cd5..2855705b9c1 100644 --- a/homeassistant/helpers/httpx_client.py +++ b/homeassistant/helpers/httpx_client.py @@ -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" diff --git a/tests/common.py b/tests/common.py index 5b2314ee038..0766da158d1 100644 --- a/tests/common.py +++ b/tests/common.py @@ -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) diff --git a/tests/components/binary_sensor/test_device_trigger.py b/tests/components/binary_sensor/test_device_trigger.py index bd357f25ba3..66fa8d35a92 100644 --- a/tests/components/binary_sensor/test_device_trigger.py +++ b/tests/components/binary_sensor/test_device_trigger.py @@ -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" ) diff --git a/tests/components/device_automation/test_toggle_entity.py b/tests/components/device_automation/test_toggle_entity.py index f034dd9ab12..59d316545fa 100644 --- a/tests/components/device_automation/test_toggle_entity.py +++ b/tests/components/device_automation/test_toggle_entity.py @@ -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" )