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