Bump pyupgrade to 2.12.0 (#48943)

This commit is contained in:
Marc Mueller 2021-04-09 18:58:27 +02:00 committed by GitHub
parent ee0c87df1c
commit 8e2b5b36b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
45 changed files with 94 additions and 95 deletions

View file

@ -1,6 +1,6 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v2.11.0
rev: v2.12.0
hooks:
- id: pyupgrade
args: [--py38-plus]

View file

@ -226,7 +226,7 @@ class ZWaveProtectionView(HomeAssistantView):
return self.json(protection_options)
protections = node.get_protections()
protection_options = {
"value_id": "{:d}".format(list(protections)[0]),
"value_id": f"{list(protections)[0]:d}",
"selected": node.get_protection_item(list(protections)[0]),
"options": node.get_protection_items(list(protections)[0]),
}

View file

@ -24,11 +24,11 @@ def create_matcher(utterance):
# Group part
if group_match is not None:
pattern.append(r"(?P<{}>[\w ]+?)\s*".format(group_match.groups()[0]))
pattern.append(fr"(?P<{group_match.groups()[0]}>[\w ]+?)\s*")
# Optional part
elif optional_match is not None:
pattern.append(r"(?:{} *)?".format(optional_match.groups()[0]))
pattern.append(fr"(?:{optional_match.groups()[0]} *)?")
pattern.append("$")
return re.compile("".join(pattern), re.I)

View file

@ -109,7 +109,7 @@ class DysonClimateEntity(DysonEntity, ClimateEntity):
and self._device.environmental_state.temperature
):
temperature_kelvin = self._device.environmental_state.temperature
return float("{:.1f}".format(temperature_kelvin - 273))
return float(f"{temperature_kelvin - 273:.1f}")
return None
@property

View file

@ -55,7 +55,7 @@ class BanSensor(SensorEntity):
self.last_ban = None
self.log_parser = log_parser
self.log_parser.ip_regex[self.jail] = re.compile(
r"\[{}\]\s*(Ban|Unban) (.*)".format(re.escape(self.jail))
fr"\[{re.escape(self.jail)}\]\s*(Ban|Unban) (.*)"
)
_LOGGER.debug("Setting up jail %s", self.jail)

View file

@ -356,7 +356,7 @@ class RachioZone(RachioSwitch):
def __str__(self):
"""Display the zone as a string."""
return 'Rachio Zone "{}" on {}'.format(self.name, str(self._controller))
return f'Rachio Zone "{self.name}" on {str(self._controller)}'
@property
def zone_id(self) -> str:

View file

