Skip to content

Commit

Permalink
Enable Ruff D212 (home-assistant#87347)
Browse files Browse the repository at this point in the history
  • Loading branch information
frenck authored Feb 3, 2023
1 parent 97de0c6 commit ca1a128
Show file tree
Hide file tree
Showing 237 changed files with 353 additions and 707 deletions.
3 changes: 1 addition & 2 deletions docs/source/_ext/edit_on_github.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
Sphinx extension for ReadTheDocs-style "Edit on GitHub" links on the sidebar.
"""Sphinx extension for ReadTheDocs-style "Edit on GitHub" links on the sidebar.
Loosely based on https://github.com/astropy/astropy/pull/347
"""
Expand Down
6 changes: 2 additions & 4 deletions homeassistant/auth/providers/legacy_api_password.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
Support Legacy API password auth provider.
"""Support Legacy API password auth provider.
It will be removed when auth system production ready
"""
Expand Down Expand Up @@ -71,8 +70,7 @@ async def async_get_or_create_credentials(
async def async_user_meta_for_credentials(
self, credentials: Credentials
) -> UserMeta:
"""
Return info for the user.
"""Return info for the user.
Will be used to populate info when creating a new user.
"""
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/backports/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ def __str__(self) -> str:
def _generate_next_value_(
name: str, start: int, count: int, last_values: list[Any]
) -> Any:
"""
Make `auto()` explicitly unsupported.
"""Make `auto()` explicitly unsupported.
We may revisit this when it's very clear that Python 3.11's
`StrEnum.auto()` behavior will no longer change.
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
This package contains components that can be plugged into Home Assistant.
"""This package contains components that can be plugged into Home Assistant.
Component design guidelines:
- Each component defines a constant DOMAIN that is equal to its filename.
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/airly/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@


def set_update_interval(instances_count: int, requests_remaining: int) -> timedelta:
"""
Return data update interval.
"""Return data update interval.
The number of requests is reset at midnight UTC so we calculate the update
interval based on number of minutes until midnight, the number of Airly instances
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/airnow/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@


async def validate_input(hass: core.HomeAssistant, data):
"""
Validate the user input allows us to connect.
"""Validate the user input allows us to connect.
Data has the keys from DATA_SCHEMA with values provided by the user.
"""
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/alexa/intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ def async_setup(hass):


async def async_setup_intents(hass):
"""
Do intents setup.
"""Do intents setup.
Right now this module does not expose any, but the intent component breaks
without it.
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/apple_tv/browse_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ def build_app_list(app_list: dict[str, str]) -> BrowseMedia:


def item_payload(item: dict[str, Any]) -> BrowseMedia:
"""
Create response payload for a single media item.
"""Create response payload for a single media item.
Used by async_browse_media.
"""
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/automation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ def __call__(self, variables: Mapping[str, Any] | None = None) -> bool:

@bind_hass
def is_on(hass: HomeAssistant, entity_id: str) -> bool:
"""
Return true if specified automation entity_id is on.
"""Return true if specified automation entity_id is on.
Async friendly.
"""
Expand Down
12 changes: 4 additions & 8 deletions homeassistant/components/bayesian/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,7 @@ def __init__(
}

async def async_added_to_hass(self) -> None:
"""
Call when entity about to be added.
"""Call when entity about to be added.
All relevant update logic for instance attributes occurs within this closure.
Other methods in this class are designed to avoid directly modifying instance
Expand All @@ -233,8 +232,7 @@ async def async_added_to_hass(self) -> None:

@callback
def async_threshold_sensor_state_listener(event: Event) -> None:
"""
Handle sensor state changes.
"""Handle sensor state changes.
When a state changes, we must update our list of current observations,
then calculate the new probability.
Expand Down Expand Up @@ -384,8 +382,7 @@ def _calculate_new_probability(self) -> float:
return prior

def _build_observations_by_entity(self) -> dict[str, list[Observation]]:
"""
Build and return data structure of the form below.
"""Build and return data structure of the form below.
{
"sensor.sensor1": [Observation, Observation],
Expand Down Expand Up @@ -414,8 +411,7 @@ def _build_observations_by_entity(self) -> dict[str, list[Observation]]:
return observations_by_entity

def _build_observations_by_template(self) -> dict[Template, list[Observation]]:
"""
Build and return data structure of the form below.
"""Build and return data structure of the form below.
{
"template": [Observation, Observation],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
class ActiveBluetoothDataUpdateCoordinator(
PassiveBluetoothDataUpdateCoordinator, Generic[_T]
):
"""
A coordinator that receives passive data from advertisements but can also poll.
"""A coordinator that receives passive data from advertisements but can also poll.
Unlike the passive processor coordinator, this coordinator does call a parser
method to parse the data from the advertisement.
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/bluetooth_tracker/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ async def see_device(


async def get_tracking_devices(hass: HomeAssistant) -> tuple[set[str], set[str]]:
"""
Load all known devices.
"""Load all known devices.
We just need the devices so set consider_home and home range to 0
"""
Expand Down
12 changes: 4 additions & 8 deletions homeassistant/components/brunt/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ async def async_setup_entry(
class BruntDevice(
CoordinatorEntity[DataUpdateCoordinator[dict[str | None, Thing]]], CoverEntity
):
"""
Representation of a Brunt cover device.
"""Representation of a Brunt cover device.
Contains the common logic for all Brunt devices.
"""
Expand Down Expand Up @@ -105,17 +104,15 @@ async def async_added_to_hass(self) -> None:

@property
def current_cover_position(self) -> int | None:
"""
Return current position of cover.
"""Return current position of cover.
None is unknown, 0 is closed, 100 is fully open.
"""
return self.coordinator.data[self.unique_id].current_position

@property
def request_cover_position(self) -> int | None:
"""
Return request position of cover.
"""Return request position of cover.
The request position is the position of the last request
to Brunt, at times there is a diff of 1 to current
Expand All @@ -125,8 +122,7 @@ def request_cover_position(self) -> int | None:

@property
def move_state(self) -> int | None:
"""
Return current moving state of cover.
"""Return current moving state of cover.
None is unknown, 0 when stopped, 1 when opening, 2 when closing
"""
Expand Down
9 changes: 3 additions & 6 deletions homeassistant/components/buienradar/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ async def async_setup_entry(


class BuienradarCam(Camera):
"""
A camera component producing animated buienradar radar-imagery GIFs.
"""A camera component producing animated buienradar radar-imagery GIFs.
Rain radar imagery camera based on image URL taken from [0].
Expand All @@ -62,8 +61,7 @@ class BuienradarCam(Camera):
def __init__(
self, latitude: float, longitude: float, delta: float, country: str
) -> None:
"""
Initialize the component.
"""Initialize the component.
This constructor must be run in the event loop.
"""
Expand Down Expand Up @@ -145,8 +143,7 @@ async def __retrieve_radar_image(self) -> bool:
async def async_camera_image(
self, width: int | None = None, height: int | None = None
) -> bytes | None:
"""
Return a still image response from the camera.
"""Return a still image response from the camera.
Uses asyncio conditions to make sure only one task enters the critical
section at the same time. Otherwise, two http requests would start
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/camera/img_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ def scale_jpeg_camera_image(cam_image: Image, width: int, height: int) -> bytes:


class TurboJPEGSingleton:
"""
Load TurboJPEG only once.
"""Load TurboJPEG only once.
Ensures we do not log load failures each snapshot
since camera image fetches happen every few
Expand Down
6 changes: 2 additions & 4 deletions homeassistant/components/cast/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,7 @@ def multizone_new_media_status(self, group_uuid, media_status):

# ========== Service Calls ==========
def _media_controller(self):
"""
Return media controller.
"""Return media controller.
First try from our own cast, then groups which our cast is a member in.
"""
Expand Down Expand Up @@ -753,8 +752,7 @@ async def async_play_media(
)

def _media_status(self):
"""
Return media status.
"""Return media status.
First try from our own cast, then groups which our cast is a member in.
"""
Expand Down
6 changes: 2 additions & 4 deletions homeassistant/components/cisco_ios/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ def scan_devices(self):
return self.last_results

def _update_info(self):
"""
Ensure the information from the Cisco router is up to date.
"""Ensure the information from the Cisco router is up to date.
Returns boolean if scanning successful.
"""
Expand Down Expand Up @@ -139,8 +138,7 @@ def _get_arp_data(self):


def _parse_cisco_mac_address(cisco_hardware_addr):
"""
Parse a Cisco formatted HW address to normal MAC.
"""Parse a Cisco formatted HW address to normal MAC.
e.g. convert
001d.ec02.07ab
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ def get_device_name(self, device):
return name

def get_extra_attributes(self, device):
"""
Get extra attributes of a device.
"""Get extra attributes of a device.
Some known extra attributes that may be returned in the device tuple
include SSID, PT (eg 802.11ac), devtype (eg iPhone 7) among others.
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/cloud/repairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ def async_manage_legacy_subscription_issue(
hass: HomeAssistant,
subscription_info: dict[str, Any],
) -> None:
"""
Manage the legacy subscription issue.
"""Manage the legacy subscription issue.
If the provider is "legacy" create an issue,
in all other cases remove the issue.
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/configurator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
Support to allow pieces of code to request configuration from the user.
"""Support to allow pieces of code to request configuration from the user.
Initiate a request by calling the `request_config` method with a callback.
This will return a request id that has to be used for future calls.
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/crownstone/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ def __init__(self, device: Crownstone) -> None:

@property
def cloud_id(self) -> str:
"""
Return the unique identifier for this device.
"""Return the unique identifier for this device.
Used as device ID and to generate unique entity ID's.
"""
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/crownstone/entry_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry) -> None:
self.usb_sphere_id: str | None = None

async def async_setup(self) -> bool:
"""
Set up a Crownstone config entry.
"""Set up a Crownstone config entry.
Returns True if the setup was successful.
"""
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/crownstone/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
def list_ports_as_str(
serial_ports: list[ListPortInfo], no_usb_option: bool = True
) -> list[str]:
"""
Represent currently available serial ports as string.
"""Represent currently available serial ports as string.
Adds option to not use usb on top of the list,
option to use manual path or refresh list at the end.
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/crownstone/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ def hass_to_crownstone_state(value: int) -> int:


class CrownstoneEntity(CrownstoneBaseEntity, LightEntity):
"""
Representation of a crownstone.
"""Representation of a crownstone.
Light platform is used to support dimming.
"""
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/crownstone/listeners.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
Listeners for updating data in the Crownstone integration.
"""Listeners for updating data in the Crownstone integration.
For data updates, Cloud Push is used in form of an SSE server that sends out events.
For fast device switching Local Push is used in form of a USB dongle that hooks into a BLE mesh.
Expand Down
9 changes: 3 additions & 6 deletions homeassistant/components/darksky/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,7 @@ def update(self) -> None:
self._attr_native_value = self.get_state(currently)

def get_state(self, data):
"""
Return a new state based on the type.
"""Return a new state based on the type.
If the sensor type is unknown, the current state is returned.
"""
Expand Down Expand Up @@ -827,8 +826,7 @@ def update(self) -> None:
self._attr_native_value = self.get_state(alerts)

def get_state(self, data):
"""
Return a new state based on the type.
"""Return a new state based on the type.
If the sensor type is unknown, the current state is returned.
"""
Expand All @@ -851,8 +849,7 @@ def get_state(self, data):


def convert_to_camel(data):
"""
Convert snake case (foo_bar_bat) to camel case (fooBarBat).
"""Convert snake case (foo_bar_bat) to camel case (fooBarBat).
This is not pythonic, but needed for certain situations.
"""
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/denonavr/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ async def async_setup_entry(
def async_log_errors(
func: Callable[Concatenate[_DenonDeviceT, _P], Awaitable[_R]],
) -> Callable[Concatenate[_DenonDeviceT, _P], Coroutine[Any, Any, _R | None]]:
"""
Log errors occurred when calling a Denon AVR receiver.
"""Log errors occurred when calling a Denon AVR receiver.
Decorates methods of DenonDevice class.
Declaration of staticmethod for this method is at the end of this class.
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/doorbird/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,7 @@ def webhook_is_registered(self, url, favs=None) -> bool:
return self.get_webhook_id(url, favs) is not None

def get_webhook_id(self, url, favs=None) -> str | None:
"""
Return the device favorite ID for the given URL.
"""Return the device favorite ID for the given URL.
The favorite must exist or there will be problems.
"""
Expand Down
Loading

0 comments on commit ca1a128

Please sign in to comment.