Skip to content

Commit

Permalink
Fix RUFF warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus authored and Markus committed Nov 11, 2023
1 parent dfbf8b6 commit 29f35aa
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 25 deletions.
47 changes: 47 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# The contents of this file is based on https://github.com/home-assistant/core/blob/dev/pyproject.toml

target-version = "py311"

select = [
"B007", # Loop control variable {name} not used within loop body
"B014", # Exception handler with duplicate exception
"C", # complexity
"D", # docstrings
"E", # pycodestyle
"F", # pyflakes/autoflake
"ICN001", # import concentions; {name} should be imported as {asname}
"PGH004", # Use specific rule codes when using noqa
"PLC0414", # Useless import alias. Import alias does not rename original package.
"SIM105", # Use contextlib.suppress({exception}) instead of try-except-pass
"SIM117", # Merge with-statements that use the same scope
"SIM118", # Use {key} in {dict} instead of {key} in {dict}.keys()
"SIM201", # Use {left} != {right} instead of not {left} == {right}
"SIM212", # Use {a} if {a} else {b} instead of {b} if not {a} else {a}
"SIM300", # Yoda conditions. Use 'age == 42' instead of '42 == age'.
"SIM401", # Use get from dict with default instead of an if block
"T20", # flake8-print
"TRY004", # Prefer TypeError exception for invalid type
"RUF006", # Store a reference to the return value of asyncio.create_task
"UP", # pyupgrade
"W", # pycodestyle
]

ignore = [
"D202", # No blank lines allowed after function docstring
"D203", # 1 blank line required before class docstring
"D213", # Multi-line docstring summary should start at the second line
"D404", # First word of the docstring should not be This
"D406", # Section name should end with a newline
"D407", # Section name underlining
"D411", # Missing blank line before section
"E501", # line too long
"E731", # do not assign a lambda expression, use a def
# Ignored due to performance: https://github.com/charliermarsh/ruff/issues/2923
"UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)`
]

[flake8-pytest-style]
fixture-parentheses = false

[mccabe]
max-complexity = 25
3 changes: 0 additions & 3 deletions custom_components/unifi_voucher/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
from dataclasses import dataclass

from homeassistant.core import HomeAssistant
from homeassistant.const import (
CONF_HOST,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.components.button import (
ButtonDeviceClass,
Expand Down
14 changes: 6 additions & 8 deletions custom_components/unifi_voucher/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from __future__ import annotations

from homeassistant.core import (
callback,
HomeAssistant,
)
from homeassistant.config_entries import (
Expand Down Expand Up @@ -55,8 +54,8 @@ def __init__(self) -> None:
self.title: str | None = None
self.data: dict[str, any] | None = None
self.sites: dict[str, str] | None = None
self.reauth_config_entry: config_entries.ConfigEntry | None = None
self.reauth_schema: dict[vol.Marker, Any] = {}
self.reauth_config_entry: ConfigEntry | None = None
self.reauth_schema: dict[vol.Marker, any] = {}

async def async_step_user(
self,
Expand Down Expand Up @@ -110,18 +109,17 @@ async def async_step_user(
# Go to site selection, if user has access to more than one site
return await self.async_step_site()

if await _async_discover_unifi(
self.hass
):
DEFAULT_HOST = "unifi"
_default_host = DEFAULT_HOST
if await _async_discover_unifi(self.hass):
_default_host = "unifi"

return self.async_show_form(
step_id="user",
data_schema=vol.Schema(
{
vol.Required(
CONF_HOST,
default=(user_input or {}).get(CONF_HOST, DEFAULT_HOST),
default=(user_input or {}).get(CONF_HOST, _default_host),
): selector.TextSelector(
selector.TextSelectorConfig(
type=selector.TextSelectorType.TEXT
Expand Down
9 changes: 6 additions & 3 deletions custom_components/unifi_voucher/coordinator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""DataUpdateCoordinator for UniFi Hotspot Manager."""
from __future__ import annotations

import asyncio

from datetime import timedelta

from homeassistant.core import HomeAssistant
Expand All @@ -12,8 +14,12 @@
CONF_VERIFY_SSL,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.exceptions import (
ConfigEntryAuthFailed,
)
from homeassistant.helpers.update_coordinator import (
DataUpdateCoordinator,
UpdateFailed,
)
import homeassistant.util.dt as dt_util

Expand All @@ -22,8 +28,6 @@
LOGGER,
UPDATE_INTERVAL,
CONF_SITE_ID,
ATTR_AVAILABLE,
ATTR_LAST_PULL,
)
from .api import (
UnifiVoucherApiClient,
Expand All @@ -32,7 +36,6 @@
UnifiVoucherRemoveRequest,
UnifiVoucherApiAuthenticationError,
UnifiVoucherApiAccessError,
UnifiVoucherApiConnectionError,
UnifiVoucherApiError,
)

Expand Down
3 changes: 0 additions & 3 deletions custom_components/unifi_voucher/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@
ATTR_NAME,
ATTR_IDENTIFIERS,
ATTR_MANUFACTURER,
ATTR_STATE,
)
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.util import slugify

from .const import (
DOMAIN,
MANUFACTURER,
ATTR_EXTRA_STATE_ATTRIBUTES,
ATTR_AVAILABLE,
ATTR_LAST_PULL,
)
from .coordinator import UnifiVoucherCoordinator
Expand Down
8 changes: 0 additions & 8 deletions custom_components/unifi_voucher/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,10 @@
from __future__ import annotations

from homeassistant.core import HomeAssistant
from homeassistant.const import (
CONF_HOST,
REVOLUTIONS_PER_MINUTE,
UnitOfTemperature,
ATTR_TEMPERATURE,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.helpers.entity import Entity

Expand Down

0 comments on commit 29f35aa

Please sign in to comment.