mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
String formatting improvements (#33653)
This commit is contained in:
parent
ed71683488
commit
886308a953
@ -86,7 +86,7 @@ def calculate_offset(event, offset):
|
||||
summary = event.get("summary", "")
|
||||
# check if we have an offset tag in the message
|
||||
# time is HH:MM or MM
|
||||
reg = "{}([+-]?[0-9]{{0,2}}(:[0-9]{{0,2}})?)".format(offset)
|
||||
reg = f"{offset}([+-]?[0-9]{{0,2}}(:[0-9]{{0,2}})?)"
|
||||
search = re.search(reg, summary)
|
||||
if search and search.group(1):
|
||||
time = search.group(1)
|
||||
@ -94,7 +94,7 @@ def calculate_offset(event, offset):
|
||||
if time[0] == "+" or time[0] == "-":
|
||||
time = "{}0:{}".format(time[0], time[1:])
|
||||
else:
|
||||
time = "0:{}".format(time)
|
||||
time = f"0:{time}"
|
||||
|
||||
offset_time = time_period_str(time)
|
||||
summary = (summary[: search.start()] + summary[search.end() :]).strip()
|
||||
|
@ -156,7 +156,7 @@ class StationPriceSensor(Entity):
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name of the sensor."""
|
||||
return "{} {}".format(self._station_data.get_station_name(), self._fuel_type)
|
||||
return f"{self._station_data.get_station_name()} {self._fuel_type}"
|
||||
|
||||
@property
|
||||
def state(self) -> Optional[float]:
|
||||
|
@ -66,7 +66,7 @@ class OhmconnectSensor(Entity):
|
||||
def update(self):
|
||||
"""Get the latest data from OhmConnect."""
|
||||
try:
|
||||
url = "https://login.ohmconnect.com/verify-ohm-hour/{}".format(self._ohmid)
|
||||
url = f"https://login.ohmconnect.com/verify-ohm-hour/{self._ohmid}"
|
||||
response = requests.get(url, timeout=10)
|
||||
root = ET.fromstring(response.text)
|
||||
|
||||
|
@ -404,7 +404,7 @@ class OsramLightifyGroup(Luminary):
|
||||
# It should be something like "<gateway host>-<group.idx()>"
|
||||
# For now keeping it as is for backward compatibility with existing
|
||||
# users.
|
||||
return "{}".format(self._luminary.lights())
|
||||
return f"{self._luminary.lights()}"
|
||||
|
||||
def _get_supported_features(self):
|
||||
"""Get list of supported features."""
|
||||
|
@ -209,7 +209,7 @@ class ThermostatDevice(ClimateDevice):
|
||||
preset_temperature = presets.get(self._preset_mode, "none")
|
||||
if self.hvac_mode == HVAC_MODE_AUTO:
|
||||
if self._thermostat_temperature == self._schedule_temperature:
|
||||
return "{}".format(self._selected_schema)
|
||||
return f"{self._selected_schema}"
|
||||
if self._thermostat_temperature == preset_temperature:
|
||||
return self._preset_mode
|
||||
return "Temporary"
|
||||
|
@ -319,7 +319,7 @@ class MinutPointEntity(Entity):
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the display name of this device."""
|
||||
return "{} {}".format(self._name, self.device_class.capitalize())
|
||||
return f"{self._name} {self.device_class.capitalize()}"
|
||||
|
||||
@property
|
||||
def is_updated(self):
|
||||
|
@ -45,10 +45,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
name = zone_config.get(CONF_FRIENDLY_NAME)
|
||||
devices.append(
|
||||
RainBirdSwitch(
|
||||
controller,
|
||||
zone,
|
||||
time,
|
||||
name if name else "Sprinkler {}".format(zone),
|
||||
controller, zone, time, name if name else f"Sprinkler {zone}",
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -80,8 +80,8 @@ def setup(hass, config):
|
||||
else:
|
||||
uri_scheme = "http://"
|
||||
|
||||
event_collector = "{}{}:{}/services/collector/event".format(uri_scheme, host, port)
|
||||
headers = {AUTHORIZATION: "Splunk {}".format(token)}
|
||||
event_collector = f"{uri_scheme}{host}:{port}/services/collector/event"
|
||||
headers = {AUTHORIZATION: f"Splunk {token}"}
|
||||
|
||||
def splunk_event_listener(event):
|
||||
"""Listen for new messages on the bus and sends them to Splunk."""
|
||||
|
@ -93,9 +93,9 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
id_ = named_sensor[CONF_ID]
|
||||
if proto is not None:
|
||||
if model is not None:
|
||||
named_sensors["{}{}{}".format(proto, model, id_)] = name
|
||||
named_sensors[f"{proto}{model}{id_}"] = name
|
||||
else:
|
||||
named_sensors["{}{}".format(proto, id_)] = name
|
||||
named_sensors[f"{proto}{id_}"] = name
|
||||
else:
|
||||
named_sensors[id_] = name
|
||||
|
||||
@ -103,7 +103,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
if not config[CONF_ONLY_NAMED]:
|
||||
sensor_name = str(tellcore_sensor.id)
|
||||
else:
|
||||
proto_id = "{}{}".format(tellcore_sensor.protocol, tellcore_sensor.id)
|
||||
proto_id = f"{tellcore_sensor.protocol}{tellcore_sensor.id}"
|
||||
proto_model_id = "{}{}{}".format(
|
||||
tellcore_sensor.protocol, tellcore_sensor.model, tellcore_sensor.id
|
||||
)
|
||||
|
@ -258,7 +258,7 @@ class TensorFlowImageProcessor(ImageProcessingEntity):
|
||||
1,
|
||||
1,
|
||||
]:
|
||||
label = "{} Detection Area".format(category.capitalize())
|
||||
label = f"{category.capitalize()} Detection Area"
|
||||
draw_box(
|
||||
draw,
|
||||
self._category_areas[category],
|
||||
|
@ -109,7 +109,7 @@ class TibberSensorElPrice(TibberSensor):
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return "Electricity price {}".format(self._name)
|
||||
return f"Electricity price {self._name}"
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
@ -179,7 +179,7 @@ class TibberSensorRT(TibberSensor):
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return "Real time consumption {}".format(self._name)
|
||||
return f"Real time consumption {self._name}"
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
|
@ -134,7 +134,7 @@ class TuyaDevice(Entity):
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return a unique ID."""
|
||||
return "tuya.{}".format(self.tuya.object_id())
|
||||
return f"tuya.{self.tuya.object_id()}"
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
@ -762,7 +762,7 @@ class WinkDevice(Entity):
|
||||
def unique_id(self):
|
||||
"""Return the unique id of the Wink device."""
|
||||
if hasattr(self.wink, "capability") and self.wink.capability() is not None:
|
||||
return "{}_{}".format(self.wink.object_id(), self.wink.capability())
|
||||
return f"{self.wink.object_id()}_{self.wink.capability()}"
|
||||
return self.wink.object_id()
|
||||
|
||||
@property
|
||||
|
@ -130,7 +130,7 @@ class WirelessTagPlatform:
|
||||
def local_base_url(self):
|
||||
"""Define base url of hass in local network."""
|
||||
if self._local_base_url is None:
|
||||
self._local_base_url = "http://{}".format(util.get_local_ip())
|
||||
self._local_base_url = f"http://{util.get_local_ip()}"
|
||||
|
||||
port = self.hass.config.api.port
|
||||
if port is not None:
|
||||
@ -198,7 +198,7 @@ def setup(hass, config):
|
||||
except (ConnectTimeout, HTTPError, WirelessTagsException) as ex:
|
||||
_LOGGER.error("Unable to connect to wirelesstag.net service: %s", str(ex))
|
||||
hass.components.persistent_notification.create(
|
||||
"Error: {}<br />Please restart hass after fixing this.".format(ex),
|
||||
f"Error: {ex}<br />Please restart hass after fixing this.",
|
||||
title=NOTIFICATION_TITLE,
|
||||
notification_id=NOTIFICATION_ID,
|
||||
)
|
||||
|
@ -39,7 +39,7 @@ def run(args):
|
||||
print(f"Active keyring : {keyr.__module__}")
|
||||
config_name = os.path.join(platform.config_root(), "keyringrc.cfg")
|
||||
print(f"Config location : {config_name}")
|
||||
print("Data location : {}\n".format(platform.data_root()))
|
||||
print(f"Data location : {platform.data_root()}\n")
|
||||
elif args.name is None:
|
||||
parser.print_help()
|
||||
return 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user