Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve formatting in component files #135261

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions homeassistant/components/advantage_air/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class AdvantageAirZoneMotion(AdvantageAirZoneEntity, BinarySensorEntity):
def __init__(self, instance: AdvantageAirData, ac_key: str, zone_key: str) -> None:
"""Initialize an Advantage Air Zone Motion sensor."""
super().__init__(instance, ac_key, zone_key)
self._attr_name = f'{self._zone["name"]} motion'
self._attr_name = f"{self._zone['name']} motion"
self._attr_unique_id += "-motion"

@property
Expand All @@ -84,7 +84,7 @@ class AdvantageAirZoneMyZone(AdvantageAirZoneEntity, BinarySensorEntity):
def __init__(self, instance: AdvantageAirData, ac_key: str, zone_key: str) -> None:
"""Initialize an Advantage Air Zone MyZone sensor."""
super().__init__(instance, ac_key, zone_key)
self._attr_name = f'{self._zone["name"]} myZone'
self._attr_name = f"{self._zone['name']} myZone"
self._attr_unique_id += "-myzone"

@property
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/advantage_air/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class AdvantageAirZoneVent(AdvantageAirZoneEntity, SensorEntity):
def __init__(self, instance: AdvantageAirData, ac_key: str, zone_key: str) -> None:
"""Initialize an Advantage Air Zone Vent Sensor."""
super().__init__(instance, ac_key, zone_key=zone_key)
self._attr_name = f'{self._zone["name"]} vent'
self._attr_name = f"{self._zone['name']} vent"
self._attr_unique_id += "-vent"

@property
Expand Down Expand Up @@ -131,7 +131,7 @@ class AdvantageAirZoneSignal(AdvantageAirZoneEntity, SensorEntity):
def __init__(self, instance: AdvantageAirData, ac_key: str, zone_key: str) -> None:
"""Initialize an Advantage Air Zone wireless signal sensor."""
super().__init__(instance, ac_key, zone_key)
self._attr_name = f'{self._zone["name"]} signal'
self._attr_name = f"{self._zone['name']} signal"
self._attr_unique_id += "-signal"

@property
Expand Down Expand Up @@ -165,7 +165,7 @@ class AdvantageAirZoneTemp(AdvantageAirZoneEntity, SensorEntity):
def __init__(self, instance: AdvantageAirData, ac_key: str, zone_key: str) -> None:
"""Initialize an Advantage Air Zone Temp Sensor."""
super().__init__(instance, ac_key, zone_key)
self._attr_name = f'{self._zone["name"]} temperature'
self._attr_name = f"{self._zone['name']} temperature"
self._attr_unique_id += "-temp"

@property
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/airthings/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ def __init__(
self._id = airthings_device.device_id
self._attr_device_info = DeviceInfo(
configuration_url=(
"https://dashboard.airthings.com/devices/"
f"{airthings_device.device_id}"
f"https://dashboard.airthings.com/devices/{airthings_device.device_id}"
),
identifiers={(DOMAIN, airthings_device.device_id)},
name=airthings_device.name,
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/airvisual_pro/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class AirVisualProMeasurementDescription(SensorEntityDescription):
state_class=SensorStateClass.MEASUREMENT,
value_fn=lambda settings, status, measurements, history: int(
history.get(
f'Outdoor {"AQI(US)" if settings["is_aqi_usa"] else "AQI(CN)"}', -1
f"Outdoor {'AQI(US)' if settings['is_aqi_usa'] else 'AQI(CN)'}", -1
)
),
translation_key="outdoor_air_quality_index",
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/automation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,9 +636,9 @@ async def async_trigger(
alias = ""
if "trigger" in run_variables:
if "description" in run_variables["trigger"]:
reason = f' by {run_variables["trigger"]["description"]}'
reason = f" by {run_variables['trigger']['description']}"
if "alias" in run_variables["trigger"]:
alias = f' trigger \'{run_variables["trigger"]["alias"]}\''
alias = f" trigger '{run_variables['trigger']['alias']}'"
self._logger.debug("Automation%s triggered%s", alias, reason)

# Create a new context referring to the old context.
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/balboa/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, client: SpaClient, key: str) -> None:
"""Initialize the control."""
mac = client.mac_address
model = client.model
self._attr_unique_id = f'{model}-{key}-{mac.replace(":","")[-6:]}'
self._attr_unique_id = f"{model}-{key}-{mac.replace(':', '')[-6:]}"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, mac)},
name=model,
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/blueprint/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def _extract_blueprint_from_community_topic(
)