@ -56,7 +56,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Reddit sensor platform."""
subreddits = config[CONF_SUBREDDITS]
user_agent = "{}_home_assistant_sensor".format(config[CONF_USERNAME])
user_agent = f"{config[CONF_USERNAME]}_home_assistant_sensor"
limit = config[CONF_MAXIMUM]
sort_by = config[CONF_SORT_BY]

View file

@ -167,7 +167,7 @@ def setup(hass, config):
for repetier in config[DOMAIN]:
_LOGGER.debug("Repetier server config %s", repetier[CONF_HOST])
url = "http://{}".format(repetier[CONF_HOST])
url = f"http://{repetier[CONF_HOST]}"
port = repetier[CONF_PORT]
api_key = repetier[CONF_API_KEY]

View file

@ -52,7 +52,7 @@ class RingBinarySensor(RingEntityMixin, BinarySensorEntity):
super().__init__(config_entry_id, device)
self._ring = ring
self._sensor_type = sensor_type
self._name = "{} {}".format(self._device.name, SENSOR_TYPES.get(sensor_type)[0])
self._name = f"{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}"

View file

@ -44,9 +44,9 @@ class RingSensor(RingEntityMixin, SensorEntity):
super().__init__(config_entry_id, device)
self._sensor_type = sensor_type
self._extra = None
self._icon = "mdi:{}".format(SENSOR_TYPES.get(sensor_type)[3])
self._icon = f"mdi:{SENSOR_TYPES.get(sensor_type)[3]}"
self._kind = SENSOR_TYPES.get(sensor_type)[4]
self._name = "{} {}".format(self._device.name, SENSOR_TYPES.get(sensor_type)[0])
self._name = f"{self._device.name} {SENSOR_TYPES.get(sensor_type)[0]}"
self._unique_id = f"{device.id}-{sensor_type}"
@property

View file

@ -32,13 +32,11 @@ def _hass_domain_validator(config):
def _platform_validator(config):
"""Validate it is a valid platform."""
try:
platform = importlib.import_module(
".{}".format(config[CONF_PLATFORM]), __name__
)
platform = importlib.import_module(f".{config[CONF_PLATFORM]}", __name__)
except ImportError:
try:
platform = importlib.import_module(
"homeassistant.components.{}.scene".format(config[CONF_PLATFORM])
f"homeassistant.components.{config[CONF_PLATFORM]}.scene"
)
except ImportError:
raise vol.Invalid("Invalid platform specified") from None

View file

@ -47,7 +47,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
for pmname in coll.supported_values():
if config.get(CONF_NAME) is not None:
name = "{} PM{}".format(config.get(CONF_NAME), pmname)
name = f"{config.get(CONF_NAME)} PM{pmname}"
else:
name = f"PM{pmname}"
dev.append(ParticulateMatterSensor(coll, name, pmname))

View file

@ -69,7 +69,7 @@ class ImageProcessingSsocr(ImageProcessingEntity):
if name:
self._name = name
else:
self._name = "SevenSegment OCR {}".format(split_entity_id(camera_entity)[1])
self._name = f"SevenSegment OCR {split_entity_id(camera_entity)[1]}"
self._state = None
self.filepath = os.path.join(

View file

@ -132,7 +132,7 @@ class SeventeenTrackSummarySensor(SensorEntity):
@property
def unique_id(self):
"""Return a unique, Home Assistant friendly identifier for this entity."""
return "summary_{}_{}".format(self._data.account_id, slugify(self._status))
return f"summary_{self._data.account_id}_{slugify(self._status)}"
@property
def unit_of_measurement(self):

View file

@ -66,7 +66,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
devs = []
for sensor_type, sensor_class in sensor_classes.items():
name = "{} {}".format(config.get(CONF_NAME), sensor_type.capitalize())
name = f"{config.get(CONF_NAME)} {sensor_type.capitalize()}"
devs.append(sensor_class(sensor_client, name))
add_entities(devs)

View file

@ -45,7 +45,7 @@ class SkybellSensor(SkybellDevice, SensorEntity):
"""Initialize a sensor for a Skybell device."""
super().__init__(device)
self._sensor_type = sensor_type
self._icon = "mdi:{}".format(SENSOR_TYPES[self._sensor_type][1])
self._icon = f"mdi:{SENSOR_TYPES[self._sensor_type][1]}"
self._name = "{} {}".format(
self._device.name, SENSOR_TYPES[self._sensor_type][0]
)

View file

@ -358,12 +358,12 @@ class SmartThingsThreeAxisSensor(SmartThingsEntity, SensorEntity):
@property
def name(self) -> str:
"""Return the name of the binary sensor."""
return "{} {}".format(self._device.label, THREE_AXIS_NAMES[self._index])
return f"{self._device.label} {THREE_AXIS_NAMES[self._index]}"
@property
def unique_id(self) -> str:
"""Return a unique ID."""
return "{}.{}".format(self._device.device_id, THREE_AXIS_NAMES[self._index])
return f"{self._device.device_id}.{THREE_AXIS_NAMES[self._index]}"
@property
def state(self):

View file

@ -153,7 +153,7 @@ class SolarEdgeSensor(CoordinatorEntity, SensorEntity):
@property
def name(self) -> str:
"""Return the name."""
return "{} ({})".format(self.platform_name, SENSOR_TYPES[self.sensor_key][1])
return f"{self.platform_name} ({SENSOR_TYPES[self.sensor_key][1]})"
@property
def icon(self) -> str | None:

View file

@ -81,8 +81,8 @@ class HlsPlaylistView(StreamView):
return []
playlist = [
"#EXT-X-MEDIA-SEQUENCE:{}".format(segments[0].sequence),
"#EXT-X-DISCONTINUITY-SEQUENCE:{}".format(segments[0].stream_id),
f"#EXT-X-MEDIA-SEQUENCE:{segments[0].sequence}",
f"#EXT-X-DISCONTINUITY-SEQUENCE:{segments[0].stream_id}",
]
last_stream_id = segments[0].stream_id
@ -91,7 +91,7 @@ class HlsPlaylistView(StreamView):
playlist.append("#EXT-X-DISCONTINUITY")
playlist.extend(
[
"#EXTINF:{:.04f},".format(float(segment.duration)),
f"#EXTINF:{float(segment.duration):.04f},",
f"./segment/{segment.sequence}.m4s",
]
)

View file

@ -51,7 +51,7 @@ class SynologyChatNotificationService(BaseNotificationService):
if file_url:
data["file_url"] = file_url
to_send = "payload={}".format(json.dumps(data))
to_send = f"payload={json.dumps(data)}"
response = requests.post(
self._resource, data=to_send, timeout=10, verify=self._verify_ssl

View file

@ -56,7 +56,7 @@ class Ted5000Sensor(SensorEntity):
"""Initialize the sensor."""
units = {POWER_WATT: "power", VOLT: "voltage"}
self._gateway = gateway
self._name = "{} mtu{} {}".format(name, mtu, units[unit])
self._name = f"{name} mtu{mtu} {units[unit]}"
self._mtu = mtu
self._unit = unit
self.update()

View file

@ -303,9 +303,7 @@ async def async_setup(hass, config):
p_type = p_config.get(CONF_PLATFORM)
platform = importlib.import_module(
".{}".format(p_config[CONF_PLATFORM]), __name__
)
platform = importlib.import_module(f".{p_config[CONF_PLATFORM]}", __name__)
_LOGGER.info("Setting up %s.%s", DOMAIN, p_type)
try:

View file

@ -218,7 +218,7 @@ class TensorFlowImageProcessor(ImageProcessingEntity):
if name:
self._name = name
else:
self._name = "TensorFlow {}".format(split_entity_id(camera_entity)[1])
self._name = f"TensorFlow {split_entity_id(camera_entity)[1]}"
self._category_index = category_index
self._min_confidence = config.get(CONF_CONFIDENCE)
self._file_out = config.get(CONF_FILE_OUT)

View file

@ -87,7 +87,7 @@ class ThinkingCleanerSensor(SensorEntity):
@property
def name(self):
"""Return the name of the sensor."""
return "{} {}".format(self._tc_object.name, SENSOR_TYPES[self.type][0])
return f"{self._tc_object.name} {SENSOR_TYPES[self.type][0]}"
@property
def icon(self):

View file

@ -385,7 +385,7 @@ class TodoistProjectData:
task[SUMMARY] = data[CONTENT]
task[COMPLETED] = data[CHECKED] == 1
task[PRIORITY] = data[PRIORITY]
task[DESCRIPTION] = "https://todoist.com/showTask?id={}".format(data[ID])
task[DESCRIPTION] = f"https://todoist.com/showTask?id={data[ID]}"
# All task Labels (optional parameter).
task[LABELS] = [

View file

@ -105,7 +105,7 @@ class TravisCISensor(SensorEntity):
self._user = user
self._branch = branch
self._state = None
self._name = "{} {}".format(self._repo_name, SENSOR_TYPES[self._sensor_type][0])
self._name = f"{self._repo_name} {SENSOR_TYPES[self._sensor_type][0]}"
@property
def name(self):

View file

@ -47,7 +47,7 @@ class VeSyncDevice(ToggleEntity):
def unique_id(self):
"""Return the ID of this device."""
if isinstance(self.device.sub_device_no, int):
return "{}{}".format(self.device.cid, str(self.device.sub_device_no))
return f"{self.device.cid}{str(self.device.sub_device_no)}"
return self.device.cid
@property

View file

@ -89,7 +89,7 @@ class VolkszaehlerSensor(SensorEntity):
@property
def name(self):
"""Return the name of the sensor."""
return "{} {}".format(self._name, SENSOR_TYPES[self.type][0])
return f"{self._name} {SENSOR_TYPES[self.type][0]}"
@property
def icon(self):

View file

@ -18,7 +18,7 @@ async def async_setup_scanner(hass, config, async_see, discovery_info=None):
async def see_vehicle():
"""Handle the reporting of the vehicle position."""
host_name = instrument.vehicle_name
dev_id = "volvo_{}".format(slugify(host_name))
dev_id = f"volvo_{slugify(host_name)}"
await async_see(
dev_id=dev_id,
host_name=host_name,

View file

@ -121,7 +121,7 @@ class WaqiSensor(SensorEntity):
"""Return the name of the sensor."""
if self.station_name:
return f"WAQI {self.station_name}"
return "WAQI {}".format(self.url if self.url else self.uid)
return f"WAQI {self.url if self.url else self.uid}"
@property
def icon(self):

View file

@ -74,7 +74,7 @@ class WaterFurnaceSensor(SensorEntity):
# This ensures that the sensors are isolated per waterfurnace unit
self.entity_id = ENTITY_ID_FORMAT.format(
"wf_{}_{}".format(slugify(self.client.unit), slugify(self._attr))
f"wf_{slugify(self.client.unit)}_{slugify(self._attr)}"
)
@property

View file

@ -69,4 +69,4 @@ def resolve_zone(hass, friendly_name):
def _get_location_from_attributes(state):
"""Get the lat/long string from an states attributes."""
attr = state.attributes
return "{},{}".format(attr.get(ATTR_LATITUDE), attr.get(ATTR_LONGITUDE))
return f"{attr.get(ATTR_LATITUDE)},{attr.get(ATTR_LONGITUDE)}"

View file

@ -315,7 +315,7 @@ class ZDOChannel(LogMixin):
self._cluster = cluster
self._zha_device = device
self._status = ChannelStatus.CREATED
self._unique_id = "{}:{}_ZDO".format(str(device.ieee), device.name)
self._unique_id = f"{str(device.ieee)}:{device.name}_ZDO"
self._cluster.add_listener(self)
@property

View file

@ -360,9 +360,7 @@ class ZHAGateway:
if zha_device is not None:
device_info = zha_device.zha_device_info
zha_device.async_cleanup_handles()
async_dispatcher_send(
self._hass, "{}_{}".format(SIGNAL_REMOVE, str(zha_device.ieee))
)
async_dispatcher_send(self._hass, f"{SIGNAL_REMOVE}_{str(zha_device.ieee)}")
asyncio.ensure_future(self._async_remove_device(zha_device, entity_refs))
if device_info is not None:
async_dispatcher_send(

View file

@ -10,13 +10,13 @@ def icon_for_battery_level(
if battery_level is None:
return f"{icon}-unknown"
if charging and battery_level > 10:
icon += "-charging-{}".format(int(round(battery_level / 20 - 0.01)) * 20)
icon += f"-charging-{int(round(battery_level / 20 - 0.01)) * 20}"
elif charging:
icon += "-outline"
elif battery_level <= 5:
icon += "-alert"
elif 5 < battery_level < 95:
icon += "-{}".format(int(round(battery_level / 10 - 0.01)) * 10)
icon += f"-{int(round(battery_level / 10 - 0.01)) * 10}"
return icon

View file

@ -105,4 +105,4 @@ def find_coordinates(
def _get_location_from_attributes(entity_state: State) -> str:
"""Get the lat/long string from an entities attributes."""
attr = entity_state.attributes
return "{},{}".format(attr.get(ATTR_LATITUDE), attr.get(ATTR_LONGITUDE))
return f"{attr.get(ATTR_LATITUDE)},{attr.get(ATTR_LONGITUDE)}"

View file

@ -427,7 +427,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 "{:02x}{:02x}{:02x}".format(round(r), round(g), round(b))
return f"{round(r):02x}{round(g):02x}{round(b):02x}"
def rgb_hex_to_rgb_list(hex_string: str) -> list[int]:

View file

@ -11,5 +11,5 @@ isort==5.7.0
pycodestyle==2.7.0
pydocstyle==6.0.0
pyflakes==2.3.1
pyupgrade==2.11.0
pyupgrade==2.12.0
yamllint==1.24.2

View file

@ -121,7 +121,7 @@ def main():
if plugin is requirements and not config.specific_integrations:
print()
plugin.validate(integrations, config)
print(" done in {:.2f}s".format(monotonic() - start))
print(f" done in {monotonic() - start:.2f}s")
except RuntimeError as err:
print()
print()

View file

@ -17,12 +17,12 @@ import pytest
async def test_ingress_request_get(hassio_client, build_type, aioclient_mock):
"""Test no auth needed for ."""
aioclient_mock.get(
"http://127.0.0.1/ingress/{}/{}".format(build_type[0], build_type[1]),
f"http://127.0.0.1/ingress/{build_type[0]}/{build_type[1]}",
text="test",
)
resp = await hassio_client.get(
"/api/hassio_ingress/{}/{}".format(build_type[0], build_type[1]),
f"/api/hassio_ingress/{build_type[0]}/{build_type[1]}",
headers={"X-Test-Header": "beer"},
)
@ -34,9 +34,10 @@ async def test_ingress_request_get(hassio_client, build_type, aioclient_mock):
# Check we forwarded command
assert len(aioclient_mock.mock_calls) == 1
assert aioclient_mock.mock_calls[-1][3]["X-Hassio-Key"] == "123456"
assert aioclient_mock.mock_calls[-1][3][
"X-Ingress-Path"
] == "/api/hassio_ingress/{}".format(build_type[0])
assert (
aioclient_mock.mock_calls[-1][3]["X-Ingress-Path"]
== f"/api/hassio_ingress/{build_type[0]}"
)
assert aioclient_mock.mock_calls[-1][3]["X-Test-Header"] == "beer"
assert aioclient_mock.mock_calls[-1][3][X_FORWARDED_FOR]
assert aioclient_mock.mock_calls[-1][3][X_FORWARDED_HOST]
@ -56,12 +57,12 @@ async def test_ingress_request_get(hassio_client, build_type, aioclient_mock):
async def test_ingress_request_post(hassio_client, build_type, aioclient_mock):
"""Test no auth needed for ."""
aioclient_mock.post(
"http://127.0.0.1/ingress/{}/{}".format(build_type[0], build_type[1]),
f"http://127.0.0.1/ingress/{build_type[0]}/{build_type[1]}",
text="test",
)
resp = await hassio_client.post(
"/api/hassio_ingress/{}/{}".format(build_type[0], build_type[1]),
f"/api/hassio_ingress/{build_type[0]}/{build_type[1]}",
headers={"X-Test-Header": "beer"},
)
@ -73,9 +74,10 @@ async def test_ingress_request_post(hassio_client, build_type, aioclient_mock):
# Check we forwarded command
assert len(aioclient_mock.mock_calls) == 1
assert aioclient_mock.mock_calls[-1][3]["X-Hassio-Key"] == "123456"
assert aioclient_mock.mock_calls[-1][3][
"X-Ingress-Path"
] == "/api/hassio_ingress/{}".format(build_type[0])
assert (
aioclient_mock.mock_calls[-1][3]["X-Ingress-Path"]
== f"/api/hassio_ingress/{build_type[0]}"
)
assert aioclient_mock.mock_calls[-1][3]["X-Test-Header"] == "beer"
assert aioclient_mock.mock_calls[-1][3][X_FORWARDED_FOR]
assert aioclient_mock.mock_calls[-1][3][X_FORWARDED_HOST]
@ -95,12 +97,12 @@ async def test_ingress_request_post(hassio_client, build_type, aioclient_mock):
async def test_ingress_request_put(hassio_client, build_type, aioclient_mock):
"""Test no auth needed for ."""
aioclient_mock.put(
"http://127.0.0.1/ingress/{}/{}".format(build_type[0], build_type[1]),
f"http://127.0.0.1/ingress/{build_type[0]}/{build_type[1]}",
text="test",
)
resp = await hassio_client.put(
"/api/hassio_ingress/{}/{}".format(build_type[0], build_type[1]),
f"/api/hassio_ingress/{build_type[0]}/{build_type[1]}",
headers={"X-Test-Header": "beer"},
)
@ -112,9 +114,10 @@ async def test_ingress_request_put(hassio_client, build_type, aioclient_mock):
# Check we forwarded command
assert len(aioclient_mock.mock_calls) == 1
assert aioclient_mock.mock_calls[-1][3]["X-Hassio-Key"] == "123456"
assert aioclient_mock.mock_calls[-1][3][
"X-Ingress-Path"
] == "/api/hassio_ingress/{}".format(build_type[0])
assert (
aioclient_mock.mock_calls[-1][3]["X-Ingress-Path"]
== f"/api/hassio_ingress/{build_type[0]}"
)
assert aioclient_mock.mock_calls[-1][3]["X-Test-Header"] == "beer"
assert aioclient_mock.mock_calls[-1][3][X_FORWARDED_FOR]
assert aioclient_mock.mock_calls[-1][3][X_FORWARDED_HOST]
@ -134,12 +137,12 @@ async def test_ingress_request_put(hassio_client, build_type, aioclient_mock):
async def test_ingress_request_delete(hassio_client, build_type, aioclient_mock):
"""Test no auth needed for ."""
aioclient_mock.delete(
"http://127.0.0.1/ingress/{}/{}".format(build_type[0], build_type[1]),
f"http://127.0.0.1/ingress/{build_type[0]}/{build_type[1]}",
text="test",
)
resp = await hassio_client.delete(
"/api/hassio_ingress/{}/{}".format(build_type[0], build_type[1]),
f"/api/hassio_ingress/{build_type[0]}/{build_type[1]}",
headers={"X-Test-Header": "beer"},
)
@ -151,9 +154,10 @@ async def test_ingress_request_delete(hassio_client, build_type, aioclient_mock)
# Check we forwarded command
assert len(aioclient_mock.mock_calls) == 1
assert aioclient_mock.mock_calls[-1][3]["X-Hassio-Key"] == "123456"
assert aioclient_mock.mock_calls[-1][3][
"X-Ingress-Path"
] == "/api/hassio_ingress/{}".format(build_type[0])
assert (
aioclient_mock.mock_calls[-1][3]["X-Ingress-Path"]
== f"/api/hassio_ingress/{build_type[0]}"
)
assert aioclient_mock.mock_calls[-1][3]["X-Test-Header"] == "beer"
assert aioclient_mock.mock_calls[-1][3][X_FORWARDED_FOR]
assert aioclient_mock.mock_calls[-1][3][X_FORWARDED_HOST]
@ -173,12 +177,12 @@ async def test_ingress_request_delete(hassio_client, build_type, aioclient_mock)
async def test_ingress_request_patch(hassio_client, build_type, aioclient_mock):
"""Test no auth needed for ."""
aioclient_mock.patch(
"http://127.0.0.1/ingress/{}/{}".format(build_type[0], build_type[1]),
f"http://127.0.0.1/ingress/{build_type[0]}/{build_type[1]}",
text="test",
)
resp = await hassio_client.patch(
"/api/hassio_ingress/{}/{}".format(build_type[0], build_type[1]),
f"/api/hassio_ingress/{build_type[0]}/{build_type[1]}",
headers={"X-Test-Header": "beer"},
)
@ -190,9 +194,10 @@ async def test_ingress_request_patch(hassio_client, build_type, aioclient_mock):
# Check we forwarded command
assert len(aioclient_mock.mock_calls) == 1
assert aioclient_mock.mock_calls[-1][3]["X-Hassio-Key"] == "123456"
assert aioclient_mock.mock_calls[-1][3][
"X-Ingress-Path"
] == "/api/hassio_ingress/{}".format(build_type[0])
assert (
aioclient_mock.mock_calls[-1][3]["X-Ingress-Path"]
== f"/api/hassio_ingress/{build_type[0]}"
)
assert aioclient_mock.mock_calls[-1][3]["X-Test-Header"] == "beer"
assert aioclient_mock.mock_calls[-1][3][X_FORWARDED_FOR]
assert aioclient_mock.mock_calls[-1][3][X_FORWARDED_HOST]
@ -212,12 +217,12 @@ async def test_ingress_request_patch(hassio_client, build_type, aioclient_mock):
async def test_ingress_request_options(hassio_client, build_type, aioclient_mock):
"""Test no auth needed for ."""
aioclient_mock.options(
"http://127.0.0.1/ingress/{}/{}".format(build_type[0], build_type[1]),
f"http://127.0.0.1/ingress/{build_type[0]}/{build_type[1]}",
text="test",
)
resp = await hassio_client.options(
"/api/hassio_ingress/{}/{}".format(build_type[0], build_type[1]),
f"/api/hassio_ingress/{build_type[0]}/{build_type[1]}",
headers={"X-Test-Header": "beer"},
)
@ -229,9 +234,10 @@ async def test_ingress_request_options(hassio_client, build_type, aioclient_mock
# Check we forwarded command
assert len(aioclient_mock.mock_calls) == 1
assert aioclient_mock.mock_calls[-1][3]["X-Hassio-Key"] == "123456"
assert aioclient_mock.mock_calls[-1][3][
"X-Ingress-Path"
] == "/api/hassio_ingress/{}".format(build_type[0])
assert (
aioclient_mock.mock_calls[-1][3]["X-Ingress-Path"]
== f"/api/hassio_ingress/{build_type[0]}"
)
assert aioclient_mock.mock_calls[-1][3]["X-Test-Header"] == "beer"
assert aioclient_mock.mock_calls[-1][3][X_FORWARDED_FOR]
assert aioclient_mock.mock_calls[-1][3][X_FORWARDED_HOST]
@ -250,22 +256,21 @@ async def test_ingress_request_options(hassio_client, build_type, aioclient_mock
)
async def test_ingress_websocket(hassio_client, build_type, aioclient_mock):
"""Test no auth needed for ."""
aioclient_mock.get(
"http://127.0.0.1/ingress/{}/{}".format(build_type[0], build_type[1])
)
aioclient_mock.get(f"http://127.0.0.1/ingress/{build_type[0]}/{build_type[1]}")
# Ignore error because we can setup a full IO infrastructure
await hassio_client.ws_connect(
"/api/hassio_ingress/{}/{}".format(build_type[0], build_type[1]),
f"/api/hassio_ingress/{build_type[0]}/{build_type[1]}",
headers={"X-Test-Header": "beer"},
)
# Check we forwarded command
assert len(aioclient_mock.mock_calls) == 1
assert aioclient_mock.mock_calls[-1][3]["X-Hassio-Key"] == "123456"
assert aioclient_mock.mock_calls[-1][3][
"X-Ingress-Path"
] == "/api/hassio_ingress/{}".format(build_type[0])
assert (
aioclient_mock.mock_calls[-1][3]["X-Ingress-Path"]
== f"/api/hassio_ingress/{build_type[0]}"
)
assert aioclient_mock.mock_calls[-1][3]["X-Test-Header"] == "beer"
assert aioclient_mock.mock_calls[-1][3][X_FORWARDED_FOR]
assert aioclient_mock.mock_calls[-1][3][X_FORWARDED_HOST]

View file

@ -34,7 +34,7 @@ def test_get_states(hass_history):
with patch("homeassistant.components.recorder.dt_util.utcnow", return_value=now):
for i in range(5):
state = ha.State(
"test.point_in_time_{}".format(i % 5),
f"test.point_in_time_{i % 5}",
f"State {i}",
{"attribute_test": i},
)
@ -49,7 +49,7 @@ def test_get_states(hass_history):
with patch("homeassistant.components.recorder.dt_util.utcnow", return_value=future):
for i in range(5):
state = ha.State(
"test.point_in_time_{}".format(i % 5),
f"test.point_in_time_{i % 5}",
f"State {i}",
{"attribute_test": i},
)

View file

@ -86,7 +86,7 @@ async def test_registration_encryption(hass, hass_client):
container = {"type": "render_template", "encrypted": True, "encrypted_data": data}
resp = await api_client.post(
"/api/webhook/{}".format(register_json[CONF_WEBHOOK_ID]), json=container
f"/api/webhook/{register_json[CONF_WEBHOOK_ID]}", json=container
)
assert resp.status == 200

View file

@ -170,7 +170,7 @@ async def test_config_flow_entry_migrate(hass):
assert mock_entity.device_id == MOCK_DEVICE_ID
# Test that last four of credentials is appended to the unique_id.
assert mock_entity.unique_id == "{}_{}".format(MOCK_UNIQUE_ID, MOCK_CREDS[-4:])
assert mock_entity.unique_id == f"{MOCK_UNIQUE_ID}_{MOCK_CREDS[-4:]}"
# Test that config entry is at the current version.
assert mock_entry.version == VERSION

View file

@ -299,7 +299,7 @@ async def test_device_info_is_set_from_status_correctly(hass, patch_get_status):
# Reformat mock status-sw_version for assertion.
mock_version = MOCK_STATUS_STANDBY["system-version"]
mock_version = mock_version[1:4]
mock_version = "{}.{}".format(mock_version[0], mock_version[1:])
mock_version = f"{mock_version[0]}.{mock_version[1:]}"
mock_state = hass.states.get(mock_entity_id).state

View file

@ -37,7 +37,7 @@ def test_battery_icon():
else:
postfix_charging = "-charging-100"
if 5 < level < 95:
postfix = "-{}".format(int(round(level / 10 - 0.01)) * 10)
postfix = f"-{int(round(level / 10 - 0.01)) * 10}"
elif level <= 5:
postfix = "-alert"
else: