Skip to content

Commit

Permalink
Bump ruff to 0.3.4 (home-assistant#112690)
Browse files Browse the repository at this point in the history
Co-authored-by: Sid <27780930+autinerd@users.noreply.github.com>
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Co-authored-by: J. Nick Koston <nick@koston.org>
  • Loading branch information
4 people authored Mar 25, 2024
1 parent 27219b6 commit 6bb4e7d
Show file tree
Hide file tree
Showing 1,044 changed files with 24,245 additions and 16,750 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.1
rev: v0.3.4
hooks:
- id: ruff
args:
Expand Down
6 changes: 2 additions & 4 deletions homeassistant/backports/functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,10 @@ def __set_name__(self, owner: type[Any], name: str) -> None:
)

@overload
def __get__(self, instance: None, owner: type[Any] | None = None) -> Self:
...
def __get__(self, instance: None, owner: type[Any] | None = None) -> Self: ...

@overload
def __get__(self, instance: Any, owner: type[Any] | None = None) -> _T:
...
def __get__(self, instance: Any, owner: type[Any] | None = None) -> _T: ...

def __get__(
self, instance: Any | None, owner: type[Any] | None = None
Expand Down
12 changes: 6 additions & 6 deletions homeassistant/components/airvisual/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ def _standardize_geography_config_entry(
# about, infer it from the data we have:
entry_updates["data"] = {**entry.data}
if CONF_CITY in entry.data:
entry_updates["data"][
CONF_INTEGRATION_TYPE
] = INTEGRATION_TYPE_GEOGRAPHY_NAME
entry_updates["data"][CONF_INTEGRATION_TYPE] = (
INTEGRATION_TYPE_GEOGRAPHY_NAME
)
else:
entry_updates["data"][
CONF_INTEGRATION_TYPE
] = INTEGRATION_TYPE_GEOGRAPHY_COORDS
entry_updates["data"][CONF_INTEGRATION_TYPE] = (
INTEGRATION_TYPE_GEOGRAPHY_COORDS
)

if not entry_updates:
return
Expand Down
7 changes: 4 additions & 3 deletions homeassistant/components/amcrest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,10 @@ async def async_stream_command(
self, *args: Any, **kwargs: Any
) -> AsyncIterator[httpx.Response]:
"""amcrest.ApiWrapper.command wrapper to catch errors."""
async with self._async_command_wrapper(), super().async_stream_command(
*args, **kwargs
) as ret:
async with (
self._async_command_wrapper(),
super().async_stream_command(*args, **kwargs) as ret,
):
yield ret

@asynccontextmanager
Expand Down
24 changes: 12 additions & 12 deletions homeassistant/components/amcrest/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,21 @@ async def async_update(self) -> None:
elif sensor_type == SENSOR_SDCARD:
storage = await self._api.async_storage_all
try:
self._attr_extra_state_attributes[
"Total"
] = f"{storage['total'][0]:.2f} {storage['total'][1]}"
self._attr_extra_state_attributes["Total"] = (
f"{storage['total'][0]:.2f} {storage['total'][1]}"
)
except ValueError:
self._attr_extra_state_attributes[
"Total"
] = f"{storage['total'][0]} {storage['total'][1]}"
self._attr_extra_state_attributes["Total"] = (
f"{storage['total'][0]} {storage['total'][1]}"
)
try:
self._attr_extra_state_attributes[
"Used"
] = f"{storage['used'][0]:.2f} {storage['used'][1]}"
self._attr_extra_state_attributes["Used"] = (
f"{storage['used'][0]:.2f} {storage['used'][1]}"
)
except ValueError:
self._attr_extra_state_attributes[
"Used"
] = f"{storage['used'][0]} {storage['used'][1]}"
self._attr_extra_state_attributes["Used"] = (
f"{storage['used'][0]} {storage['used'][1]}"
)
try:
self._attr_native_value = f"{storage['used_percent']:.2f}"
except ValueError:
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/apcupsd/diagnostics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Diagnostics support for APCUPSD."""

from __future__ import annotations

from typing import Any
Expand Down
16 changes: 8 additions & 8 deletions homeassistant/components/aranet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:

address = entry.unique_id
assert address is not None
coordinator = hass.data.setdefault(DOMAIN, {})[
entry.entry_id
] = PassiveBluetoothProcessorCoordinator(
hass,
_LOGGER,
address=address,
mode=BluetoothScanningMode.PASSIVE,
update_method=_service_info_to_adv,
coordinator = hass.data.setdefault(DOMAIN, {})[entry.entry_id] = (
PassiveBluetoothProcessorCoordinator(
hass,
_LOGGER,
address=address,
mode=BluetoothScanningMode.PASSIVE,
update_method=_service_info_to_adv,
)
)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
entry.async_on_unload(
Expand Down
12 changes: 6 additions & 6 deletions homeassistant/components/assist_pipeline/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,9 +754,9 @@ async def wake_word_detection(
raise DuplicateWakeUpDetectedError(result.wake_word_phrase)

# Record last wake up time to block duplicate detections
self.hass.data[DATA_LAST_WAKE_UP][
result.wake_word_phrase
] = time.monotonic()
self.hass.data[DATA_LAST_WAKE_UP][result.wake_word_phrase] = (
time.monotonic()
)

if result.queued_audio:
# Add audio that was pending at detection.
Expand Down Expand Up @@ -1375,9 +1375,9 @@ async def execute(self) -> None:
raise DuplicateWakeUpDetectedError(self.wake_word_phrase)

# Record last wake up time to block duplicate detections
self.run.hass.data[DATA_LAST_WAKE_UP][
self.wake_word_phrase
] = time.monotonic()
self.run.hass.data[DATA_LAST_WAKE_UP][self.wake_word_phrase] = (
time.monotonic()
)

stt_input_stream = stt_processed_stream

Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/asuswrt/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ def async_on_demand_update(self) -> None:
self._device = self._router.devices[self._device.mac]
self._attr_extra_state_attributes = {}
if self._device.last_activity:
self._attr_extra_state_attributes[
ATTR_LAST_TIME_REACHABLE
] = self._device.last_activity.isoformat(timespec="seconds")
self._attr_extra_state_attributes[ATTR_LAST_TIME_REACHABLE] = (
self._device.last_activity.isoformat(timespec="seconds")
)
self.async_write_ha_state()

async def async_added_to_hass(self) -> None:
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/august/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ def _update_from_data(self) -> None:
ATTR_BATTERY_LEVEL: self._detail.battery_level
}
if self._detail.keypad is not None:
self._attr_extra_state_attributes[
"keypad_battery_level"
] = self._detail.keypad.battery_level
self._attr_extra_state_attributes["keypad_battery_level"] = (
self._detail.keypad.battery_level
)

async def async_added_to_hass(self) -> None:
"""Restore ATTR_CHANGED_BY on startup since it is likely no longer in the activity log."""
Expand Down
7 changes: 4 additions & 3 deletions homeassistant/components/auth/indieauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ async def fetch_redirect_uris(hass: HomeAssistant, url: str) -> list[str]:
parser = LinkTagParser("redirect_uri")
chunks = 0
try:
async with aiohttp.ClientSession() as session, session.get(
url, timeout=5
) as resp:
async with (
aiohttp.ClientSession() as session,
session.get(url, timeout=5) as resp,
):
async for data in resp.content.iter_chunked(1024):
parser.feed(data.decode())
chunks += 1
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/awair/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ def _get_discovered_entries(self) -> dict[str, str]:
for flow in self._async_in_progress():
if flow["context"]["source"] == SOURCE_ZEROCONF:
info = flow["context"]["title_placeholders"]
entries[
flow["context"]["host"]
] = f"{info['model']} ({info['device_id']})"
entries[flow["context"]["host"]] = (
f"{info['model']} ({info['device_id']})"
)
return entries

async def async_step_local(
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/axis/hub/entity_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Central point to load entities for the different platforms.
"""

from __future__ import annotations

from functools import partial
Expand Down
16 changes: 8 additions & 8 deletions homeassistant/components/bluemaestro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
address = entry.unique_id
assert address is not None
data = BlueMaestroBluetoothDeviceData()
coordinator = hass.data.setdefault(DOMAIN, {})[
entry.entry_id
] = PassiveBluetoothProcessorCoordinator(
hass,
_LOGGER,
address=address,
mode=BluetoothScanningMode.PASSIVE,
update_method=data.update,
coordinator = hass.data.setdefault(DOMAIN, {})[entry.entry_id] = (
PassiveBluetoothProcessorCoordinator(
hass,
_LOGGER,
address=address,
mode=BluetoothScanningMode.PASSIVE,
update_method=data.update,
)
)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
entry.async_on_unload(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ class PassiveBluetoothDataUpdate(Generic[_T]):
"""Generic bluetooth data."""

devices: dict[str | None, DeviceInfo] = dataclasses.field(default_factory=dict)
entity_descriptions: dict[
PassiveBluetoothEntityKey, EntityDescription
] = dataclasses.field(default_factory=dict)
entity_descriptions: dict[PassiveBluetoothEntityKey, EntityDescription] = (
dataclasses.field(default_factory=dict)
)
entity_names: dict[PassiveBluetoothEntityKey, str | None] = dataclasses.field(
default_factory=dict
)
Expand Down
16 changes: 8 additions & 8 deletions homeassistant/components/bluetooth/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ def async_load_history_from_system(
not (existing_all := connectable_loaded_history.get(address))
or history.advertisement_data.rssi > existing_all.rssi
):
connectable_loaded_history[address] = all_loaded_history[
address
] = BluetoothServiceInfoBleak.from_device_and_advertisement_data(
history.device,
history.advertisement_data,
history.source,
now_monotonic,
True,
connectable_loaded_history[address] = all_loaded_history[address] = (
BluetoothServiceInfoBleak.from_device_and_advertisement_data(
history.device,
history.advertisement_data,
history.source,
now_monotonic,
True,
)
)

# Restore remote adapters
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/bmw_connected_drive/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def _handle_coordinator_update(self) -> None:
LockState.LOCKED,
LockState.SECURED,
}
self._attr_extra_state_attributes[
"door_lock_state"
] = self.vehicle.doors_and_windows.door_lock_state.value
self._attr_extra_state_attributes["door_lock_state"] = (
self.vehicle.doors_and_windows.door_lock_state.value
)

super()._handle_coordinator_update()
6 changes: 3 additions & 3 deletions homeassistant/components/bosch_shc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ async def stop_polling(event):
await hass.async_add_executor_job(session.stop_polling)

await hass.async_add_executor_job(session.start_polling)
hass.data[DOMAIN][entry.entry_id][
DATA_POLLING_HANDLER
] = hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, stop_polling)
hass.data[DOMAIN][entry.entry_id][DATA_POLLING_HANDLER] = (
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, stop_polling)
)

return True

Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/brottsplatskartan/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def update(self) -> None:
"""Update device state."""

incident_counts: defaultdict[str, int] = defaultdict(int)
get_incidents: dict[str, list] | Literal[
False
] = self._brottsplatskartan.get_incidents()
get_incidents: dict[str, list] | Literal[False] = (
self._brottsplatskartan.get_incidents()
)

if get_incidents is False:
LOGGER.debug("Problems fetching incidents")
Expand Down
30 changes: 16 additions & 14 deletions homeassistant/components/bthome/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,22 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
data = BTHomeBluetoothDeviceData(**kwargs)

device_registry = async_get(hass)
coordinator = hass.data.setdefault(DOMAIN, {})[
entry.entry_id
] = BTHomePassiveBluetoothProcessorCoordinator(
hass,
_LOGGER,
address=address,
mode=BluetoothScanningMode.PASSIVE,
update_method=lambda service_info: process_service_info(
hass, entry, data, service_info, device_registry
),
device_data=data,
discovered_event_classes=set(entry.data.get(CONF_DISCOVERED_EVENT_CLASSES, [])),
connectable=False,
entry=entry,
coordinator = hass.data.setdefault(DOMAIN, {})[entry.entry_id] = (
BTHomePassiveBluetoothProcessorCoordinator(
hass,
_LOGGER,
address=address,
mode=BluetoothScanningMode.PASSIVE,
update_method=lambda service_info: process_service_info(
hass, entry, data, service_info, device_registry
),
device_data=data,
discovered_event_classes=set(
entry.data.get(CONF_DISCOVERED_EVENT_CLASSES, [])
),
connectable=False,
entry=entry,
)
)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/canary/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def _update_data(self) -> CanaryData:

for device in location.devices:
if device.is_online:
readings_by_device_id[
device.device_id
] = self.canary.get_latest_readings(device.device_id)
readings_by_device_id[device.device_id] = (
self.canary.get_latest_readings(device.device_id)
)

return {
"locations": locations_by_id,
Expand Down
12 changes: 6 additions & 6 deletions homeassistant/components/climate/device_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ async def async_attach_trigger(
}

if trigger_type == "current_temperature_changed":
numeric_state_config[
numeric_state_trigger.CONF_VALUE_TEMPLATE
] = "{{ state.attributes.current_temperature }}"
numeric_state_config[numeric_state_trigger.CONF_VALUE_TEMPLATE] = (
"{{ state.attributes.current_temperature }}"
)
else: # trigger_type == "current_humidity_changed"
numeric_state_config[
numeric_state_trigger.CONF_VALUE_TEMPLATE
] = "{{ state.attributes.current_humidity }}"
numeric_state_config[numeric_state_trigger.CONF_VALUE_TEMPLATE] = (
"{{ state.attributes.current_humidity }}"
)

if CONF_ABOVE in config:
numeric_state_config[CONF_ABOVE] = config[CONF_ABOVE]
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/co2signal/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class CO2SensorEntityDescription(SensorEntityDescription):

# For backwards compat, allow description to override unique ID key to use
unique_id: str | None = None
unit_of_measurement_fn: Callable[
[CarbonIntensityResponse], str | None
] | None = None
unit_of_measurement_fn: Callable[[CarbonIntensityResponse], str | None] | None = (
None
)
value_fn: Callable[[CarbonIntensityResponse], float | None]


Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/daikin/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ async def _set(self, settings: dict[str, Any]) -> None:
# temperature
elif attr == ATTR_TEMPERATURE:
try:
values[
HA_ATTR_TO_DAIKIN[ATTR_TARGET_TEMPERATURE]
] = format_target_temperature(value)
values[HA_ATTR_TO_DAIKIN[ATTR_TARGET_TEMPERATURE]] = (
format_target_temperature(value)
)
except ValueError:
_LOGGER.error("Invalid temperature %s", value)

Expand Down
Loading

0 comments on commit 6bb4e7d

Please sign in to comment.