From 44c4f20ee4594dbab04e5a38089fc3121bf71f5d Mon Sep 17 00:00:00 2001 From: Amos Yuen Date: Wed, 1 Jan 2025 04:19:13 +0000 Subject: [PATCH] Use isort instead of reorder-python-imports because of incompatibility with black --- .pre-commit-config.yaml | 7 +++---- custom_components/tplink_deco/__init__.py | 13 +++++++------ custom_components/tplink_deco/api.py | 8 ++++---- custom_components/tplink_deco/config_flow.py | 9 ++++----- custom_components/tplink_deco/const.py | 1 + custom_components/tplink_deco/coordinator.py | 7 ++++--- custom_components/tplink_deco/device.py | 1 + custom_components/tplink_deco/device_tracker.py | 7 +++---- custom_components/tplink_deco/sensor.py | 7 +++---- requirements.txt | 2 +- setup.cfg | 4 ++-- 11 files changed, 33 insertions(+), 33 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 511f9f0..296b1b5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -20,12 +20,11 @@ repos: language: system types: [python] require_serial: true - - id: reorder-python-imports - name: Reorder python imports - entry: reorder-python-imports + - id: isort + name: ISort + entry: isort language: system types: [python] - args: [--application-directories=custom_components] - repo: https://github.com/pre-commit/mirrors-prettier rev: v2.2.1 hooks: diff --git a/custom_components/tplink_deco/__init__.py b/custom_components/tplink_deco/__init__.py index 53a76bb..1582fff 100644 --- a/custom_components/tplink_deco/__init__.py +++ b/custom_components/tplink_deco/__init__.py @@ -4,19 +4,18 @@ For more details about this integration, please refer to https://github.com/amosyuen/ha-tplink-deco """ + import asyncio -import logging from datetime import timedelta +import logging from typing import Any from typing import cast -import homeassistant.helpers.config_validation as cv -import voluptuous as vol -from homeassistant.components.device_tracker.const import CONF_CONSIDER_HOME -from homeassistant.components.device_tracker.const import CONF_SCAN_INTERVAL from homeassistant.components.device_tracker.const import ( DOMAIN as DEVICE_TRACKER_DOMAIN, ) +from homeassistant.components.device_tracker.const import CONF_CONSIDER_HOME +from homeassistant.components.device_tracker.const import CONF_SCAN_INTERVAL from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_DEVICE_ID from homeassistant.const import CONF_HOST @@ -28,6 +27,8 @@ from homeassistant.helpers import entity_registry from homeassistant.helpers import restore_state from homeassistant.helpers.aiohttp_client import async_get_clientsession +import homeassistant.helpers.config_validation as cv +import voluptuous as vol from .api import TplinkDecoApi from .const import ATTR_DEVICE_TYPE @@ -51,8 +52,8 @@ from .const import SERVICE_REBOOT_DECO from .coordinator import TpLinkDeco from .coordinator import TpLinkDecoClient -from .coordinator import TplinkDecoClientUpdateCoordinator from .coordinator import TpLinkDecoData +from .coordinator import TplinkDecoClientUpdateCoordinator from .coordinator import TplinkDecoUpdateCoordinator _LOGGER: logging.Logger = logging.getLogger(__name__) diff --git a/custom_components/tplink_deco/api.py b/custom_components/tplink_deco/api.py index beb79f5..716ced3 100644 --- a/custom_components/tplink_deco/api.py +++ b/custom_components/tplink_deco/api.py @@ -10,16 +10,16 @@ from typing import Any from urllib.parse import quote_plus +from Crypto.Cipher import PKCS1_v1_5 +from Crypto.PublicKey import RSA import aiohttp -import async_timeout from aiohttp.hdrs import CONTENT_TYPE from aiohttp.hdrs import COOKIE from aiohttp.hdrs import SET_COOKIE -from Crypto.Cipher import PKCS1_v1_5 -from Crypto.PublicKey import RSA +import async_timeout from cryptography.hazmat.primitives import padding -from cryptography.hazmat.primitives.ciphers import algorithms from cryptography.hazmat.primitives.ciphers import Cipher +from cryptography.hazmat.primitives.ciphers import algorithms from cryptography.hazmat.primitives.ciphers import modes from .const import DEFAULT_TIMEOUT_ERROR_RETRIES diff --git a/custom_components/tplink_deco/config_flow.py b/custom_components/tplink_deco/config_flow.py index 824c532..19713c7 100644 --- a/custom_components/tplink_deco/config_flow.py +++ b/custom_components/tplink_deco/config_flow.py @@ -1,22 +1,21 @@ """Adds config flow for TP-Link Deco.""" + import asyncio import logging from typing import Any -import voluptuous as vol from homeassistant import config_entries from homeassistant.components.device_tracker.const import CONF_CONSIDER_HOME from homeassistant.components.device_tracker.const import CONF_SCAN_INTERVAL from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_HOST -from homeassistant.const import ( - CONF_PASSWORD, -) +from homeassistant.const import CONF_PASSWORD from homeassistant.const import CONF_USERNAME -from homeassistant.core import callback from homeassistant.core import HomeAssistant +from homeassistant.core import callback from homeassistant.exceptions import ConfigEntryAuthFailed from homeassistant.exceptions import ConfigEntryNotReady +import voluptuous as vol from .__init__ import async_create_and_refresh_coordinators from .const import CONF_CLIENT_POSTFIX diff --git a/custom_components/tplink_deco/const.py b/custom_components/tplink_deco/const.py index 92dfc21..d91f4a6 100644 --- a/custom_components/tplink_deco/const.py +++ b/custom_components/tplink_deco/const.py @@ -1,4 +1,5 @@ """Constants for TP-Link Deco.""" + from homeassistant.components.device_tracker import DOMAIN as DEVICE_TRACKER_DOMAIN from homeassistant.components.device_tracker.const import ( DEFAULT_CONSIDER_HOME as DEFAULT_CONSIDER_HOME_SPAN, diff --git a/custom_components/tplink_deco/coordinator.py b/custom_components/tplink_deco/coordinator.py index 81a66c0..ad2e7a4 100644 --- a/custom_components/tplink_deco/coordinator.py +++ b/custom_components/tplink_deco/coordinator.py @@ -1,15 +1,16 @@ """TP-Link Deco Coordinator""" + import asyncio -import ipaddress -import logging from collections.abc import Callable from datetime import datetime from datetime import timedelta +import ipaddress +import logging from typing import Any -from homeassistant.core import callback from homeassistant.core import CALLBACK_TYPE from homeassistant.core import HomeAssistant +from homeassistant.core import callback from homeassistant.exceptions import ConfigEntryAuthFailed from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.update_coordinator import DataUpdateCoordinator diff --git a/custom_components/tplink_deco/device.py b/custom_components/tplink_deco/device.py index 851cedc..18692d4 100644 --- a/custom_components/tplink_deco/device.py +++ b/custom_components/tplink_deco/device.py @@ -1,4 +1,5 @@ """TP-Link Deco.""" + from homeassistant.const import ATTR_VIA_DEVICE from homeassistant.helpers.entity import DeviceInfo diff --git a/custom_components/tplink_deco/device_tracker.py b/custom_components/tplink_deco/device_tracker.py index bea0e1b..c87f456 100644 --- a/custom_components/tplink_deco/device_tracker.py +++ b/custom_components/tplink_deco/device_tracker.py @@ -1,4 +1,5 @@ """TP-Link Deco.""" + import logging from typing import Any @@ -8,8 +9,8 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_HW_VERSION from homeassistant.const import ATTR_SW_VERSION -from homeassistant.core import callback from homeassistant.core import HomeAssistant +from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.restore_state import RestoreEntity @@ -33,9 +34,7 @@ from .const import CONF_CLIENT_PREFIX from .const import CONF_DECO_POSTFIX from .const import CONF_DECO_PREFIX -from .const import ( - COORDINATOR_CLIENTS_KEY, -) +from .const import COORDINATOR_CLIENTS_KEY from .const import COORDINATOR_DECOS_KEY from .const import DEVICE_TYPE_CLIENT from .const import DEVICE_TYPE_DECO diff --git a/custom_components/tplink_deco/sensor.py b/custom_components/tplink_deco/sensor.py index d52daf3..d7133ab 100644 --- a/custom_components/tplink_deco/sensor.py +++ b/custom_components/tplink_deco/sensor.py @@ -1,4 +1,5 @@ """TP-Link Deco.""" + import logging from homeassistant.components.sensor import SensorEntity @@ -6,15 +7,13 @@ from homeassistant.components.sensor.const import SensorStateClass from homeassistant.config_entries import ConfigEntry from homeassistant.const import UnitOfDataRate -from homeassistant.core import callback from homeassistant.core import HomeAssistant +from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.update_coordinator import CoordinatorEntity -from .const import ( - COORDINATOR_CLIENTS_KEY, -) +from .const import COORDINATOR_CLIENTS_KEY from .const import COORDINATOR_DECOS_KEY from .const import DOMAIN from .const import SIGNAL_DECO_ADDED diff --git a/requirements.txt b/requirements.txt index b65732f..088ede7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ black==24.10.0 colorlog==6.9.0 flake8==7.1.1 homeassistant==2023.6.0 +isort==5.13.2 pip>=21.0,<24.4 pre-commit==4.0.1 -reorder-python-imports==3.14.0 ruff==0.8.4 diff --git a/setup.cfg b/setup.cfg index dcd270f..711effb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -20,6 +20,8 @@ ignore = # https://github.com/timothycrosley/isort/wiki/isort-Settings # splits long import on multiple lines indented by 4 spaces multi_line_output = 3 +profile=black +force_single_line=True include_trailing_comma=True force_grid_wrap=0 use_parentheses=True @@ -29,8 +31,6 @@ indent = " " not_skip = __init__.py # will group `import x` and `from x import` of the same module. force_sort_within_sections = true -sections = FUTURE,STDLIB,INBETWEENS,THIRDPARTY,FIRSTPARTY,LOCALFOLDER -default_section = THIRDPARTY known_first_party = custom_components.tplink_deco combine_as_imports = true