return ImportedBlueprint(
f'{post["username"]}/{topic["slug"]}', block_content, blueprint
f"{post['username']}/{topic['slug']}", block_content, blueprint
)


Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/bthome/logbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def async_describe_bthome_event(event: Event[BTHomeBleEvent]) -> dict[str, str]:
"""Describe bthome logbook event."""
data = event.data
device = dev_reg.async_get(data["device_id"])
name = device and device.name or f'BTHome {data["address"]}'
name = device and device.name or f"BTHome {data['address']}"
if properties := data["event_properties"]:
message = f"{data['event_class']} {data['event_type']}: {properties}"
else:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/compensation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def datapoints_greater_than_degree(value: dict) -> dict:
if len(value[CONF_DATAPOINTS]) <= value[CONF_DEGREE]:
raise vol.Invalid(
f"{CONF_DATAPOINTS} must have at least"
f" {value[CONF_DEGREE]+1} {CONF_DATAPOINTS}"
f" {value[CONF_DEGREE] + 1} {CONF_DATAPOINTS}"
)

return value
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/doods/image_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def _save_image(self, image, matches, paths):

# Draw detected objects
for instance in values:
box_label = f'{label} {instance["score"]:.1f}%'
box_label = f"{label} {instance['score']:.1f}%"
# Already scaled, use 1 for width and height
draw_box(
draw,
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/duke_energy/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ async def _async_update_data(self) -> None:
)
continue

id_prefix = f"{meter["serviceType"].lower()}_{serial_number}"
id_prefix = f"{meter['serviceType'].lower()}_{serial_number}"
consumption_statistic_id = f"{DOMAIN}:{id_prefix}_energy_consumption"
self._statistic_ids.add(consumption_statistic_id)
_LOGGER.debug(
Expand Down Expand Up @@ -136,7 +136,7 @@ async def _async_update_data(self) -> None:
)

