From ba0aaeeddb7873ad3cbfbccc5803dbce88b5e833 Mon Sep 17 00:00:00 2001
From: springstan <46536646+springstan@users.noreply.github.com>
Date: Tue, 10 Mar 2020 23:34:54 +0100
Subject: [PATCH] Use f-strings in integrations starting with "M" (#32271)
* Use f-strings in integrations starting with "M"
* Format mqtt light init with black
* Fix lint error
* Fix pylint error
* Restore constants
* Update homeassistant/components/mqtt/discovery.py
* Update homeassistant/components/mqtt/discovery.py
* Update homeassistant/components/mqtt/discovery.py
* Update homeassistant/components/mqtt/discovery.py
* Format with Black
---
homeassistant/components/magicseaweed/sensor.py | 10 ++--------
homeassistant/components/mailgun/notify.py | 3 +--
homeassistant/components/maxcube/__init__.py | 4 +---
.../components/maxcube/binary_sensor.py | 2 +-
homeassistant/components/maxcube/climate.py | 2 +-
.../components/media_player/__init__.py | 6 ++++--
.../components/mediaroom/media_player.py | 2 +-
homeassistant/components/met/const.py | 3 +--
homeassistant/components/met/weather.py | 2 +-
homeassistant/components/metoffice/sensor.py | 2 +-
homeassistant/components/mhz19/sensor.py | 2 +-
.../microsoft_face_detect/image_processing.py | 2 +-
.../microsoft_face_identify/image_processing.py | 2 +-
homeassistant/components/min_max/sensor.py | 4 +---
homeassistant/components/mobile_app/__init__.py | 2 +-
homeassistant/components/mobile_app/notify.py | 4 ++--
homeassistant/components/mobile_app/webhook.py | 2 +-
homeassistant/components/modbus/climate.py | 2 +-
homeassistant/components/modbus/sensor.py | 4 ++--
.../components/mold_indicator/sensor.py | 2 +-
homeassistant/components/mopar/__init__.py | 2 +-
homeassistant/components/mopar/lock.py | 2 +-
homeassistant/components/mopar/switch.py | 2 +-
homeassistant/components/mqtt/__init__.py | 7 ++++---
homeassistant/components/mqtt/discovery.py | 16 +++++++---------
.../components/mqtt/light/schema_basic.py | 8 ++++----
homeassistant/components/mqtt/server.py | 4 +---
homeassistant/components/mqtt_room/sensor.py | 2 +-
.../components/mychevy/binary_sensor.py | 11 +++++------
homeassistant/components/mychevy/sensor.py | 8 ++------
homeassistant/components/mysensors/__init__.py | 2 +-
homeassistant/components/mysensors/gateway.py | 5 ++---
homeassistant/components/mysensors/helpers.py | 4 ++--
homeassistant/components/ps4/media_player.py | 7 ++++---
34 files changed, 62 insertions(+), 80 deletions(-)
diff --git a/homeassistant/components/magicseaweed/sensor.py b/homeassistant/components/magicseaweed/sensor.py
index 174ecf1882e..9364bee27b2 100644
--- a/homeassistant/components/magicseaweed/sensor.py
+++ b/homeassistant/components/magicseaweed/sensor.py
@@ -154,18 +154,12 @@ class MagicSeaweedSensor(Entity):
elif self.type == "max_breaking_swell":
self._state = forecast.swell_maxBreakingHeight
elif self.type == "swell_forecast":
- summary = "{} - {}".format(
- forecast.swell_minBreakingHeight, forecast.swell_maxBreakingHeight
- )
+ summary = f"{forecast.swell_minBreakingHeight} - {forecast.swell_maxBreakingHeight}"
self._state = summary
if self.hour is None:
for hour, data in self.data.hourly.items():
occurs = hour
- hr_summary = "{} - {} {}".format(
- data.swell_minBreakingHeight,
- data.swell_maxBreakingHeight,
- data.swell_unit,
- )
+ hr_summary = f"{data.swell_minBreakingHeight} - {data.swell_maxBreakingHeight} {data.swell_unit}"
self._attrs[occurs] = hr_summary
if self.type != "swell_forecast":
diff --git a/homeassistant/components/mailgun/notify.py b/homeassistant/components/mailgun/notify.py
index c2222cfd742..5ff57914be0 100644
--- a/homeassistant/components/mailgun/notify.py
+++ b/homeassistant/components/mailgun/notify.py
@@ -25,7 +25,6 @@ _LOGGER = logging.getLogger(__name__)
# Images to attach to notification
ATTR_IMAGES = "images"
-DEFAULT_SENDER = "hass@{domain}"
DEFAULT_SANDBOX = False
# pylint: disable=no-value-for-parameter
@@ -69,7 +68,7 @@ class MailgunNotificationService(BaseNotificationService):
_LOGGER.debug("Mailgun domain: %s", self._client.domain)
self._domain = self._client.domain
if not self._sender:
- self._sender = DEFAULT_SENDER.format(domain=self._domain)
+ self._sender = f"hass@{self._domain}"
def connection_is_valid(self):
"""Check whether the provided credentials are valid."""
diff --git a/homeassistant/components/maxcube/__init__.py b/homeassistant/components/maxcube/__init__.py
index 3e6ecbc948b..ffd156b5e00 100644
--- a/homeassistant/components/maxcube/__init__.py
+++ b/homeassistant/components/maxcube/__init__.py
@@ -65,9 +65,7 @@ def setup(hass, config):
except timeout as ex:
_LOGGER.error("Unable to connect to Max!Cube gateway: %s", str(ex))
hass.components.persistent_notification.create(
- "Error: {}
"
- "You will need to restart Home Assistant after fixing."
- "".format(ex),
+ f"Error: {ex}
You will need to restart Home Assistant after fixing.",
title=NOTIFICATION_TITLE,
notification_id=NOTIFICATION_ID,
)
diff --git a/homeassistant/components/maxcube/binary_sensor.py b/homeassistant/components/maxcube/binary_sensor.py
index 639b670baa8..2670b61b456 100644
--- a/homeassistant/components/maxcube/binary_sensor.py
+++ b/homeassistant/components/maxcube/binary_sensor.py
@@ -14,7 +14,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
for handler in hass.data[DATA_KEY].values():
cube = handler.cube
for device in cube.devices:
- name = "{} {}".format(cube.room_by_id(device.room_id).name, device.name)
+ name = f"{cube.room_by_id(device.room_id).name} {device.name}"
# Only add Window Shutters
if cube.is_windowshutter(device):
diff --git a/homeassistant/components/maxcube/climate.py b/homeassistant/components/maxcube/climate.py
index a6a63ddc0fd..e723853f629 100644
--- a/homeassistant/components/maxcube/climate.py
+++ b/homeassistant/components/maxcube/climate.py
@@ -34,7 +34,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
for handler in hass.data[DATA_KEY].values():
cube = handler.cube
for device in cube.devices:
- name = "{} {}".format(cube.room_by_id(device.room_id).name, device.name)
+ name = f"{cube.room_by_id(device.room_id).name} {device.name}"
if cube.is_thermostat(device) or cube.is_wallthermostat(device):
devices.append(MaxCubeClimate(handler, name, device.rf_address))
diff --git a/homeassistant/components/media_player/__init__.py b/homeassistant/components/media_player/__init__.py
index a62b6bd7c2b..757dd00897d 100644
--- a/homeassistant/components/media_player/__init__.py
+++ b/homeassistant/components/media_player/__init__.py
@@ -104,7 +104,6 @@ _RND = SystemRandom()
ENTITY_ID_FORMAT = DOMAIN + ".{}"
-ENTITY_IMAGE_URL = "/api/media_player_proxy/{0}?token={1}&cache={2}"
CACHE_IMAGES = "images"
CACHE_MAXSIZE = "maxsize"
CACHE_LOCK = "lock"
@@ -767,7 +766,10 @@ class MediaPlayerDevice(Entity):
if image_hash is None:
return None
- return ENTITY_IMAGE_URL.format(self.entity_id, self.access_token, image_hash)
+ return (
+ f"/api/media_player_proxy/{self.entity_id}?"
+ f"token={self.access_token}&cache={image_hash}"
+ )
@property
def capability_attributes(self):
diff --git a/homeassistant/components/mediaroom/media_player.py b/homeassistant/components/mediaroom/media_player.py
index 539138783ee..28d20d0db4b 100644
--- a/homeassistant/components/mediaroom/media_player.py
+++ b/homeassistant/components/mediaroom/media_player.py
@@ -147,7 +147,7 @@ class MediaroomDevice(MediaPlayerDevice):
self._channel = None
self._optimistic = optimistic
self._state = STATE_PLAYING if optimistic else STATE_STANDBY
- self._name = "Mediaroom {}".format(device_id if device_id else host)
+ self._name = f"Mediaroom {device_id if device_id else host}"
self._available = True
if device_id:
self._unique_id = device_id
diff --git a/homeassistant/components/met/const.py b/homeassistant/components/met/const.py
index e60dab5072f..f29f034df68 100644
--- a/homeassistant/components/met/const.py
+++ b/homeassistant/components/met/const.py
@@ -9,7 +9,6 @@ HOME_LOCATION_NAME = "Home"
CONF_TRACK_HOME = "track_home"
-ENTITY_ID_SENSOR_FORMAT = WEATHER_DOMAIN + ".met_{}"
-ENTITY_ID_SENSOR_FORMAT_HOME = ENTITY_ID_SENSOR_FORMAT.format(HOME_LOCATION_NAME)
+ENTITY_ID_SENSOR_FORMAT_HOME = f"{WEATHER_DOMAIN}.met_{HOME_LOCATION_NAME}"
_LOGGER = logging.getLogger(".")
diff --git a/homeassistant/components/met/weather.py b/homeassistant/components/met/weather.py
index d99573a985e..13150098452 100644
--- a/homeassistant/components/met/weather.py
+++ b/homeassistant/components/met/weather.py
@@ -168,7 +168,7 @@ class MetWeather(WeatherEntity):
if self.track_home:
return "home"
- return "{}-{}".format(self._config[CONF_LATITUDE], self._config[CONF_LONGITUDE])
+ return f"{self._config[CONF_LATITUDE]}-{self._config[CONF_LONGITUDE]}"
@property
def name(self):
diff --git a/homeassistant/components/metoffice/sensor.py b/homeassistant/components/metoffice/sensor.py
index 1c4ca83e5bd..d04f7c5f582 100644
--- a/homeassistant/components/metoffice/sensor.py
+++ b/homeassistant/components/metoffice/sensor.py
@@ -141,7 +141,7 @@ class MetOfficeCurrentSensor(Entity):
@property
def name(self):
"""Return the name of the sensor."""
- return "{} {}".format(self._name, SENSOR_TYPES[self._condition][0])
+ return f"{self._name} {SENSOR_TYPES[self._condition][0]}"
@property
def state(self):
diff --git a/homeassistant/components/mhz19/sensor.py b/homeassistant/components/mhz19/sensor.py
index 961d8646979..892895b9e02 100644
--- a/homeassistant/components/mhz19/sensor.py
+++ b/homeassistant/components/mhz19/sensor.py
@@ -85,7 +85,7 @@ class MHZ19Sensor(Entity):
@property
def name(self):
"""Return the name of the sensor."""
- return "{}: {}".format(self._name, SENSOR_TYPES[self._sensor_type][0])
+ return f"{self._name}: {SENSOR_TYPES[self._sensor_type][0]}"
@property
def state(self):
diff --git a/homeassistant/components/microsoft_face_detect/image_processing.py b/homeassistant/components/microsoft_face_detect/image_processing.py
index c10f7edf9db..3b0580a3eeb 100644
--- a/homeassistant/components/microsoft_face_detect/image_processing.py
+++ b/homeassistant/components/microsoft_face_detect/image_processing.py
@@ -73,7 +73,7 @@ class MicrosoftFaceDetectEntity(ImageProcessingFaceEntity):
if name:
self._name = name
else:
- self._name = "MicrosoftFace {0}".format(split_entity_id(camera_entity)[1])
+ self._name = f"MicrosoftFace {split_entity_id(camera_entity)[1]}"
@property
def camera_entity(self):
diff --git a/homeassistant/components/microsoft_face_identify/image_processing.py b/homeassistant/components/microsoft_face_identify/image_processing.py
index 820292eb365..1065e64a110 100644
--- a/homeassistant/components/microsoft_face_identify/image_processing.py
+++ b/homeassistant/components/microsoft_face_identify/image_processing.py
@@ -61,7 +61,7 @@ class MicrosoftFaceIdentifyEntity(ImageProcessingFaceEntity):
if name:
self._name = name
else:
- self._name = "MicrosoftFace {0}".format(split_entity_id(camera_entity)[1])
+ self._name = f"MicrosoftFace {split_entity_id(camera_entity)[1]}"
@property
def confidence(self):
diff --git a/homeassistant/components/min_max/sensor.py b/homeassistant/components/min_max/sensor.py
index 80beaf1f798..aa58cc0be21 100644
--- a/homeassistant/components/min_max/sensor.py
+++ b/homeassistant/components/min_max/sensor.py
@@ -115,9 +115,7 @@ class MinMaxSensor(Entity):
if name:
self._name = name
else:
- self._name = "{} sensor".format(
- next(v for k, v in SENSOR_TYPES.items() if self._sensor_type == v)
- ).capitalize()
+ self._name = f"{next(v for k, v in SENSOR_TYPES.items() if self._sensor_type == v)} sensor".capitalize()
self._unit_of_measurement = None
self._unit_of_measurement_mismatch = False
self.min_value = self.max_value = self.mean = self.last = None
diff --git a/homeassistant/components/mobile_app/__init__.py b/homeassistant/components/mobile_app/__init__.py
index fcf95da586e..4396f8c8e0c 100644
--- a/homeassistant/components/mobile_app/__init__.py
+++ b/homeassistant/components/mobile_app/__init__.py
@@ -93,7 +93,7 @@ async def async_setup_entry(hass, entry):
hass.data[DOMAIN][DATA_DEVICES][webhook_id] = device
- registration_name = "Mobile App: {}".format(registration[ATTR_DEVICE_NAME])
+ registration_name = f"Mobile App: {registration[ATTR_DEVICE_NAME]}"
webhook_register(hass, DOMAIN, registration_name, webhook_id, handle_webhook)
for domain in PLATFORMS:
diff --git a/homeassistant/components/mobile_app/notify.py b/homeassistant/components/mobile_app/notify.py
index b16c47e29c0..00f4577ad9e 100644
--- a/homeassistant/components/mobile_app/notify.py
+++ b/homeassistant/components/mobile_app/notify.py
@@ -139,8 +139,8 @@ class MobileAppNotificationService(BaseNotificationService):
continue
fallback_error = result.get("errorMessage", "Unknown error")
- fallback_message = "Internal server error, please try again later: {}".format(
- fallback_error
+ fallback_message = (
+ f"Internal server error, please try again later: {fallback_error}"
)
message = result.get("message", fallback_message)
if response.status == 429:
diff --git a/homeassistant/components/mobile_app/webhook.py b/homeassistant/components/mobile_app/webhook.py
index c47f38986a1..adc90c15e98 100644
--- a/homeassistant/components/mobile_app/webhook.py
+++ b/homeassistant/components/mobile_app/webhook.py
@@ -381,7 +381,7 @@ async def webhook_register_sensor(hass, config_entry, data):
_LOGGER.error("Error registering sensor: %s", ex)
return empty_okay_response()
- register_signal = "{}_{}_register".format(DOMAIN, data[ATTR_SENSOR_TYPE])
+ register_signal = f"{DOMAIN}_{data[ATTR_SENSOR_TYPE]}_register"
async_dispatcher_send(hass, register_signal, data)
return webhook_response(
diff --git a/homeassistant/components/modbus/climate.py b/homeassistant/components/modbus/climate.py
index c0423849418..f83b7d7b901 100644
--- a/homeassistant/components/modbus/climate.py
+++ b/homeassistant/components/modbus/climate.py
@@ -162,7 +162,7 @@ class ModbusThermostat(ClimateDevice):
DATA_TYPE_FLOAT: {1: "e", 2: "f", 4: "d"},
}
- self._structure = ">{}".format(data_types[self._data_type][self._count])
+ self._structure = f">{data_types[self._data_type][self._count]}"
@property
def supported_features(self):
diff --git a/homeassistant/components/modbus/sensor.py b/homeassistant/components/modbus/sensor.py
index 716cb5299b7..b586ad852df 100644
--- a/homeassistant/components/modbus/sensor.py
+++ b/homeassistant/components/modbus/sensor.py
@@ -99,8 +99,8 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
structure = ">i"
if register[CONF_DATA_TYPE] != DATA_TYPE_CUSTOM:
try:
- structure = ">{}".format(
- data_types[register[CONF_DATA_TYPE]][register[CONF_COUNT]]
+ structure = (
+ f">{data_types[register[CONF_DATA_TYPE]][register[CONF_COUNT]]}"
)
except KeyError:
_LOGGER.error(
diff --git a/homeassistant/components/mold_indicator/sensor.py b/homeassistant/components/mold_indicator/sensor.py
index b5c72fdce29..374866a6859 100644
--- a/homeassistant/components/mold_indicator/sensor.py
+++ b/homeassistant/components/mold_indicator/sensor.py
@@ -344,7 +344,7 @@ class MoldIndicator(Entity):
elif crit_humidity < 0:
self._state = "0"
else:
- self._state = "{0:d}".format(int(crit_humidity))
+ self._state = f"{int(crit_humidity):d}"
_LOGGER.debug("Mold indicator humidity: %s", self._state)
diff --git a/homeassistant/components/mopar/__init__.py b/homeassistant/components/mopar/__init__.py
index 21a3c3d16ea..4801a7c43d6 100644
--- a/homeassistant/components/mopar/__init__.py
+++ b/homeassistant/components/mopar/__init__.py
@@ -127,7 +127,7 @@ class MoparData:
vehicle = self.vehicles[index]
if not vehicle:
return None
- return "{} {} {}".format(vehicle["year"], vehicle["make"], vehicle["model"])
+ return f"{vehicle['year']} {vehicle['make']} {vehicle['model']}"
def actuate(self, command, index):
"""Run a command on the specified Mopar vehicle."""
diff --git a/homeassistant/components/mopar/lock.py b/homeassistant/components/mopar/lock.py
index 49e25ad30c0..3933e567723 100644
--- a/homeassistant/components/mopar/lock.py
+++ b/homeassistant/components/mopar/lock.py
@@ -22,7 +22,7 @@ class MoparLock(LockDevice):
def __init__(self, data, index):
"""Initialize the Mopar lock."""
self._index = index
- self._name = "{} Lock".format(data.get_vehicle_name(self._index))
+ self._name = f"{data.get_vehicle_name(self._index)} Lock"
self._actuate = data.actuate
self._state = None
diff --git a/homeassistant/components/mopar/switch.py b/homeassistant/components/mopar/switch.py
index 2dad56637ce..c7a8c762fbc 100644
--- a/homeassistant/components/mopar/switch.py
+++ b/homeassistant/components/mopar/switch.py
@@ -22,7 +22,7 @@ class MoparSwitch(SwitchDevice):
def __init__(self, data, index):
"""Initialize the Switch."""
self._index = index
- self._name = "{} Switch".format(data.get_vehicle_name(self._index))
+ self._name = f"{data.get_vehicle_name(self._index)} Switch"
self._actuate = data.actuate
self._state = None
diff --git a/homeassistant/components/mqtt/__init__.py b/homeassistant/components/mqtt/__init__.py
index bb38c36090a..fbbf4f42d7a 100644
--- a/homeassistant/components/mqtt/__init__.py
+++ b/homeassistant/components/mqtt/__init__.py
@@ -437,8 +437,9 @@ async def async_subscribe(
topic,
catch_log_exception(
wrapped_msg_callback,
- lambda msg: "Exception in {} when handling msg on '{}': '{}'".format(
- msg_callback.__name__, msg.topic, msg.payload
+ lambda msg: (
+ f"Exception in {msg_callback.__name__} when handling msg on "
+ f"'{msg.topic}': '{msg.payload}'"
),
),
qos,
@@ -1014,7 +1015,7 @@ def _raise_on_error(result_code: int) -> None:
if result_code != 0:
raise HomeAssistantError(
- "Error talking to MQTT: {}".format(mqtt.error_string(result_code))
+ f"Error talking to MQTT: {mqtt.error_string(result_code)}"
)
diff --git a/homeassistant/components/mqtt/discovery.py b/homeassistant/components/mqtt/discovery.py
index c54ab395c94..e6350179571 100644
--- a/homeassistant/components/mqtt/discovery.py
+++ b/homeassistant/components/mqtt/discovery.py
@@ -126,9 +126,9 @@ async def async_start(
for key, value in payload.items():
if isinstance(value, str) and value:
if value[0] == TOPIC_BASE and key.endswith("_topic"):
- payload[key] = "{}{}".format(base, value[1:])
+ payload[key] = f"{base}{value[1:]}"
if value[-1] == TOPIC_BASE and key.endswith("_topic"):
- payload[key] = "{}{}".format(value[:-1], base)
+ payload[key] = f"{value[:-1]}{base}"
# If present, the node_id will be included in the discovered object id
discovery_id = " ".join((node_id, object_id)) if node_id else object_id
@@ -163,12 +163,10 @@ async def async_start(
and component in IMPLICIT_STATE_TOPIC_COMPONENTS
):
# state_topic not specified, infer from discovery topic
- payload[CONF_STATE_TOPIC] = "{}/{}/{}{}/state".format(
- discovery_topic,
- component,
- "%s/" % node_id if node_id else "",
- object_id,
- )
+ fmt_node_id = f"{node_id}/" if node_id else ""
+ payload[
+ CONF_STATE_TOPIC
+ ] = f"{discovery_topic}/{component}/{fmt_node_id}{object_id}/state"
_LOGGER.warning(
'implicit %s is deprecated, add "%s":"%s" to '
"%s discovery message",
@@ -199,7 +197,7 @@ async def async_start(
await async_load_platform(hass, component, "mqtt", payload, hass_config)
return
- config_entries_key = "{}.{}".format(component, "mqtt")
+ config_entries_key = f"{component}.mqtt"
async with hass.data[DATA_CONFIG_ENTRY_LOCK]:
if config_entries_key not in hass.data[CONFIG_ENTRY_IS_SETUP]:
if component == "device_automation":
diff --git a/homeassistant/components/mqtt/light/schema_basic.py b/homeassistant/components/mqtt/light/schema_basic.py
index a9ea21b4b0a..4b47014af48 100644
--- a/homeassistant/components/mqtt/light/schema_basic.py
+++ b/homeassistant/components/mqtt/light/schema_basic.py
@@ -675,7 +675,7 @@ class MqttLight(
{"red": rgb[0], "green": rgb[1], "blue": rgb[2]}
)
else:
- rgb_color_str = "{},{},{}".format(*rgb)
+ rgb_color_str = f"{rgb[0]},{rgb[1]},{rgb[2]}"
mqtt.async_publish(
self.hass,
@@ -695,7 +695,7 @@ class MqttLight(
mqtt.async_publish(
self.hass,
self._topic[CONF_HS_COMMAND_TOPIC],
- "{},{}".format(*hs_color),
+ f"{hs_color[0]},{hs_color[1]}",
self._config[CONF_QOS],
self._config[CONF_RETAIN],
)
@@ -710,7 +710,7 @@ class MqttLight(
mqtt.async_publish(
self.hass,
self._topic[CONF_XY_COMMAND_TOPIC],
- "{},{}".format(*xy_color),
+ f"{xy_color[0]},{xy_color[1]}",
self._config[CONF_QOS],
self._config[CONF_RETAIN],
)
@@ -753,7 +753,7 @@ class MqttLight(
{"red": rgb[0], "green": rgb[1], "blue": rgb[2]}
)
else:
- rgb_color_str = "{},{},{}".format(*rgb)
+ rgb_color_str = f"{rgb[0]},{rgb[1]},{rgb[2]}"
mqtt.async_publish(
self.hass,
diff --git a/homeassistant/components/mqtt/server.py b/homeassistant/components/mqtt/server.py
index 61ba5c392b1..1b2a56a2195 100644
--- a/homeassistant/components/mqtt/server.py
+++ b/homeassistant/components/mqtt/server.py
@@ -85,9 +85,7 @@ def generate_config(hass, passwd, password):
# Encrypt with what hbmqtt uses to verify
passwd.write(
- "homeassistant:{}\n".format(custom_app_context.encrypt(password)).encode(
- "utf-8"
- )
+ f"homeassistant:{custom_app_context.encrypt(password)}\n".encode("utf-8")
)
passwd.flush()
diff --git a/homeassistant/components/mqtt_room/sensor.py b/homeassistant/components/mqtt_room/sensor.py
index d8dfa65f799..580ffd606f3 100644
--- a/homeassistant/components/mqtt_room/sensor.py
+++ b/homeassistant/components/mqtt_room/sensor.py
@@ -73,7 +73,7 @@ class MQTTRoomSensor(Entity):
"""Initialize the sensor."""
self._state = STATE_NOT_HOME
self._name = name
- self._state_topic = "{}{}".format(state_topic, "/+")
+ self._state_topic = f"{state_topic}/+"
self._device_id = slugify(device_id).upper()
self._timeout = timeout
self._consider_home = (
diff --git a/homeassistant/components/mychevy/binary_sensor.py b/homeassistant/components/mychevy/binary_sensor.py
index e6d4d23c9b4..e5b0dc8b6ea 100644
--- a/homeassistant/components/mychevy/binary_sensor.py
+++ b/homeassistant/components/mychevy/binary_sensor.py
@@ -1,7 +1,10 @@
"""Support for MyChevy binary sensors."""
import logging
-from homeassistant.components.binary_sensor import ENTITY_ID_FORMAT, BinarySensorDevice
+from homeassistant.components.binary_sensor import (
+ DOMAIN as BINARY_SENSOR_DOMAIN,
+ BinarySensorDevice,
+)
from homeassistant.core import callback
from homeassistant.util import slugify
@@ -42,11 +45,7 @@ class EVBinarySensor(BinarySensorDevice):
self._type = config.device_class
self._is_on = None
self._car_vid = car_vid
- self.entity_id = ENTITY_ID_FORMAT.format(
- "{}_{}_{}".format(
- MYCHEVY_DOMAIN, slugify(self._car.name), slugify(self._name)
- )
- )
+ self.entity_id = f"{BINARY_SENSOR_DOMAIN}.{MYCHEVY_DOMAIN}_{slugify(self._car.name)}_{slugify(self._name)}"
@property
def name(self):
diff --git a/homeassistant/components/mychevy/sensor.py b/homeassistant/components/mychevy/sensor.py
index 56335bb1650..f45c81a0007 100644
--- a/homeassistant/components/mychevy/sensor.py
+++ b/homeassistant/components/mychevy/sensor.py
@@ -1,7 +1,7 @@
"""Support for MyChevy sensors."""
import logging
-from homeassistant.components.sensor import ENTITY_ID_FORMAT
+from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
from homeassistant.const import UNIT_PERCENTAGE
from homeassistant.core import callback
from homeassistant.helpers.entity import Entity
@@ -123,11 +123,7 @@ class EVSensor(Entity):
self._state_attributes = {}
self._car_vid = car_vid
- self.entity_id = ENTITY_ID_FORMAT.format(
- "{}_{}_{}".format(
- MYCHEVY_DOMAIN, slugify(self._car.name), slugify(self._name)
- )
- )
+ self.entity_id = f"{SENSOR_DOMAIN}.{MYCHEVY_DOMAIN}_{slugify(self._car.name)}_{slugify(self._name)}"
async def async_added_to_hass(self):
"""Register callbacks."""
diff --git a/homeassistant/components/mysensors/__init__.py b/homeassistant/components/mysensors/__init__.py
index a528be15e14..43e398b142f 100644
--- a/homeassistant/components/mysensors/__init__.py
+++ b/homeassistant/components/mysensors/__init__.py
@@ -129,7 +129,7 @@ async def async_setup(hass, config):
def _get_mysensors_name(gateway, node_id, child_id):
"""Return a name for a node child."""
- node_name = "{} {}".format(gateway.sensors[node_id].sketch_name, node_id)
+ node_name = f"{gateway.sensors[node_id].sketch_name} {node_id}"
node_name = next(
(
node[CONF_NODE_NAME]
diff --git a/homeassistant/components/mysensors/gateway.py b/homeassistant/components/mysensors/gateway.py
index 903ec069b51..d906c306dfc 100644
--- a/homeassistant/components/mysensors/gateway.py
+++ b/homeassistant/components/mysensors/gateway.py
@@ -42,7 +42,7 @@ MQTT_COMPONENT = "mqtt"
def is_serial_port(value):
"""Validate that value is a windows serial port or a unix device."""
if sys.platform.startswith("win"):
- ports = ("COM{}".format(idx + 1) for idx in range(256))
+ ports = (f"COM{idx + 1}" for idx in range(256))
if value in ports:
return value
raise vol.Invalid(f"{value} is not a serial port")
@@ -73,8 +73,7 @@ async def setup_gateways(hass, config):
for index, gateway_conf in enumerate(conf[CONF_GATEWAYS]):
persistence_file = gateway_conf.get(
- CONF_PERSISTENCE_FILE,
- hass.config.path("mysensors{}.pickle".format(index + 1)),
+ CONF_PERSISTENCE_FILE, hass.config.path(f"mysensors{index + 1}.pickle"),
)
ready_gateway = await _get_gateway(hass, config, gateway_conf, persistence_file)
if ready_gateway is not None:
diff --git a/homeassistant/components/mysensors/helpers.py b/homeassistant/components/mysensors/helpers.py
index f0e9b06b762..20b266e550e 100644
--- a/homeassistant/components/mysensors/helpers.py
+++ b/homeassistant/components/mysensors/helpers.py
@@ -92,8 +92,8 @@ def invalid_msg(gateway, child, value_type_name):
"""Return a message for an invalid child during schema validation."""
pres = gateway.const.Presentation
set_req = gateway.const.SetReq
- return "{} requires value_type {}".format(
- pres(child.type).name, set_req[value_type_name].name
+ return (
+ f"{pres(child.type).name} requires value_type {set_req[value_type_name].name}"
)
diff --git a/homeassistant/components/ps4/media_player.py b/homeassistant/components/ps4/media_player.py
index 28d201d78cd..3aa65734d34 100644
--- a/homeassistant/components/ps4/media_player.py
+++ b/homeassistant/components/ps4/media_player.py
@@ -5,7 +5,7 @@ import logging
from pyps4_2ndscreen.errors import NotReady, PSDataIncomplete
import pyps4_2ndscreen.ps4 as pyps4
-from homeassistant.components.media_player import ENTITY_IMAGE_URL, MediaPlayerDevice
+from homeassistant.components.media_player import MediaPlayerDevice
from homeassistant.components.media_player.const import (
ATTR_MEDIA_CONTENT_TYPE,
ATTR_MEDIA_TITLE,
@@ -387,8 +387,9 @@ class PS4Device(MediaPlayerDevice):
if self._state == STATE_PLAYING and self._media_content_id is not None:
image_hash = self.media_image_hash
if image_hash is not None:
- return ENTITY_IMAGE_URL.format(
- self.entity_id, self.access_token, image_hash
+ return (
+ f"/api/media_player_proxy/{self.entity_id}?"
+ f"token={self.access_token}&cache={image_hash}"
)
return MEDIA_IMAGE_DEFAULT