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