diff --git a/homeassistant/__main__.py b/homeassistant/__main__.py index 8ec2a8c2d3c..8765ee6c822 100644 --- a/homeassistant/__main__.py +++ b/homeassistant/__main__.py @@ -168,7 +168,7 @@ def get_arguments() -> argparse.Namespace: parser.add_argument( "--runner", action="store_true", - help="On restart exit with code {}".format(RESTART_EXIT_CODE), + help=f"On restart exit with code {RESTART_EXIT_CODE}", ) parser.add_argument( "--script", nargs=argparse.REMAINDER, help="Run one of the embedded scripts" @@ -240,7 +240,7 @@ def write_pid(pid_file: str) -> None: with open(pid_file, "w") as file: file.write(str(pid)) except IOError: - print("Fatal Error: Unable to write pid file {}".format(pid_file)) + print(f"Fatal Error: Unable to write pid file {pid_file}") sys.exit(1) @@ -326,7 +326,7 @@ def try_to_restart() -> None: thread.is_alive() and not thread.daemon for thread in threading.enumerate() ) if nthreads > 1: - sys.stderr.write("Found {} non-daemonic threads.\n".format(nthreads)) + sys.stderr.write(f"Found {nthreads} non-daemonic threads.\n") # Somehow we sometimes seem to trigger an assertion in the python threading # module. It seems we find threads that have no associated OS level thread diff --git a/homeassistant/auth/__init__.py b/homeassistant/auth/__init__.py index 2641f0b8f7e..e2778e9f45b 100644 --- a/homeassistant/auth/__init__.py +++ b/homeassistant/auth/__init__.py @@ -278,9 +278,7 @@ class AuthManager: module = self.get_auth_mfa_module(mfa_module_id) if module is None: - raise ValueError( - "Unable find multi-factor auth module: {}".format(mfa_module_id) - ) + raise ValueError(f"Unable find multi-factor auth module: {mfa_module_id}") await module.async_setup_user(user.id, data) @@ -295,9 +293,7 @@ class AuthManager: module = self.get_auth_mfa_module(mfa_module_id) if module is None: - raise ValueError( - "Unable find multi-factor auth module: {}".format(mfa_module_id) - ) + raise ValueError(f"Unable find multi-factor auth module: {mfa_module_id}") await module.async_depose_user(user.id) @@ -356,7 +352,7 @@ class AuthManager: ): # Each client_name can only have one # long_lived_access_token type of refresh token - raise ValueError("{} already exists".format(client_name)) + raise ValueError(f"{client_name} already exists") return await self._store.async_create_refresh_token( user, diff --git a/homeassistant/auth/auth_store.py b/homeassistant/auth/auth_store.py index 82db0bcf7a9..894819fb3c7 100644 --- a/homeassistant/auth/auth_store.py +++ b/homeassistant/auth/auth_store.py @@ -94,7 +94,7 @@ class AuthStore: for group_id in group_ids or []: group = self._groups.get(group_id) if group is None: - raise ValueError("Invalid group specified {}".format(group_id)) + raise ValueError(f"Invalid group specified {group_id}") groups.append(group) kwargs = { diff --git a/homeassistant/auth/mfa_modules/__init__.py b/homeassistant/auth/mfa_modules/__init__.py index 5481b8fe08b..baccedeabbf 100644 --- a/homeassistant/auth/mfa_modules/__init__.py +++ b/homeassistant/auth/mfa_modules/__init__.py @@ -144,15 +144,13 @@ async def auth_mfa_module_from_config( async def _load_mfa_module(hass: HomeAssistant, module_name: str) -> types.ModuleType: """Load an mfa auth module.""" - module_path = "homeassistant.auth.mfa_modules.{}".format(module_name) + module_path = f"homeassistant.auth.mfa_modules.{module_name}" try: module = importlib.import_module(module_path) except ImportError as err: _LOGGER.error("Unable to load mfa module %s: %s", module_name, err) - raise HomeAssistantError( - "Unable to load mfa module {}: {}".format(module_name, err) - ) + raise HomeAssistantError(f"Unable to load mfa module {module_name}: {err}") if hass.config.skip_pip or not hasattr(module, "REQUIREMENTS"): return module diff --git a/homeassistant/auth/providers/__init__.py b/homeassistant/auth/providers/__init__.py index c35af2e0b96..ee9ef8f94cd 100644 --- a/homeassistant/auth/providers/__init__.py +++ b/homeassistant/auth/providers/__init__.py @@ -144,14 +144,10 @@ async def load_auth_provider_module( ) -> types.ModuleType: """Load an auth provider.""" try: - module = importlib.import_module( - "homeassistant.auth.providers.{}".format(provider) - ) + module = importlib.import_module(f"homeassistant.auth.providers.{provider}") except ImportError as err: _LOGGER.error("Unable to load auth provider %s: %s", provider, err) - raise HomeAssistantError( - "Unable to load auth provider {}: {}".format(provider, err) - ) + raise HomeAssistantError(f"Unable to load auth provider {provider}: {err}") if hass.config.skip_pip or not hasattr(module, "REQUIREMENTS"): return module @@ -166,7 +162,7 @@ async def load_auth_provider_module( # https://github.com/python/mypy/issues/1424 reqs = module.REQUIREMENTS # type: ignore await requirements.async_process_requirements( - hass, "auth provider {}".format(provider), reqs + hass, f"auth provider {provider}", reqs ) processed.add(provider) diff --git a/homeassistant/bootstrap.py b/homeassistant/bootstrap.py index b0eab0da0f3..3e71a588af0 100644 --- a/homeassistant/bootstrap.py +++ b/homeassistant/bootstrap.py @@ -163,7 +163,7 @@ def async_enable_logging( # ensure that the handlers it sets up wraps the correct streams. logging.basicConfig(level=logging.INFO) - colorfmt = "%(log_color)s{}%(reset)s".format(fmt) + colorfmt = f"%(log_color)s{fmt}%(reset)s" logging.getLogger().handlers[0].setFormatter( ColoredFormatter( colorfmt, diff --git a/homeassistant/components/api/__init__.py b/homeassistant/components/api/__init__.py index ee991535104..d4faa55ed8c 100644 --- a/homeassistant/components/api/__init__.py +++ b/homeassistant/components/api/__init__.py @@ -138,7 +138,7 @@ class APIEventStream(HomeAssistantView): if payload is stop_obj: break - msg = "data: {}\n\n".format(payload) + msg = f"data: {payload}\n\n" _LOGGER.debug("STREAM %s WRITING %s", id(stop_obj), msg.strip()) await response.write(msg.encode("UTF-8")) except asyncio.TimeoutError: @@ -316,7 +316,7 @@ class APIEventView(HomeAssistantView): event_type, event_data, ha.EventOrigin.remote, self.context(request) ) - return self.json_message("Event {} fired.".format(event_type)) + return self.json_message(f"Event {event_type} fired.") class APIServicesView(HomeAssistantView): @@ -388,7 +388,7 @@ class APITemplateView(HomeAssistantView): return tpl.async_render(data.get("variables")) except (ValueError, TemplateError) as ex: return self.json_message( - "Error rendering template: {}".format(ex), HTTP_BAD_REQUEST + f"Error rendering template: {ex}", HTTP_BAD_REQUEST ) diff --git a/homeassistant/components/automation/__init__.py b/homeassistant/components/automation/__init__.py index 5de9336d1d9..1cffd361b19 100644 --- a/homeassistant/components/automation/__init__.py +++ b/homeassistant/components/automation/__init__.py @@ -143,7 +143,7 @@ async def async_setup(hass, config): async def turn_onoff_service_handler(service_call): """Handle automation turn on/off service calls.""" tasks = [] - method = "async_{}".format(service_call.service) + method = f"async_{service_call.service}" for entity in await component.async_extract_from_service(service_call): tasks.append(getattr(entity, method)()) @@ -378,7 +378,7 @@ async def _async_process_config(hass, config, component): for list_no, config_block in enumerate(conf): automation_id = config_block.get(CONF_ID) - name = config_block.get(CONF_ALIAS) or "{} {}".format(config_key, list_no) + name = config_block.get(CONF_ALIAS) or f"{config_key} {list_no}" hidden = config_block[CONF_HIDE_ENTITY] initial_state = config_block.get(CONF_INITIAL_STATE) @@ -431,7 +431,7 @@ def _async_get_action(hass, config, name): await script_obj.async_run(variables, context) except Exception as err: # pylint: disable=broad-except script_obj.async_log_exception( - _LOGGER, "Error while executing automation {}".format(entity_id), err + _LOGGER, f"Error while executing automation {entity_id}", err ) return action diff --git a/homeassistant/components/config/__init__.py b/homeassistant/components/config/__init__.py index 5de11a032c5..6d4b465fceb 100644 --- a/homeassistant/components/config/__init__.py +++ b/homeassistant/components/config/__init__.py @@ -36,7 +36,7 @@ async def async_setup(hass, config): async def setup_panel(panel_name): """Set up a panel.""" - panel = importlib.import_module(".{}".format(panel_name), __name__) + panel = importlib.import_module(f".{panel_name}", __name__) if not panel: return @@ -44,7 +44,7 @@ async def async_setup(hass, config): success = await panel.async_setup(hass) if success: - key = "{}.{}".format(DOMAIN, panel_name) + key = f"{DOMAIN}.{panel_name}" hass.bus.async_fire(EVENT_COMPONENT_LOADED, {ATTR_COMPONENT: key}) @callback @@ -82,8 +82,8 @@ class BaseEditConfigView(HomeAssistantView): post_write_hook=None, ): """Initialize a config view.""" - self.url = "/api/config/%s/%s/{config_key}" % (component, config_type) - self.name = "api:config:%s:%s" % (component, config_type) + self.url = f"/api/config/{component}/{config_type}/{{config_key}}" + self.name = f"api:config:{component}:{config_type}" self.path = path self.key_schema = key_schema self.data_schema = data_schema @@ -126,14 +126,14 @@ class BaseEditConfigView(HomeAssistantView): try: self.key_schema(config_key) except vol.Invalid as err: - return self.json_message("Key malformed: {}".format(err), 400) + return self.json_message(f"Key malformed: {err}", 400) try: # We just validate, we don't store that data because # we don't want to store the defaults. self.data_schema(data) except vol.Invalid as err: - return self.json_message("Message malformed: {}".format(err), 400) + return self.json_message(f"Message malformed: {err}", 400) hass = request.app["hass"] path = hass.config.path(self.path) diff --git a/homeassistant/components/configurator/__init__.py b/homeassistant/components/configurator/__init__.py index 99995959c23..f3b2a41e917 100644 --- a/homeassistant/components/configurator/__init__.py +++ b/homeassistant/components/configurator/__init__.py @@ -61,10 +61,10 @@ def async_request_config( Will return an ID to be used for sequent calls. """ if link_name is not None and link_url is not None: - description += "\n\n[{}]({})".format(link_name, link_url) + description += f"\n\n[{link_name}]({link_url})" if description_image is not None: - description += "\n\n![Description image]({})".format(description_image) + description += f"\n\n![Description image]({description_image})" instance = hass.data.get(_KEY_INSTANCE) diff --git a/homeassistant/components/demo/camera.py b/homeassistant/components/demo/camera.py index 7ac5fc17c69..0cd77b6112e 100644 --- a/homeassistant/components/demo/camera.py +++ b/homeassistant/components/demo/camera.py @@ -28,7 +28,7 @@ class DemoCamera(Camera): self._images_index = (self._images_index + 1) % 4 image_path = os.path.join( - os.path.dirname(__file__), "demo_{}.jpg".format(self._images_index) + os.path.dirname(__file__), f"demo_{self._images_index}.jpg" ) _LOGGER.debug("Loading camera_image: %s", image_path) with open(image_path, "rb") as file: diff --git a/homeassistant/components/demo/media_player.py b/homeassistant/components/demo/media_player.py index e3f69be3020..fb64f8015c0 100644 --- a/homeassistant/components/demo/media_player.py +++ b/homeassistant/components/demo/media_player.py @@ -417,7 +417,7 @@ class DemoTVShowPlayer(AbstractDemoPlayer): @property def media_title(self): """Return the title of current playing media.""" - return "Chapter {}".format(self._cur_episode) + return f"Chapter {self._cur_episode}" @property def media_series_title(self): diff --git a/homeassistant/components/demo/vacuum.py b/homeassistant/components/demo/vacuum.py index ffd3e768b11..2ba704d3925 100644 --- a/homeassistant/components/demo/vacuum.py +++ b/homeassistant/components/demo/vacuum.py @@ -244,7 +244,7 @@ class DemoVacuum(VacuumDevice): if self.supported_features & SUPPORT_SEND_COMMAND == 0: return - self._status = "Executing {}({})".format(command, params) + self._status = f"Executing {command}({params})" self._state = True self.schedule_update_ha_state() diff --git a/homeassistant/components/frontend/__init__.py b/homeassistant/components/frontend/__init__.py index d8790b746be..7298ce8c1d0 100644 --- a/homeassistant/components/frontend/__init__.py +++ b/homeassistant/components/frontend/__init__.py @@ -274,9 +274,7 @@ async def async_setup(hass, config): ("frontend_latest", True), ("frontend_es5", True), ): - hass.http.register_static_path( - "/{}".format(path), str(root_path / path), should_cache - ) + hass.http.register_static_path(f"/{path}", str(root_path / path), should_cache) hass.http.register_static_path( "/auth/authorize", str(root_path / "authorize.html"), False @@ -294,9 +292,7 @@ async def async_setup(hass, config): # To smooth transition to new urls, add redirects to new urls of dev tools # Added June 27, 2019. Can be removed in 2021. for panel in ("event", "info", "service", "state", "template", "mqtt"): - hass.http.register_redirect( - "/dev-{}".format(panel), "/developer-tools/{}".format(panel) - ) + hass.http.register_redirect(f"/dev-{panel}", f"/developer-tools/{panel}") async_register_built_in_panel( hass, diff --git a/homeassistant/components/hassio/__init__.py b/homeassistant/components/hassio/__init__.py index 801c20b5c2b..6603728e037 100644 --- a/homeassistant/components/hassio/__init__.py +++ b/homeassistant/components/hassio/__init__.py @@ -271,7 +271,7 @@ async def async_setup(hass, config): hass.components.persistent_notification.async_create( "Config error. See dev-info panel for details.", "Config validating", - "{0}.check_config".format(HASS_DOMAIN), + f"{HASS_DOMAIN}.check_config", ) return diff --git a/homeassistant/components/hassio/handler.py b/homeassistant/components/hassio/handler.py index 10f21556fb3..5213443614c 100644 --- a/homeassistant/components/hassio/handler.py +++ b/homeassistant/components/hassio/handler.py @@ -80,7 +80,7 @@ class HassIO: This method return a coroutine. """ - return self.send_command("/addons/{}/info".format(addon), method="get") + return self.send_command(f"/addons/{addon}/info", method="get") @_api_data def get_ingress_panels(self): @@ -120,7 +120,7 @@ class HassIO: This method return a coroutine. """ - return self.send_command("/discovery/{}".format(uuid), method="get") + return self.send_command(f"/discovery/{uuid}", method="get") @_api_bool async def update_hass_api(self, http_config, refresh_token): @@ -156,7 +156,7 @@ class HassIO: with async_timeout.timeout(timeout): request = await self.websession.request( method, - "http://{}{}".format(self._ip, command), + f"http://{self._ip}{command}", json=payload, headers={X_HASSIO: os.environ.get("HASSIO_TOKEN", "")}, ) diff --git a/homeassistant/components/hassio/http.py b/homeassistant/components/hassio/http.py index f42aaca4438..3b1b8374510 100644 --- a/homeassistant/components/hassio/http.py +++ b/homeassistant/components/hassio/http.py @@ -75,7 +75,7 @@ class HassIOView(HomeAssistantView): method = getattr(self._websession, request.method.lower()) client = await method( - "http://{}/{}".format(self._host, path), + f"http://{self._host}/{path}", data=data, headers=headers, timeout=read_timeout, diff --git a/homeassistant/components/hassio/ingress.py b/homeassistant/components/hassio/ingress.py index 84e2b096362..4ecb9a8419f 100644 --- a/homeassistant/components/hassio/ingress.py +++ b/homeassistant/components/hassio/ingress.py @@ -42,7 +42,7 @@ class HassIOIngress(HomeAssistantView): def _create_url(self, token: str, path: str) -> str: """Create URL to service.""" - return "http://{}/ingress/{}/{}".format(self._host, token, path) + return f"http://{self._host}/ingress/{token}/{path}" async def _handle( self, request: web.Request, token: str, path: str @@ -91,7 +91,7 @@ class HassIOIngress(HomeAssistantView): # Support GET query if request.query_string: - url = "{}?{}".format(url, request.query_string) + url = f"{url}?{request.query_string}" # Start proxy async with self._websession.ws_connect( @@ -175,15 +175,15 @@ def _init_header( headers[X_HASSIO] = os.environ.get("HASSIO_TOKEN", "") # Ingress information - headers[X_INGRESS_PATH] = "/api/hassio_ingress/{}".format(token) + headers[X_INGRESS_PATH] = f"/api/hassio_ingress/{token}" # Set X-Forwarded-For forward_for = request.headers.get(hdrs.X_FORWARDED_FOR) connected_ip = ip_address(request.transport.get_extra_info("peername")[0]) if forward_for: - forward_for = "{}, {!s}".format(forward_for, connected_ip) + forward_for = f"{forward_for}, {connected_ip!s}" else: - forward_for = "{!s}".format(connected_ip) + forward_for = f"{connected_ip!s}" headers[hdrs.X_FORWARDED_FOR] = forward_for # Set X-Forwarded-Host diff --git a/homeassistant/components/http/__init__.py b/homeassistant/components/http/__init__.py index 5e474dafa07..a8aaa3390a7 100644 --- a/homeassistant/components/http/__init__.py +++ b/homeassistant/components/http/__init__.py @@ -133,12 +133,12 @@ class ApiConfig: if host.startswith(("http://", "https://")): self.base_url = host elif use_ssl: - self.base_url = "https://{}".format(host) + self.base_url = f"https://{host}" else: - self.base_url = "http://{}".format(host) + self.base_url = f"http://{host}" if port is not None: - self.base_url += ":{}".format(port) + self.base_url += f":{port}" async def async_setup(hass, config): @@ -268,15 +268,11 @@ class HomeAssistantHTTP: if not hasattr(view, "url"): class_name = view.__class__.__name__ - raise AttributeError( - '{0} missing required attribute "url"'.format(class_name) - ) + raise AttributeError(f'{class_name} missing required attribute "url"') if not hasattr(view, "name"): class_name = view.__class__.__name__ - raise AttributeError( - '{0} missing required attribute "name"'.format(class_name) - ) + raise AttributeError(f'{class_name} missing required attribute "name"') view.register(self.app, self.app.router) diff --git a/homeassistant/components/http/ban.py b/homeassistant/components/http/ban.py index 71e7ff38924..d8fa8853c7f 100644 --- a/homeassistant/components/http/ban.py +++ b/homeassistant/components/http/ban.py @@ -127,7 +127,7 @@ async def process_wrong_login(request): _LOGGER.warning("Banned IP %s for too many login attempts", remote_addr) hass.components.persistent_notification.async_create( - "Too many login attempts from {}".format(remote_addr), + f"Too many login attempts from {remote_addr}", "Banning IP address", NOTIFICATION_ID_BAN, ) diff --git a/homeassistant/components/http/data_validator.py b/homeassistant/components/http/data_validator.py index 634a96aa312..5945a4ca402 100644 --- a/homeassistant/components/http/data_validator.py +++ b/homeassistant/components/http/data_validator.py @@ -43,9 +43,7 @@ class RequestDataValidator: kwargs["data"] = self._schema(data) except vol.Invalid as err: _LOGGER.error("Data does not match schema: %s", err) - return view.json_message( - "Message format incorrect: {}".format(err), 400 - ) + return view.json_message(f"Message format incorrect: {err}", 400) result = await method(view, request, *args, **kwargs) return result diff --git a/homeassistant/components/http/static.py b/homeassistant/components/http/static.py index 76844407f7d..952ca473fdc 100644 --- a/homeassistant/components/http/static.py +++ b/homeassistant/components/http/static.py @@ -10,7 +10,7 @@ from aiohttp.web_urldispatcher import StaticResource # mypy: allow-untyped-defs CACHE_TIME = 31 * 86400 # = 1 month -CACHE_HEADERS = {hdrs.CACHE_CONTROL: "public, max-age={}".format(CACHE_TIME)} +CACHE_HEADERS = {hdrs.CACHE_CONTROL: f"public, max-age={CACHE_TIME}"} # https://github.com/PyCQA/astroid/issues/633 diff --git a/homeassistant/components/input_number/__init__.py b/homeassistant/components/input_number/__init__.py index 2564b8b31b4..007ed6517ef 100644 --- a/homeassistant/components/input_number/__init__.py +++ b/homeassistant/components/input_number/__init__.py @@ -49,13 +49,11 @@ def _cv_input_number(cfg): maximum = cfg.get(CONF_MAX) if minimum >= maximum: raise vol.Invalid( - "Maximum ({}) is not greater than minimum ({})".format(minimum, maximum) + f"Maximum ({minimum}) is not greater than minimum ({maximum})" ) state = cfg.get(CONF_INITIAL) if state is not None and (state < minimum or state > maximum): - raise vol.Invalid( - "Initial value {} not in range {}-{}".format(state, minimum, maximum) - ) + raise vol.Invalid(f"Initial value {state} not in range {minimum}-{maximum}") return cfg diff --git a/homeassistant/components/input_text/__init__.py b/homeassistant/components/input_text/__init__.py index 2b7c7312f71..fc49bd65ced 100644 --- a/homeassistant/components/input_text/__init__.py +++ b/homeassistant/components/input_text/__init__.py @@ -45,12 +45,12 @@ def _cv_input_text(cfg): maximum = cfg.get(CONF_MAX) if minimum > maximum: raise vol.Invalid( - "Max len ({}) is not greater than min len ({})".format(minimum, maximum) + f"Max len ({minimum}) is not greater than min len ({maximum})" ) state = cfg.get(CONF_INITIAL) if state is not None and (len(state) < minimum or len(state) > maximum): raise vol.Invalid( - "Initial value {} length not in range {}-{}".format(state, minimum, maximum) + f"Initial value {state} length not in range {minimum}-{maximum}" ) return cfg diff --git a/homeassistant/components/integration/sensor.py b/homeassistant/components/integration/sensor.py index d24b70c4be0..236a996794a 100644 --- a/homeassistant/components/integration/sensor.py +++ b/homeassistant/components/integration/sensor.py @@ -94,7 +94,7 @@ class IntegrationSensor(RestoreEntity): self._state = 0 self._method = integration_method - self._name = name if name is not None else "{} integral".format(source_entity) + self._name = name if name is not None else f"{source_entity} integral" if unit_of_measurement is None: self._unit_template = "{}{}{}".format( diff --git a/homeassistant/components/intent_script/__init__.py b/homeassistant/components/intent_script/__init__.py index 443a4cbc854..75a0c0e8f97 100644 --- a/homeassistant/components/intent_script/__init__.py +++ b/homeassistant/components/intent_script/__init__.py @@ -55,7 +55,7 @@ async def async_setup(hass, config): for intent_type, conf in intents.items(): if CONF_ACTION in conf: conf[CONF_ACTION] = script.Script( - hass, conf[CONF_ACTION], "Intent Script {}".format(intent_type) + hass, conf[CONF_ACTION], f"Intent Script {intent_type}" ) intent.async_register(hass, ScriptIntentHandler(intent_type, conf)) diff --git a/homeassistant/components/python_script/__init__.py b/homeassistant/components/python_script/__init__.py index 715c06aca43..af0865bc685 100644 --- a/homeassistant/components/python_script/__init__.py +++ b/homeassistant/components/python_script/__init__.py @@ -113,7 +113,7 @@ def discover_scripts(hass): @bind_hass def execute_script(hass, name, data=None): """Execute a script.""" - filename = "{}.py".format(name) + filename = f"{name}.py" with open(hass.config.path(FOLDER, sanitize_filename(filename))) as fil: source = fil.read() execute(hass, filename, source, data) @@ -166,9 +166,7 @@ def execute(hass, filename, source, data=None): or isinstance(obj, TimeWrapper) and name not in ALLOWED_TIME ): - raise ScriptError( - "Not allowed to access {}.{}".format(obj.__class__.__name__, name) - ) + raise ScriptError(f"Not allowed to access {obj.__class__.__name__}.{name}") return getattr(obj, name, default) @@ -188,7 +186,7 @@ def execute(hass, filename, source, data=None): "_iter_unpack_sequence_": guarded_iter_unpack_sequence, "_unpack_sequence_": guarded_unpack_sequence, } - logger = logging.getLogger("{}.{}".format(__name__, filename)) + logger = logging.getLogger(f"{__name__}.{filename}") local = {"hass": hass, "data": data or {}, "logger": logger} try: diff --git a/homeassistant/components/recorder/migration.py b/homeassistant/components/recorder/migration.py index aee993fa104..3de0430d8f3 100644 --- a/homeassistant/components/recorder/migration.py +++ b/homeassistant/components/recorder/migration.py @@ -107,7 +107,7 @@ def _drop_index(engine, table_name, index_name): # Engines like DB2/Oracle try: - engine.execute(text("DROP INDEX {index}".format(index=index_name))) + engine.execute(text(f"DROP INDEX {index_name}")) except SQLAlchemyError: pass else: @@ -170,7 +170,7 @@ def _add_columns(engine, table_name, columns_def): table_name, ) - columns_def = ["ADD {}".format(col_def) for col_def in columns_def] + columns_def = [f"ADD {col_def}" for col_def in columns_def] try: engine.execute( @@ -265,9 +265,7 @@ def _apply_update(engine, new_version, old_version): # 'context_parent_id CHARACTER(36)', # ]) else: - raise ValueError( - "No schema migration defined for version {}".format(new_version) - ) + raise ValueError(f"No schema migration defined for version {new_version}") def _inspect_schema_version(engine, session): diff --git a/homeassistant/components/script/__init__.py b/homeassistant/components/script/__init__.py index d810d50cfbf..5a3223a8508 100644 --- a/homeassistant/components/script/__init__.py +++ b/homeassistant/components/script/__init__.py @@ -209,7 +209,7 @@ class ScriptEntity(ToggleEntity): await self.script.async_run(kwargs.get(ATTR_VARIABLES), context) except Exception as err: # pylint: disable=broad-except self.script.async_log_exception( - _LOGGER, "Error executing script {}".format(self.entity_id), err + _LOGGER, f"Error executing script {self.entity_id}", err ) raise err diff --git a/homeassistant/components/system_log/__init__.py b/homeassistant/components/system_log/__init__.py index c9bd486053e..68561d45f8f 100644 --- a/homeassistant/components/system_log/__init__.py +++ b/homeassistant/components/system_log/__init__.py @@ -198,7 +198,7 @@ async def async_setup(hass, config): return if service.service == "write": logger = logging.getLogger( - service.data.get(CONF_LOGGER, "{}.external".format(__name__)) + service.data.get(CONF_LOGGER, f"{__name__}.external") ) level = service.data[CONF_LEVEL] getattr(logger, level)(service.data[CONF_MESSAGE]) diff --git a/homeassistant/components/tts/__init__.py b/homeassistant/components/tts/__init__.py index 77d24fd7aab..3e7900502d6 100644 --- a/homeassistant/components/tts/__init__.py +++ b/homeassistant/components/tts/__init__.py @@ -165,9 +165,7 @@ async def async_setup(hass, config): DOMAIN_MP, SERVICE_PLAY_MEDIA, data, blocking=True ) - service_name = p_config.get( - CONF_SERVICE_NAME, "{}_{}".format(p_type, SERVICE_SAY) - ) + service_name = p_config.get(CONF_SERVICE_NAME, f"{p_type}_{SERVICE_SAY}") hass.services.async_register( DOMAIN, service_name, async_say_handle, schema=SCHEMA_SERVICE_SAY ) @@ -229,7 +227,7 @@ class SpeechManager: init_tts_cache_dir, cache_dir ) except OSError as err: - raise HomeAssistantError("Can't init cache dir {}".format(err)) + raise HomeAssistantError(f"Can't init cache dir {err}") def get_cache_files(): """Return a dict of given engine files.""" @@ -251,7 +249,7 @@ class SpeechManager: try: cache_files = await self.hass.async_add_job(get_cache_files) except OSError as err: - raise HomeAssistantError("Can't read cache dir {}".format(err)) + raise HomeAssistantError(f"Can't read cache dir {err}") if cache_files: self.file_cache.update(cache_files) @@ -293,7 +291,7 @@ class SpeechManager: # Languages language = language or provider.default_language if language is None or language not in provider.supported_languages: - raise HomeAssistantError("Not supported language {0}".format(language)) + raise HomeAssistantError(f"Not supported language {language}") # Options if provider.default_options and options: @@ -308,9 +306,7 @@ class SpeechManager: if opt_name not in (provider.supported_options or []) ] if invalid_opts: - raise HomeAssistantError( - "Invalid options found: {}".format(invalid_opts) - ) + raise HomeAssistantError(f"Invalid options found: {invalid_opts}") options_key = ctypes.c_size_t(hash(frozenset(options))).value else: options_key = "-" @@ -330,7 +326,7 @@ class SpeechManager: engine, key, message, use_cache, language, options ) - return "{}/api/tts_proxy/{}".format(self.base_url, filename) + return f"{self.base_url}/api/tts_proxy/{filename}" async def async_get_tts_audio(self, engine, key, message, cache, language, options): """Receive TTS and store for view in cache. @@ -341,10 +337,10 @@ class SpeechManager: extension, data = await provider.async_get_tts_audio(message, language, options) if data is None or extension is None: - raise HomeAssistantError("No TTS from {} for '{}'".format(engine, message)) + raise HomeAssistantError(f"No TTS from {engine} for '{message}'") # Create file infos - filename = ("{}.{}".format(key, extension)).lower() + filename = (f"{key}.{extension}").lower() data = self.write_tags(filename, data, provider, message, language, options) @@ -381,7 +377,7 @@ class SpeechManager: """ filename = self.file_cache.get(key) if not filename: - raise HomeAssistantError("Key {} not in file cache!".format(key)) + raise HomeAssistantError(f"Key {key} not in file cache!") voice_file = os.path.join(self.cache_dir, filename) @@ -394,7 +390,7 @@ class SpeechManager: data = await self.hass.async_add_job(load_speech) except OSError: del self.file_cache[key] - raise HomeAssistantError("Can't read {}".format(voice_file)) + raise HomeAssistantError(f"Can't read {voice_file}") self._async_store_to_memcache(key, filename, data) @@ -425,7 +421,7 @@ class SpeechManager: if key not in self.mem_cache: if key not in self.file_cache: - raise HomeAssistantError("{} not in cache!".format(key)) + raise HomeAssistantError(f"{key} not in cache!") await self.async_file_to_mem(key) content, _ = mimetypes.guess_type(filename) diff --git a/homeassistant/components/utility_meter/__init__.py b/homeassistant/components/utility_meter/__init__.py index c09c43dc282..17eacc326d3 100644 --- a/homeassistant/components/utility_meter/__init__.py +++ b/homeassistant/components/utility_meter/__init__.py @@ -98,7 +98,7 @@ async def async_setup(hass, config): tariff_confs.append( { CONF_METER: meter, - CONF_NAME: "{} {}".format(meter, tariff), + CONF_NAME: f"{meter} {tariff}", CONF_TARIFF: tariff, } ) diff --git a/homeassistant/components/utility_meter/sensor.py b/homeassistant/components/utility_meter/sensor.py index 1eceaea2ae5..1ad4300b28b 100644 --- a/homeassistant/components/utility_meter/sensor.py +++ b/homeassistant/components/utility_meter/sensor.py @@ -107,7 +107,7 @@ class UtilityMeterSensor(RestoreEntity): if name: self._name = name else: - self._name = "{} meter".format(source_entity) + self._name = f"{source_entity} meter" self._unit_of_measurement = None self._period = meter_type self._period_offset = meter_offset diff --git a/homeassistant/components/zeroconf/__init__.py b/homeassistant/components/zeroconf/__init__.py index 2ed03b73eff..af107a6ae0d 100644 --- a/homeassistant/components/zeroconf/__init__.py +++ b/homeassistant/components/zeroconf/__init__.py @@ -33,7 +33,7 @@ CONFIG_SCHEMA = vol.Schema({DOMAIN: vol.Schema({})}, extra=vol.ALLOW_EXTRA) def setup(hass, config): """Set up Zeroconf and make Home Assistant discoverable.""" - zeroconf_name = "{}.{}".format(hass.config.location_name, ZEROCONF_TYPE) + zeroconf_name = f"{hass.config.location_name}.{ZEROCONF_TYPE}" params = { "version": __version__, diff --git a/homeassistant/config.py b/homeassistant/config.py index 1f42b3db25e..f4775e71805 100644 --- a/homeassistant/config.py +++ b/homeassistant/config.py @@ -317,7 +317,7 @@ async def async_hass_config_yaml(hass: HomeAssistant) -> Dict: path = find_config_file(hass.config.config_dir) if path is None: raise HomeAssistantError( - "Config file not found in: {}".format(hass.config.config_dir) + f"Config file not found in: {hass.config.config_dir}" ) config = load_yaml_config_file(path) return config @@ -443,7 +443,7 @@ def _format_config_error(ex: vol.Invalid, domain: str, config: Dict) -> str: This method must be run in the event loop. """ - message = "Invalid config for [{}]: ".format(domain) + message = f"Invalid config for [{domain}]: " if "extra keys not allowed" in ex.error_message: message += ( "[{option}] is an invalid option for [{domain}]. " @@ -705,7 +705,7 @@ async def merge_packages_config( error = _recursive_merge(conf=config[comp_name], package=comp_conf) if error: _log_pkg_error( - pack_name, comp_name, config, "has duplicate key '{}'".format(error) + pack_name, comp_name, config, f"has duplicate key '{error}'" ) return config @@ -777,7 +777,7 @@ async def async_process_component_config( p_config ) except vol.Invalid as ex: - async_log_exception(ex, "{}.{}".format(domain, p_name), p_config, hass) + async_log_exception(ex, f"{domain}.{p_name}", p_config, hass) continue platforms.append(p_validated) @@ -836,7 +836,7 @@ def async_notify_setup_error( else: part = name - message += " - {}\n".format(part) + message += f" - {part}\n" message += "\nPlease check your config." diff --git a/homeassistant/core.py b/homeassistant/core.py index e8e33a0479e..4d7596d667b 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -1365,7 +1365,7 @@ class Config: self.time_zone = time_zone dt_util.set_default_time_zone(time_zone) else: - raise ValueError("Received invalid time zone {}".format(time_zone_str)) + raise ValueError(f"Received invalid time zone {time_zone_str}") @callback def _update( diff --git a/homeassistant/data_entry_flow.py b/homeassistant/data_entry_flow.py index 0af6677dceb..6bbd757fca6 100644 --- a/homeassistant/data_entry_flow.py +++ b/homeassistant/data_entry_flow.py @@ -126,7 +126,7 @@ class FlowManager: self, flow: Any, step_id: str, user_input: Optional[Dict] ) -> Dict: """Handle a step of a flow.""" - method = "async_step_{}".format(step_id) + method = f"async_step_{step_id}" if not hasattr(flow, method): self._progress.pop(flow.flow_id) diff --git a/homeassistant/exceptions.py b/homeassistant/exceptions.py index dfb001ff0d7..89caf730ad7 100644 --- a/homeassistant/exceptions.py +++ b/homeassistant/exceptions.py @@ -25,7 +25,7 @@ class TemplateError(HomeAssistantError): def __init__(self, exception: jinja2.TemplateError) -> None: """Init the error.""" - super().__init__("{}: {}".format(exception.__class__.__name__, exception)) + super().__init__(f"{exception.__class__.__name__}: {exception}") class PlatformNotReady(HomeAssistantError): @@ -73,10 +73,10 @@ class ServiceNotFound(HomeAssistantError): def __init__(self, domain: str, service: str) -> None: """Initialize error.""" - super().__init__(self, "Service {}.{} not found".format(domain, service)) + super().__init__(self, f"Service {domain}.{service} not found") self.domain = domain self.service = service def __str__(self) -> str: """Return string representation.""" - return "Unable to find service {}/{}".format(self.domain, self.service) + return f"Unable to find service {self.domain}/{self.service}" diff --git a/homeassistant/helpers/check_config.py b/homeassistant/helpers/check_config.py index bc39d5d5720..f49ae976827 100644 --- a/homeassistant/helpers/check_config.py +++ b/homeassistant/helpers/check_config.py @@ -62,7 +62,7 @@ async def async_check_ha_config_file(hass: HomeAssistant) -> HomeAssistantConfig message = "Package {} setup failed. Component {} {}".format( package, component, message ) - domain = "homeassistant.packages.{}.{}".format(package, component) + domain = f"homeassistant.packages.{package}.{component}" pack_config = core_config[CONF_PACKAGES].get(package, config) result.add_error(message, domain, pack_config) @@ -77,9 +77,9 @@ async def async_check_ha_config_file(hass: HomeAssistant) -> HomeAssistantConfig return result.add_error("File configuration.yaml not found.") config = await hass.async_add_executor_job(load_yaml_config_file, config_path) except FileNotFoundError: - return result.add_error("File not found: {}".format(config_path)) + return result.add_error(f"File not found: {config_path}") except HomeAssistantError as err: - return result.add_error("Error loading {}: {}".format(config_path, err)) + return result.add_error(f"Error loading {config_path}: {err}") finally: yaml_loader.clear_secret_cache() @@ -106,13 +106,13 @@ async def async_check_ha_config_file(hass: HomeAssistant) -> HomeAssistantConfig try: integration = await async_get_integration_with_requirements(hass, domain) except (RequirementsNotFound, loader.IntegrationNotFound) as ex: - result.add_error("Component error: {} - {}".format(domain, ex)) + result.add_error(f"Component error: {domain} - {ex}") continue try: component = integration.get_component() except ImportError as ex: - result.add_error("Component error: {} - {}".format(domain, ex)) + result.add_error(f"Component error: {domain} - {ex}") continue config_schema = getattr(component, "CONFIG_SCHEMA", None) @@ -159,7 +159,7 @@ async def async_check_ha_config_file(hass: HomeAssistant) -> HomeAssistantConfig RequirementsNotFound, ImportError, ) as ex: - result.add_error("Platform error {}.{} - {}".format(domain, p_name, ex)) + result.add_error(f"Platform error {domain}.{p_name} - {ex}") continue # Validate platform specific schema @@ -168,7 +168,7 @@ async def async_check_ha_config_file(hass: HomeAssistant) -> HomeAssistantConfig try: p_validated = platform_schema(p_validated) except vol.Invalid as ex: - _comp_error(ex, "{}.{}".format(domain, p_name), p_validated) + _comp_error(ex, f"{domain}.{p_name}", p_validated) continue platforms.append(p_validated) diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index bd96e1bafdb..dc2e46cc6b2 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -243,11 +243,11 @@ class Entity: This method must be run in the event loop. """ if self.hass is None: - raise RuntimeError("Attribute hass is None for {}".format(self)) + raise RuntimeError(f"Attribute hass is None for {self}") if self.entity_id is None: raise NoEntitySpecifiedError( - "No entity id specified for entity {}".format(self.name) + f"No entity id specified for entity {self.name}" ) # update entity data @@ -264,11 +264,11 @@ class Entity: def async_write_ha_state(self): """Write the state to the state machine.""" if self.hass is None: - raise RuntimeError("Attribute hass is None for {}".format(self)) + raise RuntimeError(f"Attribute hass is None for {self}") if self.entity_id is None: raise NoEntitySpecifiedError( - "No entity id specified for entity {}".format(self.name) + f"No entity id specified for entity {self.name}" ) self._async_write_ha_state() diff --git a/homeassistant/helpers/entity_component.py b/homeassistant/helpers/entity_component.py index b28beeaea72..a9237635702 100644 --- a/homeassistant/helpers/entity_component.py +++ b/homeassistant/helpers/entity_component.py @@ -205,7 +205,7 @@ class EntityComponent: async def handle_service(call): """Handle the service.""" - service_name = "{}.{}".format(self.domain, name) + service_name = f"{self.domain}.{name}" await self.hass.helpers.service.entity_service_call( self._platforms.values(), func, call, service_name, required_features ) diff --git a/homeassistant/helpers/entity_platform.py b/homeassistant/helpers/entity_platform.py index 4a6a3038fd0..7d5debd484d 100644 --- a/homeassistant/helpers/entity_platform.py +++ b/homeassistant/helpers/entity_platform.py @@ -133,7 +133,7 @@ class EntityPlatform: current_platform.set(self) logger = self.logger hass = self.hass - full_name = "{}.{}".format(self.domain, self.platform_name) + full_name = f"{self.domain}.{self.platform_name}" logger.info("Setting up %s", full_name) warn_task = hass.loop.call_later( @@ -357,7 +357,7 @@ class EntityPlatform: "Not adding entity %s because it's disabled", entry.name or entity.name - or '"{} {}"'.format(self.platform_name, entity.unique_id), + or f'"{self.platform_name} {entity.unique_id}"', ) return @@ -386,12 +386,12 @@ class EntityPlatform: # Make sure it is valid in case an entity set the value themselves if not valid_entity_id(entity.entity_id): - raise HomeAssistantError("Invalid entity id: {}".format(entity.entity_id)) + raise HomeAssistantError(f"Invalid entity id: {entity.entity_id}") if ( entity.entity_id in self.entities or entity.entity_id in self.hass.states.async_entity_ids(self.domain) ): - msg = "Entity id already exists: {}".format(entity.entity_id) + msg = f"Entity id already exists: {entity.entity_id}" if entity.unique_id is not None: msg += ". Platform {} does not generate unique IDs".format( self.platform_name diff --git a/homeassistant/helpers/entity_registry.py b/homeassistant/helpers/entity_registry.py index 7d81f62fa1c..3be00c859a7 100644 --- a/homeassistant/helpers/entity_registry.py +++ b/homeassistant/helpers/entity_registry.py @@ -166,9 +166,7 @@ class EntityRegistry: ) entity_id = self.async_generate_entity_id( - domain, - suggested_object_id or "{}_{}".format(platform, unique_id), - known_object_ids, + domain, suggested_object_id or f"{platform}_{unique_id}", known_object_ids ) if ( diff --git a/homeassistant/helpers/intent.py b/homeassistant/helpers/intent.py index ffd5918810f..4fb0d94287c 100644 --- a/homeassistant/helpers/intent.py +++ b/homeassistant/helpers/intent.py @@ -58,7 +58,7 @@ async def async_handle( handler = hass.data.get(DATA_KEY, {}).get(intent_type) # type: IntentHandler if handler is None: - raise UnknownIntent("Unknown intent {}".format(intent_type)) + raise UnknownIntent(f"Unknown intent {intent_type}") intent = Intent(hass, platform, intent_type, slots or {}, text_input) @@ -68,13 +68,11 @@ async def async_handle( return result except vol.Invalid as err: _LOGGER.warning("Received invalid slot info for %s: %s", intent_type, err) - raise InvalidSlotInfo( - "Received invalid slot info for {}".format(intent_type) - ) from err + raise InvalidSlotInfo(f"Received invalid slot info for {intent_type}") from err except IntentHandleError: raise except Exception as err: - raise IntentUnexpectedError("Error handling {}".format(intent_type)) from err + raise IntentUnexpectedError(f"Error handling {intent_type}") from err class IntentError(HomeAssistantError): @@ -109,7 +107,7 @@ def async_match_state( state = _fuzzymatch(name, states, lambda state: state.name) if state is None: - raise IntentHandleError("Unable to find an entity called {}".format(name)) + raise IntentHandleError(f"Unable to find an entity called {name}") return state @@ -118,9 +116,7 @@ def async_match_state( def async_test_feature(state: State, feature: int, feature_name: str) -> None: """Test is state supports a feature.""" if state.attributes.get(ATTR_SUPPORTED_FEATURES, 0) & feature == 0: - raise IntentHandleError( - "Entity {} does not support {}".format(state.name, feature_name) - ) + raise IntentHandleError(f"Entity {state.name} does not support {feature_name}") class IntentHandler: diff --git a/homeassistant/helpers/temperature.py b/homeassistant/helpers/temperature.py index 8b32b1355fa..30b428a9e17 100644 --- a/homeassistant/helpers/temperature.py +++ b/homeassistant/helpers/temperature.py @@ -20,7 +20,7 @@ def display_temp( # If the temperature is not a number this can cause issues # with Polymer components, so bail early there. if not isinstance(temperature, Number): - raise TypeError("Temperature is not a number: {}".format(temperature)) + raise TypeError(f"Temperature is not a number: {temperature}") # type ignore: https://github.com/python/mypy/issues/7207 if temperature_unit != ha_unit: # type: ignore diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py index ca320cb1c33..98e3849bfb6 100644 --- a/homeassistant/helpers/template.py +++ b/homeassistant/helpers/template.py @@ -320,10 +320,10 @@ class AllStates: """Return the domain state.""" if "." in name: if not valid_entity_id(name): - raise TemplateError("Invalid entity ID '{}'".format(name)) + raise TemplateError(f"Invalid entity ID '{name}'") return _get_state(self._hass, name) if not valid_entity_id(name + ".entity"): - raise TemplateError("Invalid domain name '{}'".format(name)) + raise TemplateError(f"Invalid domain name '{name}'") return DomainStates(self._hass, name) def _collect_all(self): @@ -367,9 +367,9 @@ class DomainStates: def __getattr__(self, name): """Return the states.""" - entity_id = "{}.{}".format(self._domain, name) + entity_id = f"{self._domain}.{name}" if not valid_entity_id(entity_id): - raise TemplateError("Invalid entity ID '{}'".format(entity_id)) + raise TemplateError(f"Invalid entity ID '{entity_id}'") return _get_state(self._hass, entity_id) def _collect_domain(self): @@ -399,7 +399,7 @@ class DomainStates: def __repr__(self): """Representation of Domain States.""" - return "