Improve string formatting v3 (#33667)
* Improve string formatting v3 * Address review comment
This commit is contained in:
parent
bf1b408038
commit
c20a965eda
24 changed files with 32 additions and 37 deletions
homeassistant/components
actiontec
aftership
aqualogic
arwn
darksky
denon
dublin_bus_transport
dwd_weather_warnings
ecobee
econet
group
hydrawise
hyperion
influxdb
irish_rail_transport
knx
life360
light
mobile_app
mqtt
mychevy
nest
ombi
|
@ -95,9 +95,9 @@ class ActiontecDeviceScanner(DeviceScanner):
|
|||
try:
|
||||
telnet = telnetlib.Telnet(self.host)
|
||||
telnet.read_until(b"Username: ")
|
||||
telnet.write((self.username + "\n").encode("ascii"))
|
||||
telnet.write((f"{self.username}\n").encode("ascii"))
|
||||
telnet.read_until(b"Password: ")
|
||||
telnet.write((self.password + "\n").encode("ascii"))
|
||||
telnet.write((f"{self.password}\n").encode("ascii"))
|
||||
prompt = telnet.read_until(b"Wireless Broadband Router> ").split(b"\n")[-1]
|
||||
telnet.write(b"firewall mac_cache_dump\n")
|
||||
telnet.write(b"\n")
|
||||
|
|
|
@ -27,7 +27,7 @@ CONF_TITLE = "title"
|
|||
CONF_TRACKING_NUMBER = "tracking_number"
|
||||
|
||||
DEFAULT_NAME = "aftership"
|
||||
UPDATE_TOPIC = DOMAIN + "_update"
|
||||
UPDATE_TOPIC = f"{DOMAIN}_update"
|
||||
|
||||
ICON = "mdi:package-variant-closed"
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ from homeassistant.helpers import config_validation as cv
|
|||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN = "aqualogic"
|
||||
UPDATE_TOPIC = DOMAIN + "_update"
|
||||
UPDATE_TOPIC = f"{DOMAIN}_update"
|
||||
CONF_UNIT = "unit"
|
||||
RECONNECT_INTERVAL = timedelta(seconds=10)
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ def discover_sensors(topic, payload):
|
|||
unit = TEMP_CELSIUS
|
||||
return ArwnSensor(name, "temp", unit)
|
||||
if domain == "moisture":
|
||||
name = parts[2] + " Moisture"
|
||||
name = f"{parts[2]} Moisture"
|
||||
return ArwnSensor(name, "moisture", unit, "mdi:water-percent")
|
||||
if domain == "rain":
|
||||
if len(parts) >= 3 and parts[2] == "today":
|
||||
|
|
|
@ -771,7 +771,8 @@ def convert_to_camel(data):
|
|||
This is not pythonic, but needed for certain situations.
|
||||
"""
|
||||
components = data.split("_")
|
||||
return components[0] + "".join(x.title() for x in components[1:])
|
||||
capital_components = "".join(x.title() for x in components[1:])
|
||||
return f"{components[0]}{capital_components}"
|
||||
|
||||
|
||||
class DarkSkyData:
|
||||
|
|
|
@ -187,7 +187,7 @@ class DenonDevice(MediaPlayerDevice):
|
|||
"NSE8",
|
||||
]
|
||||
for line in self.telnet_request(telnet, "NSE", all_lines=True):
|
||||
self._mediainfo += line[len(answer_codes.pop(0)) :] + "\n"
|
||||
self._mediainfo += f"{line[len(answer_codes.pop(0)) :]}\n"
|
||||
else:
|
||||
self._mediainfo = self.source
|
||||
|
||||
|
@ -257,7 +257,7 @@ class DenonDevice(MediaPlayerDevice):
|
|||
|
||||
def set_volume_level(self, volume):
|
||||
"""Set volume level, range 0..1."""
|
||||
self.telnet_command(f"MV{str(round(volume * self._volume_max)).zfill(2)}")
|
||||
self.telnet_command(f"MV{round(volume * self._volume_max):02}")
|
||||
|
||||
def mute_volume(self, mute):
|
||||
"""Mute (true) or unmute (false) media player."""
|
||||
|
|
|
@ -94,7 +94,7 @@ class DublinPublicTransportSensor(Entity):
|
|||
if self._times is not None:
|
||||
next_up = "None"
|
||||
if len(self._times) > 1:
|
||||
next_up = self._times[1][ATTR_ROUTE] + " in "
|
||||
next_up = f"{self._times[1][ATTR_ROUTE]} in "
|
||||
next_up += self._times[1][ATTR_DUE_IN]
|
||||
|
||||
return {
|
||||
|
|
|
@ -133,9 +133,9 @@ class DwdWeatherWarningsSensor(Entity):
|
|||
else:
|
||||
raise Exception("Unknown warning type")
|
||||
|
||||
data["warning_count"] = self._api.data[prefix + "_warning_count"]
|
||||
data["warning_count"] = self._api.data[f"{prefix}_warning_count"]
|
||||
i = 0
|
||||
for event in self._api.data[prefix + "_warnings"]:
|
||||
for event in self._api.data[f"{prefix}_warnings"]:
|
||||
i = i + 1
|
||||
|
||||
data[f"warning_{i}_name"] = event["event"]
|
||||
|
|
|
@ -28,7 +28,7 @@ class EcobeeBinarySensor(BinarySensorDevice):
|
|||
def __init__(self, data, sensor_name, sensor_index):
|
||||
"""Initialize the Ecobee sensor."""
|
||||
self.data = data
|
||||
self._name = sensor_name + " Occupancy"
|
||||
self._name = f"{sensor_name} Occupancy"
|
||||
self.sensor_name = sensor_name
|
||||
self.index = sensor_index
|
||||
self._state = None
|
||||
|
|
|
@ -132,11 +132,7 @@ class EcoNetWaterHeater(WaterHeaterDevice):
|
|||
self.ha_state_to_econet[value] = key
|
||||
for mode in self.supported_modes:
|
||||
if mode not in ECONET_STATE_TO_HA:
|
||||
error = (
|
||||
"Invalid operation mode mapping. "
|
||||
+ mode
|
||||
+ " doesn't map. Please report this."
|
||||
)
|
||||
error = f"Invalid operation mode mapping. {mode} doesn't map. Please report this."
|
||||
_LOGGER.error(error)
|
||||
|
||||
@property
|
||||
|
|
|
@ -174,7 +174,7 @@ def get_entity_ids(
|
|||
if not domain_filter:
|
||||
return cast(List[str], entity_ids)
|
||||
|
||||
domain_filter = domain_filter.lower() + "."
|
||||
domain_filter = f"{domain_filter.lower()}."
|
||||
|
||||
return [ent_id for ent_id in entity_ids if ent_id.startswith(domain_filter)]
|
||||
|
||||
|
|
|
@ -58,11 +58,7 @@ class HydrawiseSensor(HydrawiseEntity):
|
|||
if relay["nicetime"] == "Not scheduled":
|
||||
self._state = "not_scheduled"
|
||||
else:
|
||||
self._state = (
|
||||
relay["nicetime"].split(",")[0]
|
||||
+ " "
|
||||
+ relay["nicetime"].split(" ")[3]
|
||||
)
|
||||
self._state = f"{relay['nicetime'].split(',')[0]} {relay['nicetime'].split(' ')[3]}"
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
|
|
|
@ -285,7 +285,7 @@ class Hyperion(Light):
|
|||
sock.close()
|
||||
return False
|
||||
|
||||
sock.send(bytearray(json.dumps(request) + "\n", "utf-8"))
|
||||
sock.send(bytearray(f"{json.dumps(request)}\n", "utf-8"))
|
||||
try:
|
||||
buf = sock.recv(4096)
|
||||
except socket.timeout:
|
||||
|
|
|
@ -239,7 +239,7 @@ def setup(hass, config):
|
|||
elif key != "unit_of_measurement" or include_uom:
|
||||
# If the key is already in fields
|
||||
if key in json["fields"]:
|
||||
key = key + "_"
|
||||
key = f"{key}_"
|
||||
# Prevent column data errors in influxDB.
|
||||
# For each value we try to cast it as float
|
||||
# But if we can not do it we store the value
|
||||
|
|
|
@ -97,9 +97,11 @@ class IrishRailTransportSensor(Entity):
|
|||
if self._times:
|
||||
next_up = "None"
|
||||
if len(self._times) > 1:
|
||||
next_up = self._times[1][ATTR_ORIGIN] + " to "
|
||||
next_up += self._times[1][ATTR_DESTINATION] + " in "
|
||||
next_up += self._times[1][ATTR_DUE_IN]
|
||||
next_up = (
|
||||
f"{self._times[1][ATTR_ORIGIN]} to "
|
||||
f"{self._times[1][ATTR_DESTINATION]} in "
|
||||
f"{self._times[1][ATTR_DUE_IN]}"
|
||||
)
|
||||
|
||||
return {
|
||||
ATTR_ATTRIBUTION: ATTRIBUTION,
|
||||
|
|
|
@ -139,7 +139,7 @@ def async_add_entities_config(hass, config, async_add_entities):
|
|||
"""Set up climate for KNX platform configured within platform."""
|
||||
climate_mode = XknxClimateMode(
|
||||
hass.data[DATA_KNX].xknx,
|
||||
name=config[CONF_NAME] + " Mode",
|
||||
name=f"{config[CONF_NAME]} Mode",
|
||||
group_address_operation_mode=config.get(CONF_OPERATION_MODE_ADDRESS),
|
||||
group_address_operation_mode_state=config.get(
|
||||
CONF_OPERATION_MODE_STATE_ADDRESS
|
||||
|
|
|
@ -57,7 +57,7 @@ def _prefix(value):
|
|||
if not value:
|
||||
return ""
|
||||
if not value.endswith("_"):
|
||||
return value + "_"
|
||||
return f"{value}_"
|
||||
return value
|
||||
|
||||
|
||||
|
|
|
@ -325,7 +325,7 @@ class Profiles:
|
|||
def get_default(cls, entity_id):
|
||||
"""Return the default turn-on profile for the given light."""
|
||||
# pylint: disable=unsupported-membership-test
|
||||
name = entity_id + ".default"
|
||||
name = f"{entity_id}.default"
|
||||
if name in cls._all:
|
||||
return name
|
||||
name = "group.all_lights.default"
|
||||
|
|
|
@ -70,5 +70,5 @@ ATTR_SENSOR_TYPE_SENSOR = "sensor"
|
|||
ATTR_SENSOR_UNIQUE_ID = "unique_id"
|
||||
ATTR_SENSOR_UOM = "unit_of_measurement"
|
||||
|
||||
SIGNAL_SENSOR_UPDATE = DOMAIN + "_sensor_update"
|
||||
SIGNAL_SENSOR_UPDATE = f"{DOMAIN}_sensor_update"
|
||||
SIGNAL_LOCATION_UPDATE = DOMAIN + "_location_update_{}"
|
||||
|
|
|
@ -166,7 +166,7 @@ async def async_start(
|
|||
hass.data[CONFIG_ENTRY_IS_SETUP] = set()
|
||||
|
||||
await mqtt.async_subscribe(
|
||||
hass, discovery_topic + "/#", async_device_message_received, 0
|
||||
hass, f"{discovery_topic}/#", async_device_message_received, 0
|
||||
)
|
||||
|
||||
return True
|
||||
|
|
|
@ -13,7 +13,7 @@ from homeassistant.util import Throttle
|
|||
|
||||
DOMAIN = "mychevy"
|
||||
UPDATE_TOPIC = DOMAIN
|
||||
ERROR_TOPIC = DOMAIN + "_error"
|
||||
ERROR_TOPIC = f"{DOMAIN}_error"
|
||||
|
||||
MYCHEVY_SUCCESS = "success"
|
||||
MYCHEVY_ERROR = "error"
|
||||
|
|
|
@ -69,7 +69,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||
for variable in conditions:
|
||||
if variable in _BINARY_TYPES_DEPRECATED:
|
||||
wstr = (
|
||||
variable + " is no a longer supported "
|
||||
f"{variable} is no a longer supported "
|
||||
"monitored_conditions. See "
|
||||
"https://www.home-assistant.io/integrations/binary_sensor.nest/ "
|
||||
"for valid options."
|
||||
|
|
|
@ -96,7 +96,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||
)
|
||||
else:
|
||||
wstr = (
|
||||
variable + " is no a longer supported "
|
||||
f"{variable} is no a longer supported "
|
||||
"monitored_conditions. See "
|
||||
"https://www.home-assistant.io/integrations/"
|
||||
"binary_sensor.nest/ for valid options."
|
||||
|
|
|
@ -38,7 +38,7 @@ def urlbase(value) -> str:
|
|||
value = str(value).strip("/")
|
||||
if not value:
|
||||
return value
|
||||
return value + "/"
|
||||
return f"{value}/"
|
||||
|
||||
|
||||
SUBMIT_MOVIE_REQUEST_SERVICE_SCHEMA = vol.Schema({vol.Required(ATTR_NAME): cv.string})
|
||||
|
|
Loading…
Add table
Reference in a new issue