name_prefix = (
f"Duke Energy " f"{meter["serviceType"].capitalize()} {serial_number}"
f"Duke Energy {meter['serviceType'].capitalize()} {serial_number}"
)
consumption_metadata = StatisticMetaData(
has_mean=False,
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/ecobee/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def remote_sensor_devices(self) -> list:
"""Return the remote sensor device name_by_user or name for the thermostat."""
return sorted(
[
f'{item["name_by_user"]} ({item["id"]})'
f"{item['name_by_user']} ({item['id']})"
for item in self.remote_sensor_ids_names
]
)
Expand Down Expand Up @@ -873,7 +873,7 @@ def set_sensors_used_in_climate(
translation_placeholders={
"options": ", ".join(
[
f'{item["name_by_user"]} ({item["id"]})'
f"{item['name_by_user']} ({item['id']})"
for item in self.remote_sensor_ids_names
]
)
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/ecobee/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, data: EcobeeData, thermostat_index: int) -> None:
"""Initialize the thermostat."""
super().__init__(data, thermostat_index)
self._attr_unique_id = (
f"{self.thermostat["identifier"]}_notify_{thermostat_index}"
f"{self.thermostat['identifier']}_notify_{thermostat_index}"
)

def send_message(self, message: str, title: str | None = None) -> None:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/flux_led/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def _async_migrator(entity_entry: er.RegistryEntry) -> dict[str, Any] | None:
and mac_matches_by_one(entity_mac, unique_id)
):
# Old format {dhcp_mac}....., New format {discovery_mac}....
new_unique_id = f"{unique_id}{entity_unique_id[len(unique_id):]}"
new_unique_id = f"{unique_id}{entity_unique_id[len(unique_id) :]}"
else:
return None
_LOGGER.debug(
Expand Down
8 changes: 4 additions & 4 deletions homeassistant/components/fronius/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ def __init__(
"unit"
)
self._attr_unique_id = (
f'{logger_data["unique_identifier"]["value"]}-{description.key}'
f"{logger_data['unique_identifier']['value']}-{description.key}"
)


Expand All @@ -815,7 +815,7 @@ def __init__(
if (meter_uid := meter_data["serial"]["value"]) == "n.a.":
meter_uid = (
f"{coordinator.solar_net.solar_net_device_id}:"
f'{meter_data["model"]["value"]}'
f"{meter_data['model']['value']}"
)

self._attr_device_info = DeviceInfo(
Expand Down Expand Up @@ -849,7 +849,7 @@ def __init__(
sw_version=device_data["software"]["value"],
via_device=(DOMAIN, coordinator.solar_net.solar_net_device_id),
)
self._attr_unique_id = f'{device_data["serial"]["value"]}-{description.key}'
self._attr_unique_id = f"{device_data['serial']['value']}-{description.key}"


class PowerFlowSensor(_FroniusSensorEntity):
Expand Down Expand Up @@ -883,7 +883,7 @@ def __init__(
super().__init__(coordinator, description, solar_net_id)
storage_data = self._device_data()

self._attr_unique_id = f'{storage_data["serial"]["value"]}-{description.key}'
self._attr_unique_id = f"{storage_data['serial']['value']}-{description.key}"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, storage_data["serial"]["value"])},
manufacturer=storage_data["manufacturer"]["value"],
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/harmony/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ async def connect(self) -> None:
except (ValueError, AttributeError) as err:
await self._client.close()
raise ConfigEntryNotReady(
f"{self.name}: Error {err} while connected HUB at:"
f" {self._address}:8088"
f"{self.name}: Error {err} while connected HUB at: {self._address}:8088"
) from err
if not connected:
await self._client.close()
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/hisense_aehw4a1/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ async def async_update(self) -> None:
fan_mode = status["wind_status"]
self._attr_fan_mode = AC_TO_HA_FAN_MODES[fan_mode]

swing_mode = f'{status["up_down"]}{status["left_right"]}'
swing_mode = f"{status['up_down']}{status['left_right']}"
self._attr_swing_mode = AC_TO_HA_SWING[swing_mode]

if self._attr_hvac_mode in (HVACMode.COOL, HVACMode.HEAT):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/hive/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, hive: Hive, hive_device: dict[str, Any]) -> None:
self.hive = hive
self.device = hive_device
self._attr_name = self.device["haName"]
self._attr_unique_id = f'{self.device["hiveID"]}-{self.device["hiveType"]}'
self._attr_unique_id = f"{self.device['hiveID']}-{self.device['hiveType']}"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, self.device["device_id"])},
model=self.device["deviceData"]["model"],
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/homekit/iidmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def get_or_allocate_iid(
char_hap_type: str | None = uuid_to_hap_type(char_uuid) if char_uuid else None
# Allocation key must be a string since we are saving it to JSON
allocation_key = (
f'{service_hap_type}_{service_unique_id or ""}_'
f'{char_hap_type or ""}_{char_unique_id or ""}'
f"{service_hap_type}_{service_unique_id or ''}_"
f"{char_hap_type or ''}_{char_unique_id or ''}"
)
# AID must be a string since JSON keys cannot be int
aid_str = str(aid)
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/homekit/type_triggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(
for idx, trigger in enumerate(device_triggers):
type_: str = trigger["type"]
subtype: str | None = trigger.get("subtype")
unique_id = f'{type_}-{subtype or ""}'
unique_id = f"{type_}-{subtype or ''}"
entity_id: str | None = None
if (entity_id_or_uuid := trigger.get("entity_id")) and (
entry := ent_reg.async_get(entity_id_or_uuid)
Expand Down Expand Up @@ -122,7 +122,7 @@ async def async_trigger(
"""
reason = ""
if "trigger" in run_variables and "description" in run_variables["trigger"]:
reason = f' by {run_variables["trigger"]["description"]}'
reason = f" by {run_variables['trigger']['description']}"
_LOGGER.debug("Button triggered%s - %s", reason, run_variables)
idx = int(run_variables["trigger"]["idx"])
self.triggers[idx].set_value(0)
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/homekit_controller/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,7 @@ async def async_setup(self) -> None:
self.hass,
self.async_update_available_state,
timedelta(seconds=BLE_AVAILABILITY_CHECK_INTERVAL),
name=f"HomeKit Device {self.unique_id} BLE availability "
"check poll",
name=f"HomeKit Device {self.unique_id} BLE availability check poll",
)
)
# BLE devices always get an RSSI sensor as well
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/ihc/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(
self.suggested_area = product.get("group")
if "id" in product:
product_id = product["id"]
self.device_id = f"{controller_id}_{product_id }"
self.device_id = f"{controller_id}_{product_id}"
# this will name the device the same way as the IHC visual application: Product name + position
self.device_name = product["name"]
if self.ihc_position:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/ista_ecotrend/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async def async_step_user(
else:
if TYPE_CHECKING:
assert info
title = f"{info["firstName"]} {info["lastName"]}".strip()
title = f"{info['firstName']} {info['lastName']}".strip()
await self.async_set_unique_id(info["activeConsumptionUnit"])
self._abort_if_unique_id_configured()
return self.async_create_entry(
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/isy994/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
def time_string(i: int) -> str:
"""Return a formatted ramp rate time string."""
if i >= 60:
return f"{(float(i)/60):.1f} {UnitOfTime.MINUTES}"
return f"{(float(i) / 60):.1f} {UnitOfTime.MINUTES}"
return f"{i} {UnitOfTime.SECONDS}"


Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/keymitt_ble/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def short_address(address: str) -> str:

def name_from_discovery(discovery: MicroBotAdvertisement) -> str:
"""Get the name from a discovery."""
return f'{discovery.data["local_name"]} {short_address(discovery.address)}'
return f"{discovery.data['local_name']} {short_address(discovery.address)}"


class MicroBotConfigFlow(ConfigFlow, domain=DOMAIN):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/knx/expose.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def __init__(
self._remove_listener: Callable[[], None] | None = None
self.device: ExposeSensor = ExposeSensor(
xknx=self.xknx,
name=f"{self.entity_id}__{self.expose_attribute or "state"}",
name=f"{self.entity_id}__{self.expose_attribute or 'state'}",
group_address=config[KNX_ADDRESS],
respond_to_read=config[CONF_RESPOND_TO_READ],
value_type=self.expose_type,
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/kostal_plenticore/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ async def async_setup(self) -> bool:
model=f"{prod1} {prod2}",
name=settings["scb:network"][hostname_id],
sw_version=(
f'IOC: {device_local["Properties:VersionIOC"]}'
f' MC: {device_local["Properties:VersionMC"]}'
f"IOC: {device_local['Properties:VersionIOC']}"
f" MC: {device_local['Properties:VersionMC']}"
),
)

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/lacrosse_view/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> list[Loca
raise InvalidAuth from error

if not locations:
raise NoLocations(f'No locations found for account {data["username"]}')
raise NoLocations(f"No locations found for account {data['username']}")

return locations

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/lcn/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ def get_resource(domain_name: str, domain_data: ConfigType) -> str:
if domain_name == "cover":
return cast(str, domain_data["motor"])
if domain_name == "climate":
return f'{domain_data["source"]}.{domain_data["setpoint"]}'
return f"{domain_data['source']}.{domain_data['setpoint']}"
if domain_name == "scene":
return f'{domain_data["register"]}.{domain_data["scene"]}'
return f"{domain_data['register']}.{domain_data['scene']}"
raise ValueError("Unknown domain")


Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/lektrico/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ async def _get_lektrico_device_settings_and_treat_unique_id(self) -> None:
self._serial_number = str(settings["serial_number"])
self._device_type = settings["type"]
self._board_revision = settings["board_revision"]
self._name = f"{settings["type"]}_{self._serial_number}"
self._name = f"{settings['type']}_{self._serial_number}"

# Check if already configured
# Set unique id
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/lg_thinq/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def on_message_received(
async def async_handle_device_event(self, message: dict) -> None:
"""Handle received mqtt message."""
unique_id = (
f"{message["deviceId"]}_{list(message["report"].keys())[0]}"
f"{message['deviceId']}_{list(message['report'].keys())[0]}"
if message["deviceType"] == DeviceType.WASHTOWER
else message["deviceId"]
)
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/lovelace/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ async def async_browse_media(
BrowseMedia(
title=view["title"],
media_class=MediaClass.APP,
media_content_id=f'{info["url_path"]}/{view["path"]}',
media_content_id=f"{info['url_path']}/{view['path']}",
media_content_type=DOMAIN,
thumbnail="https://brands.home-assistant.io/_/lovelace/logo.png",
can_play=True,
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/lutron_caseta/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def async_setup_entry(

# Append the child device name to the end of the parent keypad
# name to create the entity name
full_name = f'{parent_device_info.get("name")} {device_name}'
full_name = f"{parent_device_info.get('name')} {device_name}"
# Set the device_info to the same as the Parent Keypad
# The entities will be nested inside the keypad device
entities.append(
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/lutron_caseta/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(self, device, data):
parent_keypad = keypads[device["parent_device"]]
parent_device_info = parent_keypad["device_info"]
# Append the child device name to the end of the parent keypad name to create the entity name
self._attr_name = f'{parent_device_info["name"]} {device["device_name"]}'
self._attr_name = f"{parent_device_info['name']} {device['device_name']}"
# Set the device_info to the same as the Parent Keypad
# The entities will be nested inside the keypad device
self._attr_device_info = parent_device_info
Expand Down
Loading
Loading