From c20a965edaff9b973a92ff3267140f529f4f0088 Mon Sep 17 00:00:00 2001
From: springstan <46536646+springstan@users.noreply.github.com>
Date: Sun, 5 Apr 2020 01:32:58 +0200
Subject: [PATCH] Improve string formatting v3 (#33667)

* Improve string formatting v3

* Address review comment
---
 homeassistant/components/actiontec/device_tracker.py    | 4 ++--
 homeassistant/components/aftership/sensor.py            | 2 +-
 homeassistant/components/aqualogic/__init__.py          | 2 +-
 homeassistant/components/arwn/sensor.py                 | 2 +-
 homeassistant/components/darksky/sensor.py              | 3 ++-
 homeassistant/components/denon/media_player.py          | 4 ++--
 homeassistant/components/dublin_bus_transport/sensor.py | 2 +-
 homeassistant/components/dwd_weather_warnings/sensor.py | 4 ++--
 homeassistant/components/ecobee/binary_sensor.py        | 2 +-
 homeassistant/components/econet/water_heater.py         | 6 +-----
 homeassistant/components/group/__init__.py              | 2 +-
 homeassistant/components/hydrawise/sensor.py            | 6 +-----
 homeassistant/components/hyperion/light.py              | 2 +-
 homeassistant/components/influxdb/__init__.py           | 2 +-
 homeassistant/components/irish_rail_transport/sensor.py | 8 +++++---
 homeassistant/components/knx/climate.py                 | 2 +-
 homeassistant/components/life360/__init__.py            | 2 +-
 homeassistant/components/light/__init__.py              | 2 +-
 homeassistant/components/mobile_app/const.py            | 2 +-
 homeassistant/components/mqtt/discovery.py              | 2 +-
 homeassistant/components/mychevy/__init__.py            | 2 +-
 homeassistant/components/nest/binary_sensor.py          | 2 +-
 homeassistant/components/nest/sensor.py                 | 2 +-
 homeassistant/components/ombi/__init__.py               | 2 +-
 24 files changed, 32 insertions(+), 37 deletions(-)

diff --git a/homeassistant/components/actiontec/device_tracker.py b/homeassistant/components/actiontec/device_tracker.py
index d9d4a4f2ea6..e3fdeaf35f2 100644
--- a/homeassistant/components/actiontec/device_tracker.py
+++ b/homeassistant/components/actiontec/device_tracker.py
@@ -95,9 +95,9 @@ class ActiontecDeviceScanner(DeviceScanner):
         try:
             telnet = telnetlib.Telnet(self.host)
             telnet.read_until(b"Username: ")
-            telnet.write((self.username + "\n").encode("ascii"))
+            telnet.write((f"{self.username}\n").encode("ascii"))
             telnet.read_until(b"Password: ")
-            telnet.write((self.password + "\n").encode("ascii"))
+            telnet.write((f"{self.password}\n").encode("ascii"))
             prompt = telnet.read_until(b"Wireless Broadband Router> ").split(b"\n")[-1]
             telnet.write(b"firewall mac_cache_dump\n")
             telnet.write(b"\n")
diff --git a/homeassistant/components/aftership/sensor.py b/homeassistant/components/aftership/sensor.py
index 3f00c8c310d..a615c5e4033 100644
--- a/homeassistant/components/aftership/sensor.py
+++ b/homeassistant/components/aftership/sensor.py
@@ -27,7 +27,7 @@ CONF_TITLE = "title"
 CONF_TRACKING_NUMBER = "tracking_number"
 
 DEFAULT_NAME = "aftership"
-UPDATE_TOPIC = DOMAIN + "_update"
+UPDATE_TOPIC = f"{DOMAIN}_update"
 
 ICON = "mdi:package-variant-closed"
 
diff --git a/homeassistant/components/aqualogic/__init__.py b/homeassistant/components/aqualogic/__init__.py
index 9f693966382..7ed38206a11 100644
--- a/homeassistant/components/aqualogic/__init__.py
+++ b/homeassistant/components/aqualogic/__init__.py
@@ -18,7 +18,7 @@ from homeassistant.helpers import config_validation as cv
 _LOGGER = logging.getLogger(__name__)
 
 DOMAIN = "aqualogic"
-UPDATE_TOPIC = DOMAIN + "_update"
+UPDATE_TOPIC = f"{DOMAIN}_update"
 CONF_UNIT = "unit"
 RECONNECT_INTERVAL = timedelta(seconds=10)
 
diff --git a/homeassistant/components/arwn/sensor.py b/homeassistant/components/arwn/sensor.py
index 6684a5b882b..7be5c4bfb93 100644
--- a/homeassistant/components/arwn/sensor.py
+++ b/homeassistant/components/arwn/sensor.py
@@ -32,7 +32,7 @@ def discover_sensors(topic, payload):
             unit = TEMP_CELSIUS
         return ArwnSensor(name, "temp", unit)
     if domain == "moisture":
-        name = parts[2] + " Moisture"
+        name = f"{parts[2]} Moisture"
         return ArwnSensor(name, "moisture", unit, "mdi:water-percent")
     if domain == "rain":
         if len(parts) >= 3 and parts[2] == "today":
diff --git a/homeassistant/components/darksky/sensor.py b/homeassistant/components/darksky/sensor.py
index 26ba590888f..0d6814fca10 100644
--- a/homeassistant/components/darksky/sensor.py
+++ b/homeassistant/components/darksky/sensor.py
@@ -771,7 +771,8 @@ def convert_to_camel(data):
     This is not pythonic, but needed for certain situations.
     """
     components = data.split("_")
-    return components[0] + "".join(x.title() for x in components[1:])
+    capital_components = "".join(x.title() for x in components[1:])
+    return f"{components[0]}{capital_components}"
 
 
 class DarkSkyData:
diff --git a/homeassistant/components/denon/media_player.py b/homeassistant/components/denon/media_player.py
index 9f210add0af..11c31107ef6 100644
--- a/homeassistant/components/denon/media_player.py
+++ b/homeassistant/components/denon/media_player.py
@@ -187,7 +187,7 @@ class DenonDevice(MediaPlayerDevice):
                 "NSE8",
             ]
             for line in self.telnet_request(telnet, "NSE", all_lines=True):
-                self._mediainfo += line[len(answer_codes.pop(0)) :] + "\n"
+                self._mediainfo += f"{line[len(answer_codes.pop(0)) :]}\n"
         else:
             self._mediainfo = self.source
 
@@ -257,7 +257,7 @@ class DenonDevice(MediaPlayerDevice):
 
     def set_volume_level(self, volume):
         """Set volume level, range 0..1."""
-        self.telnet_command(f"MV{str(round(volume * self._volume_max)).zfill(2)}")
+        self.telnet_command(f"MV{round(volume * self._volume_max):02}")
 
     def mute_volume(self, mute):
         """Mute (true) or unmute (false) media player."""
diff --git a/homeassistant/components/dublin_bus_transport/sensor.py b/homeassistant/components/dublin_bus_transport/sensor.py
index 5de0b62a4a9..e75775bf75f 100644
--- a/homeassistant/components/dublin_bus_transport/sensor.py
+++ b/homeassistant/components/dublin_bus_transport/sensor.py
@@ -94,7 +94,7 @@ class DublinPublicTransportSensor(Entity):
         if self._times is not None:
             next_up = "None"
             if len(self._times) > 1:
-                next_up = self._times[1][ATTR_ROUTE] + " in "
+                next_up = f"{self._times[1][ATTR_ROUTE]} in "
                 next_up += self._times[1][ATTR_DUE_IN]
 
             return {
diff --git a/homeassistant/components/dwd_weather_warnings/sensor.py b/homeassistant/components/dwd_weather_warnings/sensor.py
index 966ec407ce8..2b7d2296a01 100644
--- a/homeassistant/components/dwd_weather_warnings/sensor.py
+++ b/homeassistant/components/dwd_weather_warnings/sensor.py
@@ -133,9 +133,9 @@ class DwdWeatherWarningsSensor(Entity):
         else:
             raise Exception("Unknown warning type")
 
-        data["warning_count"] = self._api.data[prefix + "_warning_count"]
+        data["warning_count"] = self._api.data[f"{prefix}_warning_count"]
         i = 0
-        for event in self._api.data[prefix + "_warnings"]:
+        for event in self._api.data[f"{prefix}_warnings"]:
             i = i + 1
 
             data[f"warning_{i}_name"] = event["event"]
diff --git a/homeassistant/components/ecobee/binary_sensor.py b/homeassistant/components/ecobee/binary_sensor.py
index 71aaee1c405..2f422007ff4 100644
--- a/homeassistant/components/ecobee/binary_sensor.py
+++ b/homeassistant/components/ecobee/binary_sensor.py
@@ -28,7 +28,7 @@ class EcobeeBinarySensor(BinarySensorDevice):
     def __init__(self, data, sensor_name, sensor_index):
         """Initialize the Ecobee sensor."""
         self.data = data
-        self._name = sensor_name + " Occupancy"
+        self._name = f"{sensor_name} Occupancy"
         self.sensor_name = sensor_name
         self.index = sensor_index
         self._state = None
diff --git a/homeassistant/components/econet/water_heater.py b/homeassistant/components/econet/water_heater.py
index 26ee7cb8bd4..8fede954255 100644
--- a/homeassistant/components/econet/water_heater.py
+++ b/homeassistant/components/econet/water_heater.py
@@ -132,11 +132,7 @@ class EcoNetWaterHeater(WaterHeaterDevice):
             self.ha_state_to_econet[value] = key
         for mode in self.supported_modes:
             if mode not in ECONET_STATE_TO_HA:
-                error = (
-                    "Invalid operation mode mapping. "
-                    + mode
-                    + " doesn't map. Please report this."
-                )
+                error = f"Invalid operation mode mapping. {mode} doesn't map. Please report this."
                 _LOGGER.error(error)
 
     @property
diff --git a/homeassistant/components/group/__init__.py b/homeassistant/components/group/__init__.py
index fd44a80cf3c..e4966a1a4ce 100644
--- a/homeassistant/components/group/__init__.py
+++ b/homeassistant/components/group/__init__.py
@@ -174,7 +174,7 @@ def get_entity_ids(
     if not domain_filter:
         return cast(List[str], entity_ids)
 
-    domain_filter = domain_filter.lower() + "."
+    domain_filter = f"{domain_filter.lower()}."
 
     return [ent_id for ent_id in entity_ids if ent_id.startswith(domain_filter)]
 
diff --git a/homeassistant/components/hydrawise/sensor.py b/homeassistant/components/hydrawise/sensor.py
index 53bca799657..88146dbeb0d 100644
--- a/homeassistant/components/hydrawise/sensor.py
+++ b/homeassistant/components/hydrawise/sensor.py
@@ -58,11 +58,7 @@ class HydrawiseSensor(HydrawiseEntity):
                     if relay["nicetime"] == "Not scheduled":
                         self._state = "not_scheduled"
                     else:
-                        self._state = (
-                            relay["nicetime"].split(",")[0]
-                            + " "
-                            + relay["nicetime"].split(" ")[3]
-                        )
+                        self._state = f"{relay['nicetime'].split(',')[0]} {relay['nicetime'].split(' ')[3]}"
 
     @property
     def icon(self):
diff --git a/homeassistant/components/hyperion/light.py b/homeassistant/components/hyperion/light.py
index fa5d58fb385..fc96f672afb 100644
--- a/homeassistant/components/hyperion/light.py
+++ b/homeassistant/components/hyperion/light.py
@@ -285,7 +285,7 @@ class Hyperion(Light):
             sock.close()
             return False
 
-        sock.send(bytearray(json.dumps(request) + "\n", "utf-8"))
+        sock.send(bytearray(f"{json.dumps(request)}\n", "utf-8"))
         try:
             buf = sock.recv(4096)
         except socket.timeout:
diff --git a/homeassistant/components/influxdb/__init__.py b/homeassistant/components/influxdb/__init__.py
index 1b3093447ec..922a0197cf1 100644
--- a/homeassistant/components/influxdb/__init__.py
+++ b/homeassistant/components/influxdb/__init__.py
@@ -239,7 +239,7 @@ def setup(hass, config):
             elif key != "unit_of_measurement" or include_uom:
                 # If the key is already in fields
                 if key in json["fields"]:
-                    key = key + "_"
+                    key = f"{key}_"
                 # Prevent column data errors in influxDB.
                 # For each value we try to cast it as float
                 # But if we can not do it we store the value
diff --git a/homeassistant/components/irish_rail_transport/sensor.py b/homeassistant/components/irish_rail_transport/sensor.py
index 3bb7da52e22..76f8d0dfaab 100644
--- a/homeassistant/components/irish_rail_transport/sensor.py
+++ b/homeassistant/components/irish_rail_transport/sensor.py
@@ -97,9 +97,11 @@ class IrishRailTransportSensor(Entity):
         if self._times:
             next_up = "None"
             if len(self._times) > 1:
-                next_up = self._times[1][ATTR_ORIGIN] + " to "
-                next_up += self._times[1][ATTR_DESTINATION] + " in "
-                next_up += self._times[1][ATTR_DUE_IN]
+                next_up = (
+                    f"{self._times[1][ATTR_ORIGIN]} to "
+                    f"{self._times[1][ATTR_DESTINATION]} in "
+                    f"{self._times[1][ATTR_DUE_IN]}"
+                )
 
             return {
                 ATTR_ATTRIBUTION: ATTRIBUTION,
diff --git a/homeassistant/components/knx/climate.py b/homeassistant/components/knx/climate.py
index e6da946c81c..e7e489dba78 100644
--- a/homeassistant/components/knx/climate.py
+++ b/homeassistant/components/knx/climate.py
@@ -139,7 +139,7 @@ def async_add_entities_config(hass, config, async_add_entities):
     """Set up climate for KNX platform configured within platform."""
     climate_mode = XknxClimateMode(
         hass.data[DATA_KNX].xknx,
-        name=config[CONF_NAME] + " Mode",
+        name=f"{config[CONF_NAME]} Mode",
         group_address_operation_mode=config.get(CONF_OPERATION_MODE_ADDRESS),
         group_address_operation_mode_state=config.get(
             CONF_OPERATION_MODE_STATE_ADDRESS
diff --git a/homeassistant/components/life360/__init__.py b/homeassistant/components/life360/__init__.py
index 50117c210a2..8338cbf7f11 100644
--- a/homeassistant/components/life360/__init__.py
+++ b/homeassistant/components/life360/__init__.py
@@ -57,7 +57,7 @@ def _prefix(value):
     if not value:
         return ""
     if not value.endswith("_"):
-        return value + "_"
+        return f"{value}_"
     return value
 
 
diff --git a/homeassistant/components/light/__init__.py b/homeassistant/components/light/__init__.py
index 5b9b923cc56..e86de00b59f 100644
--- a/homeassistant/components/light/__init__.py
+++ b/homeassistant/components/light/__init__.py
@@ -325,7 +325,7 @@ class Profiles:
     def get_default(cls, entity_id):
         """Return the default turn-on profile for the given light."""
         # pylint: disable=unsupported-membership-test
-        name = entity_id + ".default"
+        name = f"{entity_id}.default"
         if name in cls._all:
             return name
         name = "group.all_lights.default"
diff --git a/homeassistant/components/mobile_app/const.py b/homeassistant/components/mobile_app/const.py
index f43f1c88396..a9cdc676932 100644
--- a/homeassistant/components/mobile_app/const.py
+++ b/homeassistant/components/mobile_app/const.py
@@ -70,5 +70,5 @@ ATTR_SENSOR_TYPE_SENSOR = "sensor"
 ATTR_SENSOR_UNIQUE_ID = "unique_id"
 ATTR_SENSOR_UOM = "unit_of_measurement"
 
-SIGNAL_SENSOR_UPDATE = DOMAIN + "_sensor_update"
+SIGNAL_SENSOR_UPDATE = f"{DOMAIN}_sensor_update"
 SIGNAL_LOCATION_UPDATE = DOMAIN + "_location_update_{}"
diff --git a/homeassistant/components/mqtt/discovery.py b/homeassistant/components/mqtt/discovery.py
index 812bb183e1c..ce8207fc28d 100644
--- a/homeassistant/components/mqtt/discovery.py
+++ b/homeassistant/components/mqtt/discovery.py
@@ -166,7 +166,7 @@ async def async_start(
     hass.data[CONFIG_ENTRY_IS_SETUP] = set()
 
     await mqtt.async_subscribe(
-        hass, discovery_topic + "/#", async_device_message_received, 0
+        hass, f"{discovery_topic}/#", async_device_message_received, 0
     )
 
     return True
diff --git a/homeassistant/components/mychevy/__init__.py b/homeassistant/components/mychevy/__init__.py
index 0ec4d05a623..2b8bd65dfe8 100644
--- a/homeassistant/components/mychevy/__init__.py
+++ b/homeassistant/components/mychevy/__init__.py
@@ -13,7 +13,7 @@ from homeassistant.util import Throttle
 
 DOMAIN = "mychevy"
 UPDATE_TOPIC = DOMAIN
-ERROR_TOPIC = DOMAIN + "_error"
+ERROR_TOPIC = f"{DOMAIN}_error"
 
 MYCHEVY_SUCCESS = "success"
 MYCHEVY_ERROR = "error"
diff --git a/homeassistant/components/nest/binary_sensor.py b/homeassistant/components/nest/binary_sensor.py
index a029fcfe7d6..34dc7b06ade 100644
--- a/homeassistant/components/nest/binary_sensor.py
+++ b/homeassistant/components/nest/binary_sensor.py
@@ -69,7 +69,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
     for variable in conditions:
         if variable in _BINARY_TYPES_DEPRECATED:
             wstr = (
-                variable + " is no a longer supported "
+                f"{variable} is no a longer supported "
                 "monitored_conditions. See "
                 "https://www.home-assistant.io/integrations/binary_sensor.nest/ "
                 "for valid options."
diff --git a/homeassistant/components/nest/sensor.py b/homeassistant/components/nest/sensor.py
index 064c78917e1..082b5b19b5f 100644
--- a/homeassistant/components/nest/sensor.py
+++ b/homeassistant/components/nest/sensor.py
@@ -96,7 +96,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
                 )
             else:
                 wstr = (
-                    variable + " is no a longer supported "
+                    f"{variable} is no a longer supported "
                     "monitored_conditions. See "
                     "https://www.home-assistant.io/integrations/"
                     "binary_sensor.nest/ for valid options."
diff --git a/homeassistant/components/ombi/__init__.py b/homeassistant/components/ombi/__init__.py
index 750772ce8f5..dcd8f264161 100644
--- a/homeassistant/components/ombi/__init__.py
+++ b/homeassistant/components/ombi/__init__.py
@@ -38,7 +38,7 @@ def urlbase(value) -> str:
     value = str(value).strip("/")
     if not value:
         return value
-    return value + "/"
+    return f"{value}/"
 
 
 SUBMIT_MOVIE_REQUEST_SERVICE_SCHEMA = vol.Schema({vol.Required(ATTR_NAME): cv.string})
-- 
GitLab