From e3bcfb88e709e756af2d47d4ca6aa04512869a7b Mon Sep 17 00:00:00 2001 From: springstan <46536646+springstan@users.noreply.github.com> Date: Sun, 5 Apr 2020 16:01:41 +0200 Subject: [PATCH] Improve string formatting v4 (#33668) * Improve string formatting v4 * Use normal strings instead of f-strings * Fix zeroconf test by adding back part of a condition --- homeassistant/components/almond/__init__.py | 6 ++---- homeassistant/components/anthemav/media_player.py | 5 ++--- homeassistant/components/braviatv/media_player.py | 6 ++++-- homeassistant/components/envisalink/sensor.py | 2 +- homeassistant/components/mqtt_statestream/__init__.py | 10 +++++----- homeassistant/components/neato/vacuum.py | 5 ++--- homeassistant/components/opencv/image_processing.py | 2 +- homeassistant/components/pioneer/media_player.py | 4 ++-- homeassistant/components/proximity/__init__.py | 2 +- homeassistant/components/rachio/const.py | 8 ++++---- homeassistant/components/raspihats/switch.py | 2 +- homeassistant/components/remember_the_milk/__init__.py | 10 ++++++---- homeassistant/components/waterfurnace/__init__.py | 2 +- homeassistant/components/websocket_api/const.py | 2 +- homeassistant/components/wink/water_heater.py | 3 +-- homeassistant/components/zeroconf/__init__.py | 4 ++-- homeassistant/components/zha/api.py | 4 ++-- homeassistant/components/zha/core/device.py | 4 ++-- script/gen_requirements_all.py | 7 ++----- script/inspect_schemas.py | 2 +- 20 files changed, 43 insertions(+), 47 deletions(-) diff --git a/homeassistant/components/almond/__init__.py b/homeassistant/components/almond/__init__.py index c9870b4cd32..58fada7a196 100644 --- a/homeassistant/components/almond/__init__.py +++ b/homeassistant/components/almond/__init__.py @@ -291,10 +291,8 @@ class AlmondAgent(conversation.AbstractConversationAgent): buffer += f"\n Picture: {message['url']}" elif message["type"] == "rdl": buffer += ( - "\n Link: " - + message["rdl"]["displayTitle"] - + " " - + message["rdl"]["webCallback"] + f"\n Link: {message['rdl']['displayTitle']} " + f"{message['rdl']['webCallback']}" ) elif message["type"] == "choice": if first_choice: diff --git a/homeassistant/components/anthemav/media_player.py b/homeassistant/components/anthemav/media_player.py index 9a64b56b575..40317ef1728 100644 --- a/homeassistant/components/anthemav/media_player.py +++ b/homeassistant/components/anthemav/media_player.py @@ -142,9 +142,8 @@ class AnthemAVR(MediaPlayerDevice): def app_name(self): """Return details about current video and audio stream.""" return ( - self._lookup("video_input_resolution_text", "") - + " " - + self._lookup("audio_input_name", "") + f"{self._lookup('video_input_resolution_text', '')} " + f"{self._lookup('audio_input_name', '')}" ) @property diff --git a/homeassistant/components/braviatv/media_player.py b/homeassistant/components/braviatv/media_player.py index d428e2deea8..31cc98f7e4b 100644 --- a/homeassistant/components/braviatv/media_player.py +++ b/homeassistant/components/braviatv/media_player.py @@ -154,8 +154,10 @@ def request_configuration(config, hass, add_entities): _CONFIGURING[host] = configurator.request_config( name, bravia_configuration_callback, - description="Enter the Pin shown on your Sony Bravia TV." - + "If no Pin is shown, enter 0000 to let TV show you a Pin.", + description=( + "Enter the Pin shown on your Sony Bravia TV." + "If no Pin is shown, enter 0000 to let TV show you a Pin." + ), description_image="/static/images/smart-tv.png", submit_caption="Confirm", fields=[{"id": "pin", "name": "Enter the pin", "type": ""}], diff --git a/homeassistant/components/envisalink/sensor.py b/homeassistant/components/envisalink/sensor.py index b4f15a2999e..3f3711b2e40 100644 --- a/homeassistant/components/envisalink/sensor.py +++ b/homeassistant/components/envisalink/sensor.py @@ -46,7 +46,7 @@ class EnvisalinkSensor(EnvisalinkDevice, Entity): self._partition_number = partition_number _LOGGER.debug("Setting up sensor for partition: %s", partition_name) - super().__init__(partition_name + " Keypad", info, controller) + super().__init__(f"{partition_name} Keypad", info, controller) async def async_added_to_hass(self): """Register callbacks.""" diff --git a/homeassistant/components/mqtt_statestream/__init__.py b/homeassistant/components/mqtt_statestream/__init__.py index e35f2653283..8e63bffe568 100644 --- a/homeassistant/components/mqtt_statestream/__init__.py +++ b/homeassistant/components/mqtt_statestream/__init__.py @@ -68,7 +68,7 @@ async def async_setup(hass, config): pub_exclude.get(CONF_ENTITIES, []), ) if not base_topic.endswith("/"): - base_topic = base_topic + "/" + base_topic = f"{base_topic}/" @callback def _state_publisher(entity_id, old_state, new_state): @@ -80,17 +80,17 @@ async def async_setup(hass, config): payload = new_state.state - mybase = base_topic + entity_id.replace(".", "/") + "/" - hass.components.mqtt.async_publish(mybase + "state", payload, 1, True) + mybase = f"{base_topic}{entity_id.replace('.', '/')}/" + hass.components.mqtt.async_publish(f"{mybase}state", payload, 1, True) if publish_timestamps: if new_state.last_updated: hass.components.mqtt.async_publish( - mybase + "last_updated", new_state.last_updated.isoformat(), 1, True + f"{mybase}last_updated", new_state.last_updated.isoformat(), 1, True ) if new_state.last_changed: hass.components.mqtt.async_publish( - mybase + "last_changed", new_state.last_changed.isoformat(), 1, True + f"{mybase}last_changed", new_state.last_changed.isoformat(), 1, True ) if publish_attributes: diff --git a/homeassistant/components/neato/vacuum.py b/homeassistant/components/neato/vacuum.py index 7a9cd1d9e45..391fcecf373 100644 --- a/homeassistant/components/neato/vacuum.py +++ b/homeassistant/components/neato/vacuum.py @@ -199,9 +199,8 @@ class NeatoConnectedVacuum(StateVacuumDevice): if robot_alert is None: self._clean_state = STATE_CLEANING self._status_state = ( - MODE.get(self._state["cleaning"]["mode"]) - + " " - + ACTION.get(self._state["action"]) + f"{MODE.get(self._state['cleaning']['mode'])} " + f"{ACTION.get(self._state['action'])}" ) if ( "boundary" in self._state["cleaning"] diff --git a/homeassistant/components/opencv/image_processing.py b/homeassistant/components/opencv/image_processing.py index 8e300c77465..c2cd62237d7 100644 --- a/homeassistant/components/opencv/image_processing.py +++ b/homeassistant/components/opencv/image_processing.py @@ -32,7 +32,7 @@ ATTR_TOTAL_MATCHES = "total_matches" CASCADE_URL = ( "https://raw.githubusercontent.com/opencv/opencv/master/data/" - + "lbpcascades/lbpcascade_frontalface.xml" + "lbpcascades/lbpcascade_frontalface.xml" ) CONF_CLASSIFIER = "classifier" diff --git a/homeassistant/components/pioneer/media_player.py b/homeassistant/components/pioneer/media_player.py index 6e902271171..899a06dc278 100644 --- a/homeassistant/components/pioneer/media_player.py +++ b/homeassistant/components/pioneer/media_player.py @@ -225,7 +225,7 @@ class PioneerDevice(MediaPlayerDevice): def set_volume_level(self, volume): """Set volume level, range 0..1.""" # 60dB max - self.telnet_command(str(round(volume * MAX_VOLUME)).zfill(3) + "VL") + self.telnet_command(f"{round(volume * MAX_VOLUME):03}VL") def mute_volume(self, mute): """Mute (true) or unmute (false) media player.""" @@ -237,4 +237,4 @@ class PioneerDevice(MediaPlayerDevice): def select_source(self, source): """Select input source.""" - self.telnet_command(self._source_name_to_number.get(source) + "FN") + self.telnet_command(f"{self._source_name_to_number.get(source)}FN") diff --git a/homeassistant/components/proximity/__init__.py b/homeassistant/components/proximity/__init__.py index 7e5f6436757..0182f6bc072 100644 --- a/homeassistant/components/proximity/__init__.py +++ b/homeassistant/components/proximity/__init__.py @@ -160,7 +160,7 @@ class Proximity(Entity): if (device_state.state).lower() == (self.friendly_name).lower(): device_friendly = device_state.name if devices_in_zone != "": - devices_in_zone = devices_in_zone + ", " + devices_in_zone = f"{devices_in_zone}, " devices_in_zone = devices_in_zone + device_friendly # No-one to track so reset the entity. diff --git a/homeassistant/components/rachio/const.py b/homeassistant/components/rachio/const.py index 587cd85a2a5..2e73bf9b116 100644 --- a/homeassistant/components/rachio/const.py +++ b/homeassistant/components/rachio/const.py @@ -54,7 +54,7 @@ RACHIO_API_EXCEPTIONS = ( STATUS_ONLINE = "ONLINE" STATUS_OFFLINE = "OFFLINE" -SIGNAL_RACHIO_UPDATE = DOMAIN + "_update" -SIGNAL_RACHIO_CONTROLLER_UPDATE = SIGNAL_RACHIO_UPDATE + "_controller" -SIGNAL_RACHIO_ZONE_UPDATE = SIGNAL_RACHIO_UPDATE + "_zone" -SIGNAL_RACHIO_SCHEDULE_UPDATE = SIGNAL_RACHIO_UPDATE + "_schedule" +SIGNAL_RACHIO_UPDATE = f"{DOMAIN}_update" +SIGNAL_RACHIO_CONTROLLER_UPDATE = f"{SIGNAL_RACHIO_UPDATE}_controller" +SIGNAL_RACHIO_ZONE_UPDATE = f"{SIGNAL_RACHIO_UPDATE}_zone" +SIGNAL_RACHIO_SCHEDULE_UPDATE = f"{SIGNAL_RACHIO_UPDATE}_schedule" diff --git a/homeassistant/components/raspihats/switch.py b/homeassistant/components/raspihats/switch.py index d6129577118..98bcb4d0aa8 100644 --- a/homeassistant/components/raspihats/switch.py +++ b/homeassistant/components/raspihats/switch.py @@ -105,7 +105,7 @@ class I2CHatSwitch(ToggleEntity): def _log_message(self, message): """Create log message.""" - string = self._name + " " + string = f"{self._name} " string += f"{self._board}I2CHat@{hex(self._address)} " string += f"channel:{str(self._channel)}{message}" return string diff --git a/homeassistant/components/remember_the_milk/__init__.py b/homeassistant/components/remember_the_milk/__init__.py index 52199b2b9c6..9de33c67158 100644 --- a/homeassistant/components/remember_the_milk/__init__.py +++ b/homeassistant/components/remember_the_milk/__init__.py @@ -137,10 +137,12 @@ def _register_new_account( request_id = configurator.async_request_config( f"{DOMAIN} - {account_name}", callback=register_account_callback, - description="You need to log in to Remember The Milk to" - + "connect your account. \n\n" - + 'Step 1: Click on the link "Remember The Milk login"\n\n' - + 'Step 2: Click on "login completed"', + description=( + "You need to log in to Remember The Milk to" + "connect your account. \n\n" + "Step 1: Click on the link 'Remember The Milk login'\n\n" + "Step 2: Click on 'login completed'" + ), link_name="Remember The Milk login", link_url=url, submit_caption="login completed", diff --git a/homeassistant/components/waterfurnace/__init__.py b/homeassistant/components/waterfurnace/__init__.py index 942ab8a14ac..2ec77e35070 100644 --- a/homeassistant/components/waterfurnace/__init__.py +++ b/homeassistant/components/waterfurnace/__init__.py @@ -14,7 +14,7 @@ from homeassistant.helpers import config_validation as cv, discovery _LOGGER = logging.getLogger(__name__) DOMAIN = "waterfurnace" -UPDATE_TOPIC = DOMAIN + "_update" +UPDATE_TOPIC = f"{DOMAIN}_update" SCAN_INTERVAL = timedelta(seconds=10) ERROR_INTERVAL = timedelta(seconds=300) MAX_FAILS = 10 diff --git a/homeassistant/components/websocket_api/const.py b/homeassistant/components/websocket_api/const.py index 61f12fd5f57..183e7008853 100644 --- a/homeassistant/components/websocket_api/const.py +++ b/homeassistant/components/websocket_api/const.py @@ -39,6 +39,6 @@ SIGNAL_WEBSOCKET_CONNECTED = "websocket_connected" SIGNAL_WEBSOCKET_DISCONNECTED = "websocket_disconnected" # Data used to store the current connection list -DATA_CONNECTIONS = DOMAIN + ".connections" +DATA_CONNECTIONS = f"{DOMAIN}.connections" JSON_DUMP = partial(json.dumps, cls=JSONEncoder, allow_nan=False) diff --git a/homeassistant/components/wink/water_heater.py b/homeassistant/components/wink/water_heater.py index 11330c7c9a5..dae6acf91bf 100644 --- a/homeassistant/components/wink/water_heater.py +++ b/homeassistant/components/wink/water_heater.py @@ -104,8 +104,7 @@ class WinkWaterHeater(WinkDevice, WaterHeaterDevice): else: error = ( "Invalid operation mode mapping. " - + mode - + " doesn't map. Please report this." + f"{mode} doesn't map. Please report this." ) _LOGGER.error(error) return op_list diff --git a/homeassistant/components/zeroconf/__init__.py b/homeassistant/components/zeroconf/__init__.py index 7e9f6e60ed5..373df9e6384 100644 --- a/homeassistant/components/zeroconf/__init__.py +++ b/homeassistant/components/zeroconf/__init__.py @@ -134,8 +134,8 @@ def handle_homekit(hass, info) -> bool: for test_model in HOMEKIT: if ( model != test_model - and not model.startswith(test_model + " ") - and not model.startswith(test_model + "-") + and not model.startswith(f"{test_model} ") + and not model.startswith(f"{test_model}-") ): continue diff --git a/homeassistant/components/zha/api.py b/homeassistant/components/zha/api.py index f3b6e2eebd9..433f9dd7ff2 100644 --- a/homeassistant/components/zha/api.py +++ b/homeassistant/components/zha/api.py @@ -774,9 +774,9 @@ async def async_binding_operation(zha_gateway, source_ieee, target_ieee, operati res = await asyncio.gather(*(t[0] for t in bind_tasks), return_exceptions=True) for outcome, log_msg in zip(res, bind_tasks): if isinstance(outcome, Exception): - fmt = log_msg[1] + " failed: %s" + fmt = f"{log_msg[1]} failed: %s" else: - fmt = log_msg[1] + " completed: %s" + fmt = f"{log_msg[1]} completed: %s" zdo.debug(fmt, *(log_msg[2] + (outcome,))) diff --git a/homeassistant/components/zha/core/device.py b/homeassistant/components/zha/core/device.py index e0d9cfa0a3e..56e8d3ddcbf 100644 --- a/homeassistant/components/zha/core/device.py +++ b/homeassistant/components/zha/core/device.py @@ -625,9 +625,9 @@ class ZHADevice(LogMixin): res = await asyncio.gather(*(t[0] for t in tasks), return_exceptions=True) for outcome, log_msg in zip(res, tasks): if isinstance(outcome, Exception): - fmt = log_msg[1] + " failed: %s" + fmt = f"{log_msg[1]} failed: %s" else: - fmt = log_msg[1] + " completed: %s" + fmt = f"{log_msg[1]} completed: %s" zdo.debug(fmt, *(log_msg[2] + (outcome,))) def log(self, level, msg, *args): diff --git a/script/gen_requirements_all.py b/script/gen_requirements_all.py index ce22b66eb35..40fb1ad8b49 100755 --- a/script/gen_requirements_all.py +++ b/script/gen_requirements_all.py @@ -102,7 +102,7 @@ def explore_module(package, explore_children): if not hasattr(module, "__path__"): return found - for _, name, _ in pkgutil.iter_modules(module.__path__, package + "."): + for _, name, _ in pkgutil.iter_modules(module.__path__, f"{package}."): found.append(name) if explore_children: @@ -169,10 +169,7 @@ def gather_requirements_from_manifests(errors, reqs): continue process_requirements( - errors, - integration.requirements, - f"homeassistant.components.{domain}", - reqs, + errors, integration.requirements, f"homeassistant.components.{domain}", reqs ) diff --git a/script/inspect_schemas.py b/script/inspect_schemas.py index 6ea37f26d10..cd72f55a855 100755 --- a/script/inspect_schemas.py +++ b/script/inspect_schemas.py @@ -13,7 +13,7 @@ def explore_module(package): module = importlib.import_module(package) if not hasattr(module, "__path__"): return [] - for _, name, _ in pkgutil.iter_modules(module.__path__, package + "."): + for _, name, _ in pkgutil.iter_modules(module.__path__, f"{package}."): yield name