From 886308a95380a9c32f6db513e45dfe6287178ebb Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sat, 4 Apr 2020 21:39:22 +0200 Subject: [PATCH] String formatting improvements (#33653) --- homeassistant/components/calendar/__init__.py | 4 ++-- homeassistant/components/nsw_fuel_station/sensor.py | 2 +- homeassistant/components/ohmconnect/sensor.py | 2 +- homeassistant/components/osramlightify/light.py | 2 +- homeassistant/components/plugwise/climate.py | 2 +- homeassistant/components/point/__init__.py | 2 +- homeassistant/components/rainbird/switch.py | 5 +---- homeassistant/components/splunk/__init__.py | 4 ++-- homeassistant/components/tellstick/sensor.py | 6 +++--- homeassistant/components/tensorflow/image_processing.py | 2 +- homeassistant/components/tibber/sensor.py | 4 ++-- homeassistant/components/tuya/__init__.py | 2 +- homeassistant/components/wink/__init__.py | 2 +- homeassistant/components/wirelesstag/__init__.py | 4 ++-- homeassistant/scripts/keyring.py | 2 +- 15 files changed, 21 insertions(+), 24 deletions(-) diff --git a/homeassistant/components/calendar/__init__.py b/homeassistant/components/calendar/__init__.py index 53edf48ae80..6a03d899a09 100644 --- a/homeassistant/components/calendar/__init__.py +++ b/homeassistant/components/calendar/__init__.py @@ -86,7 +86,7 @@ def calculate_offset(event, offset): summary = event.get("summary", "") # check if we have an offset tag in the message # time is HH:MM or MM - reg = "{}([+-]?[0-9]{{0,2}}(:[0-9]{{0,2}})?)".format(offset) + reg = f"{offset}([+-]?[0-9]{{0,2}}(:[0-9]{{0,2}})?)" search = re.search(reg, summary) if search and search.group(1): time = search.group(1) @@ -94,7 +94,7 @@ def calculate_offset(event, offset): if time[0] == "+" or time[0] == "-": time = "{}0:{}".format(time[0], time[1:]) else: - time = "0:{}".format(time) + time = f"0:{time}" offset_time = time_period_str(time) summary = (summary[: search.start()] + summary[search.end() :]).strip() diff --git a/homeassistant/components/nsw_fuel_station/sensor.py b/homeassistant/components/nsw_fuel_station/sensor.py index b4cd7bd161e..5e9a9835bf4 100644 --- a/homeassistant/components/nsw_fuel_station/sensor.py +++ b/homeassistant/components/nsw_fuel_station/sensor.py @@ -156,7 +156,7 @@ class StationPriceSensor(Entity): @property def name(self) -> str: """Return the name of the sensor.""" - return "{} {}".format(self._station_data.get_station_name(), self._fuel_type) + return f"{self._station_data.get_station_name()} {self._fuel_type}" @property def state(self) -> Optional[float]: diff --git a/homeassistant/components/ohmconnect/sensor.py b/homeassistant/components/ohmconnect/sensor.py index 490ebbe75b3..56a3cc06556 100644 --- a/homeassistant/components/ohmconnect/sensor.py +++ b/homeassistant/components/ohmconnect/sensor.py @@ -66,7 +66,7 @@ class OhmconnectSensor(Entity): def update(self): """Get the latest data from OhmConnect.""" try: - url = "https://login.ohmconnect.com/verify-ohm-hour/{}".format(self._ohmid) + url = f"https://login.ohmconnect.com/verify-ohm-hour/{self._ohmid}" response = requests.get(url, timeout=10) root = ET.fromstring(response.text) diff --git a/homeassistant/components/osramlightify/light.py b/homeassistant/components/osramlightify/light.py index 05064861844..3a911fbcf95 100644 --- a/homeassistant/components/osramlightify/light.py +++ b/homeassistant/components/osramlightify/light.py @@ -404,7 +404,7 @@ class OsramLightifyGroup(Luminary): # It should be something like "-" # For now keeping it as is for backward compatibility with existing # users. - return "{}".format(self._luminary.lights()) + return f"{self._luminary.lights()}" def _get_supported_features(self): """Get list of supported features.""" diff --git a/homeassistant/components/plugwise/climate.py b/homeassistant/components/plugwise/climate.py index 9b519f969e0..aef1dd78197 100644 --- a/homeassistant/components/plugwise/climate.py +++ b/homeassistant/components/plugwise/climate.py @@ -209,7 +209,7 @@ class ThermostatDevice(ClimateDevice): preset_temperature = presets.get(self._preset_mode, "none") if self.hvac_mode == HVAC_MODE_AUTO: if self._thermostat_temperature == self._schedule_temperature: - return "{}".format(self._selected_schema) + return f"{self._selected_schema}" if self._thermostat_temperature == preset_temperature: return self._preset_mode return "Temporary" diff --git a/homeassistant/components/point/__init__.py b/homeassistant/components/point/__init__.py index 2817871cd7c..bb591b79884 100644 --- a/homeassistant/components/point/__init__.py +++ b/homeassistant/components/point/__init__.py @@ -319,7 +319,7 @@ class MinutPointEntity(Entity): @property def name(self): """Return the display name of this device.""" - return "{} {}".format(self._name, self.device_class.capitalize()) + return f"{self._name} {self.device_class.capitalize()}" @property def is_updated(self): diff --git a/homeassistant/components/rainbird/switch.py b/homeassistant/components/rainbird/switch.py index cb4ac83090f..7f589401e3c 100644 --- a/homeassistant/components/rainbird/switch.py +++ b/homeassistant/components/rainbird/switch.py @@ -45,10 +45,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): name = zone_config.get(CONF_FRIENDLY_NAME) devices.append( RainBirdSwitch( - controller, - zone, - time, - name if name else "Sprinkler {}".format(zone), + controller, zone, time, name if name else f"Sprinkler {zone}", ) ) diff --git a/homeassistant/components/splunk/__init__.py b/homeassistant/components/splunk/__init__.py index 1d5d39416a3..5b26d9b1c6f 100644 --- a/homeassistant/components/splunk/__init__.py +++ b/homeassistant/components/splunk/__init__.py @@ -80,8 +80,8 @@ def setup(hass, config): else: uri_scheme = "http://" - event_collector = "{}{}:{}/services/collector/event".format(uri_scheme, host, port) - headers = {AUTHORIZATION: "Splunk {}".format(token)} + event_collector = f"{uri_scheme}{host}:{port}/services/collector/event" + headers = {AUTHORIZATION: f"Splunk {token}"} def splunk_event_listener(event): """Listen for new messages on the bus and sends them to Splunk.""" diff --git a/homeassistant/components/tellstick/sensor.py b/homeassistant/components/tellstick/sensor.py index 4a3ff75b864..93c510e2fa1 100644 --- a/homeassistant/components/tellstick/sensor.py +++ b/homeassistant/components/tellstick/sensor.py @@ -93,9 +93,9 @@ def setup_platform(hass, config, add_entities, discovery_info=None): id_ = named_sensor[CONF_ID] if proto is not None: if model is not None: - named_sensors["{}{}{}".format(proto, model, id_)] = name + named_sensors[f"{proto}{model}{id_}"] = name else: - named_sensors["{}{}".format(proto, id_)] = name + named_sensors[f"{proto}{id_}"] = name else: named_sensors[id_] = name @@ -103,7 +103,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): if not config[CONF_ONLY_NAMED]: sensor_name = str(tellcore_sensor.id) else: - proto_id = "{}{}".format(tellcore_sensor.protocol, tellcore_sensor.id) + proto_id = f"{tellcore_sensor.protocol}{tellcore_sensor.id}" proto_model_id = "{}{}{}".format( tellcore_sensor.protocol, tellcore_sensor.model, tellcore_sensor.id ) diff --git a/homeassistant/components/tensorflow/image_processing.py b/homeassistant/components/tensorflow/image_processing.py index b003fef56c0..f4eb5342c46 100644 --- a/homeassistant/components/tensorflow/image_processing.py +++ b/homeassistant/components/tensorflow/image_processing.py @@ -258,7 +258,7 @@ class TensorFlowImageProcessor(ImageProcessingEntity): 1, 1, ]: - label = "{} Detection Area".format(category.capitalize()) + label = f"{category.capitalize()} Detection Area" draw_box( draw, self._category_areas[category], diff --git a/homeassistant/components/tibber/sensor.py b/homeassistant/components/tibber/sensor.py index 9e95f3cc05b..054fad3246a 100644 --- a/homeassistant/components/tibber/sensor.py +++ b/homeassistant/components/tibber/sensor.py @@ -109,7 +109,7 @@ class TibberSensorElPrice(TibberSensor): @property def name(self): """Return the name of the sensor.""" - return "Electricity price {}".format(self._name) + return f"Electricity price {self._name}" @property def icon(self): @@ -179,7 +179,7 @@ class TibberSensorRT(TibberSensor): @property def name(self): """Return the name of the sensor.""" - return "Real time consumption {}".format(self._name) + return f"Real time consumption {self._name}" @property def should_poll(self): diff --git a/homeassistant/components/tuya/__init__.py b/homeassistant/components/tuya/__init__.py index dffd66265a6..2a1085a53e3 100644 --- a/homeassistant/components/tuya/__init__.py +++ b/homeassistant/components/tuya/__init__.py @@ -134,7 +134,7 @@ class TuyaDevice(Entity): @property def unique_id(self): """Return a unique ID.""" - return "tuya.{}".format(self.tuya.object_id()) + return f"tuya.{self.tuya.object_id()}" @property def name(self): diff --git a/homeassistant/components/wink/__init__.py b/homeassistant/components/wink/__init__.py index ceeb8b4cbc0..53bac129dbc 100644 --- a/homeassistant/components/wink/__init__.py +++ b/homeassistant/components/wink/__init__.py @@ -762,7 +762,7 @@ class WinkDevice(Entity): def unique_id(self): """Return the unique id of the Wink device.""" if hasattr(self.wink, "capability") and self.wink.capability() is not None: - return "{}_{}".format(self.wink.object_id(), self.wink.capability()) + return f"{self.wink.object_id()}_{self.wink.capability()}" return self.wink.object_id() @property diff --git a/homeassistant/components/wirelesstag/__init__.py b/homeassistant/components/wirelesstag/__init__.py index 5637cabbfd2..7296179a126 100644 --- a/homeassistant/components/wirelesstag/__init__.py +++ b/homeassistant/components/wirelesstag/__init__.py @@ -130,7 +130,7 @@ class WirelessTagPlatform: def local_base_url(self): """Define base url of hass in local network.""" if self._local_base_url is None: - self._local_base_url = "http://{}".format(util.get_local_ip()) + self._local_base_url = f"http://{util.get_local_ip()}" port = self.hass.config.api.port if port is not None: @@ -198,7 +198,7 @@ def setup(hass, config): except (ConnectTimeout, HTTPError, WirelessTagsException) as ex: _LOGGER.error("Unable to connect to wirelesstag.net service: %s", str(ex)) hass.components.persistent_notification.create( - "Error: {}
Please restart hass after fixing this.".format(ex), + f"Error: {ex}
Please restart hass after fixing this.", title=NOTIFICATION_TITLE, notification_id=NOTIFICATION_ID, ) diff --git a/homeassistant/scripts/keyring.py b/homeassistant/scripts/keyring.py index 0622b8c3d45..124449d4467 100644 --- a/homeassistant/scripts/keyring.py +++ b/homeassistant/scripts/keyring.py @@ -39,7 +39,7 @@ def run(args): print(f"Active keyring : {keyr.__module__}") config_name = os.path.join(platform.config_root(), "keyringrc.cfg") print(f"Config location : {config_name}") - print("Data location : {}\n".format(platform.data_root())) + print(f"Data location : {platform.data_root()}\n") elif args.name is None: parser.print_help() return 1