String formatting improvements (#33635)
* String formatting improvements * Found another onepull/33636/head^2
parent
025cce3445
commit
e8a0abd107
|
@ -191,7 +191,9 @@ class AfterShipSensor(Entity):
|
|||
"name": name,
|
||||
"tracking_number": track["tracking_number"],
|
||||
"slug": track["slug"],
|
||||
"link": "%s%s/%s" % (BASE, track["slug"], track["tracking_number"]),
|
||||
"link": "{}{}/{}".format(
|
||||
BASE, track["slug"], track["tracking_number"]
|
||||
),
|
||||
"last_update": track["updated_at"],
|
||||
"expected_delivery": track["expected_delivery"],
|
||||
"status": track["tag"],
|
||||
|
|
|
@ -255,10 +255,8 @@ class BrSensor(Entity):
|
|||
def uid(self, coordinates):
|
||||
"""Generate a unique id using coordinates and sensor type."""
|
||||
# The combination of the location, name and sensor type is unique
|
||||
return "%2.6f%2.6f%s" % (
|
||||
coordinates[CONF_LATITUDE],
|
||||
coordinates[CONF_LONGITUDE],
|
||||
self.type,
|
||||
return "{:2.6f}{:2.6f}{}".format(
|
||||
coordinates[CONF_LATITUDE], coordinates[CONF_LONGITUDE], self.type,
|
||||
)
|
||||
|
||||
@callback
|
||||
|
|
|
@ -226,7 +226,7 @@ class ZWaveProtectionView(HomeAssistantView):
|
|||
return self.json(protection_options)
|
||||
protections = node.get_protections()
|
||||
protection_options = {
|
||||
"value_id": "{0:d}".format(list(protections)[0]),
|
||||
"value_id": "{:d}".format(list(protections)[0]),
|
||||
"selected": node.get_protection_item(list(protections)[0]),
|
||||
"options": node.get_protection_items(list(protections)[0]),
|
||||
}
|
||||
|
|
|
@ -321,7 +321,7 @@ class GoogleTravelTimeSensor(Entity):
|
|||
def _get_location_from_attributes(entity):
|
||||
"""Get the lat/long string from an entities attributes."""
|
||||
attr = entity.attributes
|
||||
return "%s,%s" % (attr.get(ATTR_LATITUDE), attr.get(ATTR_LONGITUDE))
|
||||
return "{},{}".format(attr.get(ATTR_LATITUDE), attr.get(ATTR_LONGITUDE))
|
||||
|
||||
def _resolve_zone(self, friendly_name):
|
||||
entities = self._hass.states.all()
|
||||
|
|
|
@ -67,7 +67,9 @@ class CecPlayerDevice(CecDevice, MediaPlayerDevice):
|
|||
def __init__(self, device, logical) -> None:
|
||||
"""Initialize the HDMI device."""
|
||||
CecDevice.__init__(self, device, logical)
|
||||
self.entity_id = "%s.%s_%s" % (DOMAIN, "hdmi", hex(self._logical_address)[2:])
|
||||
self.entity_id = "{}.{}_{}".format(
|
||||
DOMAIN, "hdmi", hex(self._logical_address)[2:]
|
||||
)
|
||||
|
||||
def send_keypress(self, key):
|
||||
"""Send keypress to CEC adapter."""
|
||||
|
|
|
@ -28,7 +28,9 @@ class CecSwitchDevice(CecDevice, SwitchDevice):
|
|||
def __init__(self, device, logical) -> None:
|
||||
"""Initialize the HDMI device."""
|
||||
CecDevice.__init__(self, device, logical)
|
||||
self.entity_id = "%s.%s_%s" % (DOMAIN, "hdmi", hex(self._logical_address)[2:])
|
||||
self.entity_id = "{}.{}_{}".format(
|
||||
DOMAIN, "hdmi", hex(self._logical_address)[2:]
|
||||
)
|
||||
|
||||
def turn_on(self, **kwargs) -> None:
|
||||
"""Turn device on."""
|
||||
|
|
|
@ -203,6 +203,6 @@ class NestTempSensor(NestSensorDevice):
|
|||
|
||||
if isinstance(temp, tuple):
|
||||
low, high = temp
|
||||
self._state = "%s-%s" % (int(low), int(high))
|
||||
self._state = "{}-{}".format(int(low), int(high))
|
||||
else:
|
||||
self._state = round(temp, 1)
|
||||
|
|
|
@ -255,7 +255,7 @@ class NotionEntity(Entity):
|
|||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return "{0}: {1}".format(
|
||||
return "{}: {}".format(
|
||||
self._notion.sensors[self._sensor_id]["name"], self._name
|
||||
)
|
||||
|
||||
|
@ -268,7 +268,7 @@ class NotionEntity(Entity):
|
|||
def unique_id(self):
|
||||
"""Return a unique, unchanging string that represents this sensor."""
|
||||
task = self._notion.tasks[self._task_id]
|
||||
return "{0}_{1}".format(self._sensor_id, task["task_type"])
|
||||
return "{}_{}".format(self._sensor_id, task["task_type"])
|
||||
|
||||
async def _update_bridge_id(self):
|
||||
"""Update the entity's bridge ID if it has changed.
|
||||
|
|
|
@ -86,7 +86,7 @@ class OpenAlprCloudEntity(ImageProcessingAlprEntity):
|
|||
if name:
|
||||
self._name = name
|
||||
else:
|
||||
self._name = "OpenAlpr {0}".format(split_entity_id(camera_entity)[1])
|
||||
self._name = "OpenAlpr {}".format(split_entity_id(camera_entity)[1])
|
||||
|
||||
@property
|
||||
def confidence(self):
|
||||
|
|
|
@ -161,7 +161,7 @@ class OpenAlprLocalEntity(ImageProcessingAlprEntity):
|
|||
if name:
|
||||
self._name = name
|
||||
else:
|
||||
self._name = "OpenAlpr {0}".format(split_entity_id(camera_entity)[1])
|
||||
self._name = "OpenAlpr {}".format(split_entity_id(camera_entity)[1])
|
||||
|
||||
@property
|
||||
def confidence(self):
|
||||
|
|
|
@ -132,7 +132,7 @@ class OpenCVImageProcessor(ImageProcessingEntity):
|
|||
if name:
|
||||
self._name = name
|
||||
else:
|
||||
self._name = "OpenCV {0}".format(split_entity_id(camera_entity)[1])
|
||||
self._name = "OpenCV {}".format(split_entity_id(camera_entity)[1])
|
||||
self._classifiers = classifiers
|
||||
self._matches = {}
|
||||
self._total_matches = 0
|
||||
|
|
|
@ -82,7 +82,7 @@ async def async_setup(hass, config):
|
|||
|
||||
conf = config[DOMAIN]
|
||||
|
||||
identifier = "{0}, {1}".format(
|
||||
identifier = "{}, {}".format(
|
||||
conf.get(CONF_LATITUDE, hass.config.latitude),
|
||||
conf.get(CONF_LONGITUDE, hass.config.longitude),
|
||||
)
|
||||
|
|
|
@ -20,7 +20,7 @@ from .const import DOMAIN
|
|||
def configured_instances(hass):
|
||||
"""Return a set of configured OpenUV instances."""
|
||||
return set(
|
||||
"{0}, {1}".format(
|
||||
"{}, {}".format(
|
||||
entry.data.get(CONF_LATITUDE, hass.config.latitude),
|
||||
entry.data.get(CONF_LONGITUDE, hass.config.longitude),
|
||||
)
|
||||
|
@ -64,7 +64,7 @@ class OpenUvFlowHandler(config_entries.ConfigFlow):
|
|||
if not user_input:
|
||||
return await self._show_form()
|
||||
|
||||
identifier = "{0}, {1}".format(
|
||||
identifier = "{}, {}".format(
|
||||
user_input.get(CONF_LATITUDE, self.hass.config.latitude),
|
||||
user_input.get(CONF_LONGITUDE, self.hass.config.longitude),
|
||||
)
|
||||
|
|
|
@ -34,7 +34,7 @@ class QrEntity(ImageProcessingEntity):
|
|||
if name:
|
||||
self._name = name
|
||||
else:
|
||||
self._name = "QR {0}".format(split_entity_id(camera_entity)[1])
|
||||
self._name = "QR {}".format(split_entity_id(camera_entity)[1])
|
||||
self._state = None
|
||||
|
||||
@property
|
||||
|
|
|
@ -142,7 +142,7 @@ class RainCloudEntity(Entity):
|
|||
"""Initialize the RainCloud entity."""
|
||||
self.data = data
|
||||
self._sensor_type = sensor_type
|
||||
self._name = "{0} {1}".format(self.data.name, KEY_MAP.get(self._sensor_type))
|
||||
self._name = "{} {}".format(self.data.name, KEY_MAP.get(self._sensor_type))
|
||||
self._state = None
|
||||
|
||||
@property
|
||||
|
|
|
@ -426,7 +426,7 @@ class RainMachineEntity(Entity):
|
|||
"identifiers": {(DOMAIN, self.rainmachine.controller.mac)},
|
||||
"name": self.rainmachine.controller.name,
|
||||
"manufacturer": "RainMachine",
|
||||
"model": "Version {0} (API: {1})".format(
|
||||
"model": "Version {} (API: {})".format(
|
||||
self.rainmachine.controller.hardware_version,
|
||||
self.rainmachine.controller.api_version,
|
||||
),
|
||||
|
|
|
@ -120,7 +120,7 @@ class RainMachineBinarySensor(RainMachineEntity, BinarySensorDevice):
|
|||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique, Home Assistant friendly identifier for this entity."""
|
||||
return "{0}_{1}".format(
|
||||
return "{}_{}".format(
|
||||
self.rainmachine.device_mac.replace(":", ""), self._sensor_type
|
||||
)
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ class RainMachineSensor(RainMachineEntity):
|
|||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique, Home Assistant friendly identifier for this entity."""
|
||||
return "{0}_{1}".format(
|
||||
return "{}_{}".format(
|
||||
self.rainmachine.device_mac.replace(":", ""), self._sensor_type
|
||||
)
|
||||
|
||||
|
|
|
@ -142,7 +142,7 @@ class RainMachineSwitch(RainMachineEntity, SwitchDevice):
|
|||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique, Home Assistant friendly identifier for this entity."""
|
||||
return "{0}_{1}_{2}".format(
|
||||
return "{}_{}_{}".format(
|
||||
self.rainmachine.device_mac.replace(":", ""),
|
||||
self._switch_type,
|
||||
self._rainmachine_entity_id,
|
||||
|
@ -219,7 +219,7 @@ class RainMachineProgram(RainMachineSwitch):
|
|||
|
||||
try:
|
||||
next_run = datetime.strptime(
|
||||
"{0} {1}".format(
|
||||
"{} {}".format(
|
||||
self._switch_data["nextRun"], self._switch_data["startTime"]
|
||||
),
|
||||
"%Y-%m-%d %H:%M",
|
||||
|
|
|
@ -47,9 +47,7 @@ class RingBinarySensor(RingEntityMixin, BinarySensorDevice):
|
|||
super().__init__(config_entry_id, device)
|
||||
self._ring = ring
|
||||
self._sensor_type = sensor_type
|
||||
self._name = "{0} {1}".format(
|
||||
self._device.name, SENSOR_TYPES.get(sensor_type)[0]
|
||||
)
|
||||
self._name = "{} {}".format(self._device.name, SENSOR_TYPES.get(sensor_type)[0])
|
||||
self._device_class = SENSOR_TYPES.get(sensor_type)[2]
|
||||
self._state = None
|
||||
self._unique_id = f"{device.id}-{sensor_type}"
|
||||
|
|
|
@ -46,9 +46,7 @@ class RingSensor(RingEntityMixin, Entity):
|
|||
self._extra = None
|
||||
self._icon = "mdi:{}".format(SENSOR_TYPES.get(sensor_type)[3])
|
||||
self._kind = SENSOR_TYPES.get(sensor_type)[4]
|
||||
self._name = "{0} {1}".format(
|
||||
self._device.name, SENSOR_TYPES.get(sensor_type)[0]
|
||||
)
|
||||
self._name = "{} {}".format(self._device.name, SENSOR_TYPES.get(sensor_type)[0])
|
||||
self._unique_id = f"{device.id}-{sensor_type}"
|
||||
|
||||
@property
|
||||
|
|
|
@ -153,8 +153,8 @@ class RokuDevice(MediaPlayerDevice):
|
|||
if self.current_app.id is None:
|
||||
return None
|
||||
|
||||
return "http://{0}:{1}/query/icon/{2}".format(
|
||||
self.ip_address, DEFAULT_PORT, self.current_app.id
|
||||
return (
|
||||
f"http://{self.ip_address}:{DEFAULT_PORT}/query/icon/{self.current_app.id}"
|
||||
)
|
||||
|
||||
@property
|
||||
|
|
|
@ -69,14 +69,12 @@ class ImageProcessingSsocr(ImageProcessingEntity):
|
|||
if name:
|
||||
self._name = name
|
||||
else:
|
||||
self._name = "SevenSegment OCR {0}".format(
|
||||
split_entity_id(camera_entity)[1]
|
||||
)
|
||||
self._name = "SevenSegment OCR {}".format(split_entity_id(camera_entity)[1])
|
||||
self._state = None
|
||||
|
||||
self.filepath = os.path.join(
|
||||
self.hass.config.config_dir,
|
||||
"ssocr-{0}.png".format(self._name.replace(" ", "_")),
|
||||
"ssocr-{}.png".format(self._name.replace(" ", "_")),
|
||||
)
|
||||
crop = [
|
||||
"crop",
|
||||
|
|
|
@ -130,7 +130,7 @@ class SeventeenTrackSummarySensor(Entity):
|
|||
@property
|
||||
def unique_id(self):
|
||||
"""Return a unique, Home Assistant friendly identifier for this entity."""
|
||||
return "summary_{0}_{1}".format(self._data.account_id, slugify(self._status))
|
||||
return "summary_{}_{}".format(self._data.account_id, slugify(self._status))
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
|
|
|
@ -51,7 +51,7 @@ class SkybellBinarySensor(SkybellDevice, BinarySensorDevice):
|
|||
"""Initialize a binary sensor for a Skybell device."""
|
||||
super().__init__(device)
|
||||
self._sensor_type = sensor_type
|
||||
self._name = "{0} {1}".format(
|
||||
self._name = "{} {}".format(
|
||||
self._device.name, SENSOR_TYPES[self._sensor_type][0]
|
||||
)
|
||||
self._device_class = SENSOR_TYPES[self._sensor_type][1]
|
||||
|
|
|
@ -49,7 +49,7 @@ class SkybellSensor(SkybellDevice):
|
|||
super().__init__(device)
|
||||
self._sensor_type = sensor_type
|
||||
self._icon = "mdi:{}".format(SENSOR_TYPES[self._sensor_type][1])
|
||||
self._name = "{0} {1}".format(
|
||||
self._name = "{} {}".format(
|
||||
self._device.name, SENSOR_TYPES[self._sensor_type][0]
|
||||
)
|
||||
self._state = None
|
||||
|
|
|
@ -48,7 +48,7 @@ class SkybellSwitch(SkybellDevice, SwitchDevice):
|
|||
"""Initialize a light for a Skybell device."""
|
||||
super().__init__(device)
|
||||
self._switch_type = switch_type
|
||||
self._name = "{0} {1}".format(
|
||||
self._name = "{} {}".format(
|
||||
self._device.name, SWITCH_TYPES[self._switch_type][0]
|
||||
)
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ class StarlingBalanceSensor(Entity):
|
|||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return "{0} {1}".format(
|
||||
return "{} {}".format(
|
||||
self._account_name, self._balance_data_type.replace("_", " ").capitalize()
|
||||
)
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ def setup(hass, config):
|
|||
# Send attribute values
|
||||
for key, value in states.items():
|
||||
if isinstance(value, (float, int)):
|
||||
stat = "%s.%s" % (state.entity_id, key.replace(" ", "_"))
|
||||
stat = "{}.{}".format(state.entity_id, key.replace(" ", "_"))
|
||||
statsd_client.gauge(stat, value, sample_rate)
|
||||
|
||||
else:
|
||||
|
|
|
@ -97,7 +97,7 @@ class SwissHydrologicalDataSensor(Entity):
|
|||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return "{0} {1}".format(self._data["water-body-name"], self._condition)
|
||||
return "{} {}".format(self._data["water-body-name"], self._condition)
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str:
|
||||
|
|
|
@ -168,7 +168,7 @@ class TensorFlowImageProcessor(ImageProcessingEntity):
|
|||
if name:
|
||||
self._name = name
|
||||
else:
|
||||
self._name = "TensorFlow {0}".format(split_entity_id(camera_entity)[1])
|
||||
self._name = "TensorFlow {}".format(split_entity_id(camera_entity)[1])
|
||||
self._session = session
|
||||
self._graph = detection_graph
|
||||
self._category_index = category_index
|
||||
|
@ -270,7 +270,7 @@ class TensorFlowImageProcessor(ImageProcessingEntity):
|
|||
|
||||
# Draw detected objects
|
||||
for instance in values:
|
||||
label = "{0} {1:.1f}%".format(category, instance["score"])
|
||||
label = "{} {:.1f}%".format(category, instance["score"])
|
||||
draw_box(
|
||||
draw, instance["box"], img_width, img_height, label, (255, 255, 0)
|
||||
)
|
||||
|
|
|
@ -121,7 +121,7 @@ class TileScanner:
|
|||
|
||||
for tile in tiles:
|
||||
await self._async_see(
|
||||
dev_id="tile_{0}".format(slugify(tile["tile_uuid"])),
|
||||
dev_id="tile_{}".format(slugify(tile["tile_uuid"])),
|
||||
gps=(
|
||||
tile["last_tile_state"]["latitude"],
|
||||
tile["last_tile_state"]["longitude"],
|
||||
|
|
|
@ -106,9 +106,7 @@ class TravisCISensor(Entity):
|
|||
self._user = user
|
||||
self._branch = branch
|
||||
self._state = None
|
||||
self._name = "{0} {1}".format(
|
||||
self._repo_name, SENSOR_TYPES[self._sensor_type][0]
|
||||
)
|
||||
self._name = "{} {}".format(self._repo_name, SENSOR_TYPES[self._sensor_type][0])
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
|
|
@ -108,7 +108,7 @@ class ConfigEntryWithingsApi(AbstractWithingsApi):
|
|||
partial(
|
||||
requests.request,
|
||||
method,
|
||||
"%s/%s" % (self.URL, path),
|
||||
f"{self.URL}/{path}",
|
||||
params=params,
|
||||
headers={
|
||||
"Authorization": "Bearer %s"
|
||||
|
|
|
@ -136,7 +136,7 @@ class XiaomiCamera(Camera):
|
|||
else:
|
||||
video = videos[-1]
|
||||
|
||||
return "ftp://{0}:{1}@{2}:{3}{4}/{5}".format(
|
||||
return "ftp://{}:{}@{}:{}{}/{}".format(
|
||||
self.user, self.passwd, host, self.port, ftp.pwd(), video
|
||||
)
|
||||
|
||||
|
|
|
@ -147,7 +147,7 @@ def setup(hass, config):
|
|||
def device_discovered(_, info):
|
||||
_LOGGER.debug("Adding autodetected %s", info["hostname"])
|
||||
|
||||
name = "yeelight_%s_%s" % (info["device_type"], info["properties"]["mac"])
|
||||
name = "yeelight_{}_{}".format(info["device_type"], info["properties"]["mac"])
|
||||
|
||||
device_config = DEVICE_SCHEMA({CONF_NAME: name})
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ class YiCamera(Camera):
|
|||
|
||||
await ftp.quit()
|
||||
self._is_on = True
|
||||
return "ftp://{0}:{1}@{2}:{3}{4}/{5}/{6}".format(
|
||||
return "ftp://{}:{}@{}:{}{}/{}/{}".format(
|
||||
self.user,
|
||||
self.passwd,
|
||||
self.host,
|
||||
|
|
|
@ -139,7 +139,7 @@ class YrSensor(Entity):
|
|||
return None
|
||||
return (
|
||||
"https://api.met.no/weatherapi/weathericon/1.1/"
|
||||
"?symbol={0};content_type=image/png".format(self._state)
|
||||
f"?symbol={self._state};content_type=image/png"
|
||||
)
|
||||
|
||||
@property
|
||||
|
|
|
@ -424,7 +424,7 @@ def color_rgbw_to_rgb(r: int, g: int, b: int, w: int) -> Tuple[int, int, int]:
|
|||
|
||||
def color_rgb_to_hex(r: int, g: int, b: int) -> str:
|
||||
"""Return a RGB color from a hex color string."""
|
||||
return "{0:02x}{1:02x}{2:02x}".format(round(r), round(g), round(b))
|
||||
return "{:02x}{:02x}{:02x}".format(round(r), round(g), round(b))
|
||||
|
||||
|
||||
def rgb_hex_to_rgb_list(hex_string: str) -> List[int]:
|
||||
|
|
Loading…
Reference in New Issue