diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2f4aea74ae9..97093bc8dbe 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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] diff --git a/homeassistant/components/config/zwave.py b/homeassistant/components/config/zwave.py index ca1a99c6bb7..dd1bf1f08e2 100644 --- a/homeassistant/components/config/zwave.py +++ b/homeassistant/components/config/zwave.py @@ -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]), } diff --git a/homeassistant/components/conversation/util.py b/homeassistant/components/conversation/util.py index 4904cb9f990..b21b75be9b5 100644 --- a/homeassistant/components/conversation/util.py +++ b/homeassistant/components/conversation/util.py @@ -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) diff --git a/homeassistant/components/dyson/climate.py b/homeassistant/components/dyson/climate.py index e7b8f42f1b1..4f4c4d7cbba 100644 --- a/homeassistant/components/dyson/climate.py +++ b/homeassistant/components/dyson/climate.py @@ -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 diff --git a/homeassistant/components/fail2ban/sensor.py b/homeassistant/components/fail2ban/sensor.py index 29ac5c3d0b5..908ab5d77c0 100644 --- a/homeassistant/components/fail2ban/sensor.py +++ b/homeassistant/components/fail2ban/sensor.py @@ -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) diff --git a/homeassistant/components/rachio/switch.py b/homeassistant/components/rachio/switch.py index 8d87b688aa4..30146cb44f6 100644 --- a/homeassistant/components/rachio/switch.py +++ b/homeassistant/components/rachio/switch.py @@ -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: diff --git a/homeassistant/components/reddit/sensor.py b/homeassistant/components/reddit/sensor.py index a88de916009..1e755b950bf 100644 --- a/homeassistant/components/reddit/sensor.py +++ b/homeassistant/components/reddit/sensor.py @@ -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] diff --git a/homeassistant/components/repetier/__init__.py b/homeassistant/components/repetier/__init__.py index a680fd77761..c104fc447e2 100644 --- a/homeassistant/components/repetier/__init__.py +++ b/homeassistant/components/repetier/__init__.py @@ -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] diff --git a/homeassistant/components/ring/binary_sensor.py b/homeassistant/components/ring/binary_sensor.py index 18ce87e722e..28d686df06a 100644 --- a/homeassistant/components/ring/binary_sensor.py +++ b/homeassistant/components/ring/binary_sensor.py @@ -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}" diff --git a/homeassistant/components/ring/sensor.py b/homeassistant/components/ring/sensor.py index a2b9e2300dc..fb1c38fcbde 100644 --- a/homeassistant/components/ring/sensor.py +++ b/homeassistant/components/ring/sensor.py @@ -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 diff --git a/homeassistant/components/scene/__init__.py b/homeassistant/components/scene/__init__.py index e11934c61c3..ced56fe5905 100644 --- a/homeassistant/components/scene/__init__.py +++ b/homeassistant/components/scene/__init__.py @@ -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 diff --git a/homeassistant/components/serial_pm/sensor.py b/homeassistant/components/serial_pm/sensor.py index b81c60e0a19..fd017661de2 100644 --- a/homeassistant/components/serial_pm/sensor.py +++ b/homeassistant/components/serial_pm/sensor.py @@ -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)) diff --git a/homeassistant/components/seven_segments/image_processing.py b/homeassistant/components/seven_segments/image_processing.py index 4515ec7441b..6ff6b63746a 100644 --- a/homeassistant/components/seven_segments/image_processing.py +++ b/homeassistant/components/seven_segments/image_processing.py @@ -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( diff --git a/homeassistant/components/seventeentrack/sensor.py b/homeassistant/components/seventeentrack/sensor.py index e856f71b008..ab0f0779656 100644 --- a/homeassistant/components/seventeentrack/sensor.py +++ b/homeassistant/components/seventeentrack/sensor.py @@ -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): diff --git a/homeassistant/components/sht31/sensor.py b/homeassistant/components/sht31/sensor.py index fd5506ee513..65ebbf0d882 100644 --- a/homeassistant/components/sht31/sensor.py +++ b/homeassistant/components/sht31/sensor.py @@ -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) diff --git a/homeassistant/components/skybell/sensor.py b/homeassistant/components/skybell/sensor.py index 8dc13814c67..de99a22f4c9 100644 --- a/homeassistant/components/skybell/sensor.py +++ b/homeassistant/components/skybell/sensor.py @@ -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] ) diff --git a/homeassistant/components/smartthings/sensor.py b/homeassistant/components/smartthings/sensor.py index 86377e32e23..533d8f6476e 100644 --- a/homeassistant/components/smartthings/sensor.py +++ b/homeassistant/components/smartthings/sensor.py @@ -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): diff --git a/homeassistant/components/solaredge/sensor.py b/homeassistant/components/solaredge/sensor.py index b93a84a77fb..d827990ac55 100644 --- a/homeassistant/components/solaredge/sensor.py +++ b/homeassistant/components/solaredge/sensor.py @@ -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: diff --git a/homeassistant/components/stream/hls.py b/homeassistant/components/stream/hls.py index 4909bbf95a3..ffeae4dbffd 100644 --- a/homeassistant/components/stream/hls.py +++ b/homeassistant/components/stream/hls.py @@ -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", ] ) diff --git a/homeassistant/components/synology_chat/notify.py b/homeassistant/components/synology_chat/notify.py index df43c5668f3..f73fd65ba3f 100644 --- a/homeassistant/components/synology_chat/notify.py +++ b/homeassistant/components/synology_chat/notify.py @@ -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 diff --git a/homeassistant/components/ted5000/sensor.py b/homeassistant/components/ted5000/sensor.py index d618ca9c2cf..62cdd5066ad 100644 --- a/homeassistant/components/ted5000/sensor.py +++ b/homeassistant/components/ted5000/sensor.py @@ -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() diff --git a/homeassistant/components/telegram_bot/__init__.py b/homeassistant/components/telegram_bot/__init__.py index 86bf4c24407..589d85bd20e 100644 --- a/homeassistant/components/telegram_bot/__init__.py +++ b/homeassistant/components/telegram_bot/__init__.py @@ -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: diff --git a/homeassistant/components/tensorflow/image_processing.py b/homeassistant/components/tensorflow/image_processing.py index dad83005512..f4e90a83154 100644 --- a/homeassistant/components/tensorflow/image_processing.py +++ b/homeassistant/components/tensorflow/image_processing.py @@ -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) diff --git a/homeassistant/components/thinkingcleaner/sensor.py b/homeassistant/components/thinkingcleaner/sensor.py index 56cf272f7d1..fa1dfd5988c 100644 --- a/homeassistant/components/thinkingcleaner/sensor.py +++ b/homeassistant/components/thinkingcleaner/sensor.py @@ -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): diff --git a/homeassistant/components/todoist/calendar.py b/homeassistant/components/todoist/calendar.py index 976462c95fa..8b9379d2186 100644 --- a/homeassistant/components/todoist/calendar.py +++ b/homeassistant/components/todoist/calendar.py @@ -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] = [ diff --git a/homeassistant/components/travisci/sensor.py b/homeassistant/components/travisci/sensor.py index 94a6ba3a48f..82b158aa0ec 100644 --- a/homeassistant/components/travisci/sensor.py +++ b/homeassistant/components/travisci/sensor.py @@ -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): diff --git a/homeassistant/components/vesync/common.py b/homeassistant/components/vesync/common.py index 240a5e48287..fcab5bb5a63 100644 --- a/homeassistant/components/vesync/common.py +++ b/homeassistant/components/vesync/common.py @@ -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 diff --git a/homeassistant/components/volkszaehler/sensor.py b/homeassistant/components/volkszaehler/sensor.py index 61fcf1d2969..4eb2f512f31 100644 --- a/homeassistant/components/volkszaehler/sensor.py +++ b/homeassistant/components/volkszaehler/sensor.py @@ -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): diff --git a/homeassistant/components/volvooncall/device_tracker.py b/homeassistant/components/volvooncall/device_tracker.py index eab42156c9a..ebc4990db55 100644 --- a/homeassistant/components/volvooncall/device_tracker.py +++ b/homeassistant/components/volvooncall/device_tracker.py @@ -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, diff --git a/homeassistant/components/waqi/sensor.py b/homeassistant/components/waqi/sensor.py index ef01c057a9e..084ec17bb28 100644 --- a/homeassistant/components/waqi/sensor.py +++ b/homeassistant/components/waqi/sensor.py @@ -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): diff --git a/homeassistant/components/waterfurnace/sensor.py b/homeassistant/components/waterfurnace/sensor.py index 91e455d03d6..fe7c94ed634 100644 --- a/homeassistant/components/waterfurnace/sensor.py +++ b/homeassistant/components/waterfurnace/sensor.py @@ -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 diff --git a/homeassistant/components/waze_travel_time/helpers.py b/homeassistant/components/waze_travel_time/helpers.py index 8c8c89f28e6..326a6018c96 100644 --- a/homeassistant/components/waze_travel_time/helpers.py +++ b/homeassistant/components/waze_travel_time/helpers.py @@ -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)}" diff --git a/homeassistant/components/zha/core/channels/base.py b/homeassistant/components/zha/core/channels/base.py index bc93459dbad..4238707656d 100644 --- a/homeassistant/components/zha/core/channels/base.py +++ b/homeassistant/components/zha/core/channels/base.py @@ -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 diff --git a/homeassistant/components/zha/core/gateway.py b/homeassistant/components/zha/core/gateway.py index de65ed6695e..96e4a7c3eb8 100644 --- a/homeassistant/components/zha/core/gateway.py +++ b/homeassistant/components/zha/core/gateway.py @@ -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( diff --git a/homeassistant/helpers/icon.py b/homeassistant/helpers/icon.py index 628dc9d341e..a289ab4a874 100644 --- a/homeassistant/helpers/icon.py +++ b/homeassistant/helpers/icon.py @@ -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 diff --git a/homeassistant/helpers/location.py b/homeassistant/helpers/location.py index a613220ef0f..ff27c580d23 100644 --- a/homeassistant/helpers/location.py +++ b/homeassistant/helpers/location.py @@ -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)}" diff --git a/homeassistant/util/color.py b/homeassistant/util/color.py index 2a34fe82c59..4b5c7a11cbc 100644 --- a/homeassistant/util/color.py +++ b/homeassistant/util/color.py @@ -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]: diff --git a/requirements_test_pre_commit.txt b/requirements_test_pre_commit.txt index 06e87a5c51c..0bdcde40808 100644 --- a/requirements_test_pre_commit.txt +++ b/requirements_test_pre_commit.txt @@ -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 diff --git a/script/hassfest/__main__.py b/script/hassfest/__main__.py index 6901622bfb3..8edc3ec6eb6 100644 --- a/script/hassfest/__main__.py +++ b/script/hassfest/__main__.py @@ -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() diff --git a/tests/components/hassio/test_ingress.py b/tests/components/hassio/test_ingress.py index 72500d0be20..e75de8741bf 100644 --- a/tests/components/hassio/test_ingress.py +++ b/tests/components/hassio/test_ingress.py @@ -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] diff --git a/tests/components/history/test_init.py b/tests/components/history/test_init.py index f4d1c817858..497f296437f 100644 --- a/tests/components/history/test_init.py +++ b/tests/components/history/test_init.py @@ -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}, ) diff --git a/tests/components/mobile_app/test_http_api.py b/tests/components/mobile_app/test_http_api.py index c5b363c25b0..456f3fab261 100644 --- a/tests/components/mobile_app/test_http_api.py +++ b/tests/components/mobile_app/test_http_api.py @@ -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 diff --git a/tests/components/ps4/test_init.py b/tests/components/ps4/test_init.py index da241022938..cfe2f4b8e87 100644 --- a/tests/components/ps4/test_init.py +++ b/tests/components/ps4/test_init.py @@ -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 diff --git a/tests/components/ps4/test_media_player.py b/tests/components/ps4/test_media_player.py index d402cbb01ae..3f71f5f9d52 100644 --- a/tests/components/ps4/test_media_player.py +++ b/tests/components/ps4/test_media_player.py @@ -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 diff --git a/tests/helpers/test_icon.py b/tests/helpers/test_icon.py index 4f1d4cb223f..033a6cd6b69 100644 --- a/tests/helpers/test_icon.py +++ b/tests/helpers/test_icon.py @@ -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: