From c8060fce0dde3db12c2dbc10f7e4f275bb20f202 Mon Sep 17 00:00:00 2001 From: Teemu R Date: Sun, 27 Oct 2019 21:07:29 +0100 Subject: [PATCH] add azure pipeline for tests, and enforce black, flake8 and isort for commits (#566) * use azure pipeline instead of travis [skip ci] * add flake8, isort to precommit hooks, format files * remove unnecessary .hound.yml, adjust line lengths and disable mypy temporarily * try 88 instead of 100 for max line length. * miio.discover has to be defined separately to have access to all devices * adjust manifest, add pytest-cov * second try for cov report --- .flake8.ini | 6 --- .hound.yml | 3 -- .pre-commit-config.yaml | 16 ++++++ MANIFEST.in | 3 +- azure-pipelines.yml | 47 +++++++++++++++++ miio/__init__.py | 24 +++++---- miio/airconditioningcompanion.py | 2 +- miio/airdehumidifier.py | 4 +- miio/airfresh.py | 2 +- miio/airhumidifier.py | 4 +- miio/airpurifier.py | 2 +- miio/airqualitymonitor.py | 17 +++--- miio/alarmclock.py | 3 +- miio/aqaracamera.py | 4 +- miio/chuangmi_ir.py | 18 +++---- miio/chuangmi_plug.py | 2 +- miio/cli.py | 2 +- miio/click_common.py | 22 ++++---- miio/cooker.py | 2 +- miio/device.py | 4 +- miio/discovery.py | 58 ++++++++++----------- miio/extract_tokens.py | 4 +- miio/fan.py | 2 +- miio/philips_moonlight.py | 2 +- miio/powerstrip.py | 4 +- miio/protocol.py | 17 +++--- miio/pwzn_relay.py | 2 +- miio/tests/test_airconditioningcompanion.py | 14 ++--- miio/tests/test_airdehumidifier.py | 11 ++-- miio/tests/test_airfresh.py | 7 +-- miio/tests/test_airhumidifier.py | 13 ++--- miio/tests/test_airpurifier.py | 9 ++-- miio/tests/test_airqualitymonitor.py | 12 +++-- miio/tests/test_ceil.py | 3 +- miio/tests/test_chuangmi_ir.py | 1 + miio/tests/test_chuangmi_plug.py | 5 +- miio/tests/test_click_common.py | 2 +- miio/tests/test_fan.py | 17 +++--- miio/tests/test_philips_bulb.py | 3 +- miio/tests/test_philips_eyecare.py | 3 +- miio/tests/test_philips_moonlight.py | 3 +- miio/tests/test_powerstrip.py | 7 +-- miio/tests/test_toiletlid.py | 6 ++- miio/tests/test_vacuum.py | 1 + miio/tests/test_waterpurifier.py | 1 + miio/tests/test_yeelight.py | 3 +- miio/toiletlid.py | 2 +- miio/updater.py | 5 +- miio/utils.py | 2 +- miio/vacuum.py | 14 ++--- miio/vacuum_cli.py | 5 +- miio/vacuumcontainers.py | 4 +- miio/waterpurifier.py | 1 - miio/yeelight.py | 5 +- setup.py | 3 +- tox.ini | 27 +++++++++- 56 files changed, 283 insertions(+), 182 deletions(-) delete mode 100644 .flake8.ini delete mode 100644 .hound.yml create mode 100644 azure-pipelines.yml diff --git a/.flake8.ini b/.flake8.ini deleted file mode 100644 index 4599cfcc8..000000000 --- a/.flake8.ini +++ /dev/null @@ -1,6 +0,0 @@ -[flake8] -exclude = .git,.tox,__pycache__ -max-line-length = 100 -select = C,E,F,W,B,B950 -ignore = E501,W503,E203 - diff --git a/.hound.yml b/.hound.yml deleted file mode 100644 index 0b5196624..000000000 --- a/.hound.yml +++ /dev/null @@ -1,3 +0,0 @@ -python: - enabled: true - config_file: .flake8.ini diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index da9057788..7c1aac7b1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,3 +4,19 @@ repos: hooks: - id: black language_version: python3 + +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.3.0 + hooks: + - id: flake8 + +- repo: https://github.com/pre-commit/mirrors-isort + rev: v4.3.21 + hooks: + - id: isort + +#- repo: https://github.com/pre-commit/mirrors-mypy +# rev: v0.740 +# hooks: +# - id: mypy +# args: [--no-strict-optional, --ignore-missing-imports] diff --git a/MANIFEST.in b/MANIFEST.in index cda9b38ba..3deae7dbe 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,7 @@ include *.md include *.txt -include .flake8.ini +include *.yaml +include *.yml include LICENSE include tox.ini recursive-include docs *.py diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 000000000..56a942701 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,47 @@ +trigger: +- master +pr: +- master + +pool: + vmImage: 'ubuntu-latest' +strategy: + matrix: + Python36: + python.version: '3.6' + Python37: + python.version: '3.7' +# Python38: +# python.version: '3.8' + +steps: +- task: UsePythonVersion@0 + inputs: + versionSpec: '$(python.version)' + displayName: 'Use Python $(python.version)' + +- script: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install pytest pytest-azurepipelines pytest-cov + displayName: 'Install dependencies' + +- script: | + pre-commit run black --all-files + displayName: 'Code formating (black)' + +- script: | + pre-commit run flake8 --all-files + displayName: 'Code formating (flake8)' + +#- script: | +# pre-commit run mypy --all-files +# displayName: 'Typing checks (mypy)' + +- script: | + pre-commit run isort --all-files + displayName: 'Order of imports (isort)' + +- script: | + pytest --cov miio --cov-report html + displayName: 'Tests' diff --git a/miio/__init__.py b/miio/__init__.py index bf0aaf970..b3c7b24b2 100644 --- a/miio/__init__.py +++ b/miio/__init__.py @@ -1,38 +1,40 @@ # flake8: noqa -from miio.airconditioningcompanion import AirConditioningCompanion -from miio.airconditioningcompanion import AirConditioningCompanionV3 +from miio.airconditioningcompanion import ( + AirConditioningCompanion, + AirConditioningCompanionV3, +) +from miio.airdehumidifier import AirDehumidifier from miio.airfresh import AirFresh from miio.airhumidifier import AirHumidifier -from miio.airdehumidifier import AirDehumidifier from miio.airpurifier import AirPurifier from miio.airqualitymonitor import AirQualityMonitor +from miio.aqaracamera import AqaraCamera from miio.ceil import Ceil from miio.chuangmi_camera import ChuangmiCamera from miio.chuangmi_ir import ChuangmiIr -from miio.chuangmi_plug import Plug, PlugV1, PlugV3, ChuangmiPlug +from miio.chuangmi_plug import ChuangmiPlug, Plug, PlugV1, PlugV3 from miio.cooker import Cooker -from miio.device import Device, DeviceException, DeviceError -from miio.fan import Fan, FanV2, FanSA1, FanZA1, FanZA4, FanP5 +from miio.device import Device, DeviceError, DeviceException +from miio.fan import Fan, FanP5, FanSA1, FanV2, FanZA1, FanZA4 from miio.philips_bulb import PhilipsBulb from miio.philips_eyecare import PhilipsEyecare from miio.philips_moonlight import PhilipsMoonlight from miio.powerstrip import PowerStrip from miio.protocol import Message, Utils -from miio.toiletlid import Toiletlid from miio.pwzn_relay import PwznRelay +from miio.toiletlid import Toiletlid from miio.vacuum import Vacuum, VacuumException from miio.vacuumcontainers import ( - VacuumStatus, - ConsumableStatus, - DNDStatus, CleaningDetails, CleaningSummary, + ConsumableStatus, + DNDStatus, Timer, + VacuumStatus, ) from miio.waterpurifier import WaterPurifier from miio.wifirepeater import WifiRepeater from miio.wifispeaker import WifiSpeaker from miio.yeelight import Yeelight -from miio.aqaracamera import AqaraCamera from miio.discovery import Discovery diff --git a/miio/airconditioningcompanion.py b/miio/airconditioningcompanion.py index 5ece30111..47d0eacfe 100644 --- a/miio/airconditioningcompanion.py +++ b/miio/airconditioningcompanion.py @@ -4,7 +4,7 @@ import click -from .click_common import command, format_output, EnumType +from .click_common import EnumType, command, format_output from .device import Device, DeviceException _LOGGER = logging.getLogger(__name__) diff --git a/miio/airdehumidifier.py b/miio/airdehumidifier.py index 0db153651..7defd8257 100755 --- a/miio/airdehumidifier.py +++ b/miio/airdehumidifier.py @@ -5,8 +5,8 @@ import click -from .click_common import command, format_output, EnumType -from .device import Device, DeviceInfo, DeviceError, DeviceException +from .click_common import EnumType, command, format_output +from .device import Device, DeviceError, DeviceException, DeviceInfo _LOGGER = logging.getLogger(__name__) diff --git a/miio/airfresh.py b/miio/airfresh.py index f4a542133..9a7beece1 100644 --- a/miio/airfresh.py +++ b/miio/airfresh.py @@ -5,7 +5,7 @@ import click -from .click_common import command, format_output, EnumType +from .click_common import EnumType, command, format_output from .device import Device, DeviceException _LOGGER = logging.getLogger(__name__) diff --git a/miio/airhumidifier.py b/miio/airhumidifier.py index dfeb0459d..ee4a9183d 100644 --- a/miio/airhumidifier.py +++ b/miio/airhumidifier.py @@ -5,8 +5,8 @@ import click -from .click_common import command, format_output, EnumType -from .device import Device, DeviceInfo, DeviceError, DeviceException +from .click_common import EnumType, command, format_output +from .device import Device, DeviceError, DeviceException, DeviceInfo _LOGGER = logging.getLogger(__name__) diff --git a/miio/airpurifier.py b/miio/airpurifier.py index 7d8b3814e..aa48710b2 100644 --- a/miio/airpurifier.py +++ b/miio/airpurifier.py @@ -6,7 +6,7 @@ import click -from .click_common import command, format_output, EnumType +from .click_common import EnumType, command, format_output from .device import Device, DeviceException _LOGGER = logging.getLogger(__name__) diff --git a/miio/airqualitymonitor.py b/miio/airqualitymonitor.py index 4bc31483f..0a5bbc9da 100644 --- a/miio/airqualitymonitor.py +++ b/miio/airqualitymonitor.py @@ -25,13 +25,7 @@ "sensor_state", ] -AVAILABLE_PROPERTIES_B1 = [ - "co2e", - "humidity", - "pm25", - "temperature", - "tvoc" -] +AVAILABLE_PROPERTIES_B1 = ["co2e", "humidity", "pm25", "temperature", "tvoc"] AVAILABLE_PROPERTIES_S1 = ["battery", "co2", "humidity", "pm25", "temperature", "tvoc"] @@ -204,7 +198,9 @@ def __init__( self.model = model elif model is not None: self.model = MODEL_AIRQUALITYMONITOR_V1 - _LOGGER.error("Device model %s unsupported. Falling back to %s.", model, self.model) + _LOGGER.error( + "Device model %s unsupported. Falling back to %s.", model, self.model + ) else: """Force autodetection""" self.model = None @@ -250,7 +246,10 @@ def status(self) -> AirQualityMonitorStatus: values_count, ) - if self.model == MODEL_AIRQUALITYMONITOR_S1 or self.model == MODEL_AIRQUALITYMONITOR_B1: + if ( + self.model == MODEL_AIRQUALITYMONITOR_S1 + or self.model == MODEL_AIRQUALITYMONITOR_B1 + ): return AirQualityMonitorStatus(defaultdict(lambda: None, values)) else: return AirQualityMonitorStatus( diff --git a/miio/alarmclock.py b/miio/alarmclock.py index dfd3000ce..c72b9640e 100644 --- a/miio/alarmclock.py +++ b/miio/alarmclock.py @@ -1,9 +1,10 @@ import enum import time + import click +from .click_common import EnumType, command from .device import Device -from .click_common import command, EnumType class HourlySystem(enum.Enum): diff --git a/miio/aqaracamera.py b/miio/aqaracamera.py index b8dabed5c..c4acb74b7 100644 --- a/miio/aqaracamera.py +++ b/miio/aqaracamera.py @@ -7,11 +7,11 @@ TODO: add sdcard status & fix all TODOS TODO: add tests """ -import attr import logging -from typing import Any, Dict from enum import IntEnum +from typing import Any, Dict +import attr import click from .click_common import command, format_output diff --git a/miio/chuangmi_ir.py b/miio/chuangmi_ir.py index 3d902aef3..6e1a293f9 100644 --- a/miio/chuangmi_ir.py +++ b/miio/chuangmi_ir.py @@ -3,19 +3,19 @@ import click from construct import ( - Struct, - Const, - Rebuild, - this, - len_, Adapter, + Array, + BitsInteger, + BitStruct, Computed, + Const, + Int16ub, Int16ul, Int32ul, - Int16ub, - Array, - BitStruct, - BitsInteger, + Rebuild, + Struct, + len_, + this, ) from .click_common import command, format_output diff --git a/miio/chuangmi_plug.py b/miio/chuangmi_plug.py index 020c6f71a..008e80ba1 100644 --- a/miio/chuangmi_plug.py +++ b/miio/chuangmi_plug.py @@ -1,6 +1,6 @@ import logging from collections import defaultdict -from typing import Dict, Any, Optional +from typing import Any, Dict, Optional import click diff --git a/miio/cli.py b/miio/cli.py index 0924e4d8f..b9c440e6d 100644 --- a/miio/cli.py +++ b/miio/cli.py @@ -4,8 +4,8 @@ import click from miio.click_common import ( - ExceptionHandlerGroup, DeviceGroupMeta, + ExceptionHandlerGroup, GlobalContextObject, json_output, ) diff --git a/miio/click_common.py b/miio/click_common.py index d0b80c83b..ed7196317 100644 --- a/miio/click_common.py +++ b/miio/click_common.py @@ -3,23 +3,25 @@ This file contains common functions for cli tools. """ import ast +import ipaddress +import json +import logging +import re import sys +from functools import partial, wraps +from typing import Union + +import click + +import miio + +from .exceptions import DeviceError if sys.version_info < (3, 5): print( "To use this script you need python 3.5 or newer, got %s" % (sys.version_info,) ) sys.exit(1) -import click -import ipaddress -import miio -import logging -import json -import re -from typing import Union -from functools import wraps -from functools import partial -from .exceptions import DeviceError _LOGGER = logging.getLogger(__name__) diff --git a/miio/cooker.py b/miio/cooker.py index b098ff005..297efbc90 100644 --- a/miio/cooker.py +++ b/miio/cooker.py @@ -3,7 +3,7 @@ import string from collections import defaultdict from datetime import time -from typing import Optional, List +from typing import List, Optional import click diff --git a/miio/device.py b/miio/device.py index 8903e1172..c5a5e0392 100644 --- a/miio/device.py +++ b/miio/device.py @@ -9,8 +9,8 @@ import click import construct -from .click_common import DeviceGroupMeta, command, format_output, LiteralParamType -from .exceptions import DeviceException, DeviceError, RecoverableError +from .click_common import DeviceGroupMeta, LiteralParamType, command, format_output +from .exceptions import DeviceError, DeviceException, RecoverableError from .protocol import Message _LOGGER = logging.getLogger(__name__) diff --git a/miio/discovery.py b/miio/discovery.py index cbcee9c9c..b4af5e6d6 100644 --- a/miio/discovery.py +++ b/miio/discovery.py @@ -3,70 +3,68 @@ import ipaddress import logging from functools import partial -from typing import Union, Callable, Dict, Optional # noqa: F401 +from typing import Callable, Dict, Optional, Union # noqa: F401 import zeroconf from . import ( - Device, - Vacuum, - ChuangmiCamera, - ChuangmiPlug, - PowerStrip, - AirPurifier, + AirConditioningCompanion, AirFresh, + AirHumidifier, + AirPurifier, + AirQualityMonitor, + AqaraCamera, Ceil, + ChuangmiCamera, + ChuangmiIr, + ChuangmiPlug, + Cooker, + Device, + Fan, PhilipsBulb, PhilipsEyecare, PhilipsMoonlight, - ChuangmiIr, - AirHumidifier, + PowerStrip, + Toiletlid, + Vacuum, WaterPurifier, - WifiSpeaker, WifiRepeater, + WifiSpeaker, Yeelight, - Fan, - Cooker, - AirConditioningCompanion, - AirQualityMonitor, - AqaraCamera, - Toiletlid, ) - from .airconditioningcompanion import ( MODEL_ACPARTNER_V1, MODEL_ACPARTNER_V2, MODEL_ACPARTNER_V3, ) -from .airqualitymonitor import ( - MODEL_AIRQUALITYMONITOR_V1, - MODEL_AIRQUALITYMONITOR_B1, - MODEL_AIRQUALITYMONITOR_S1, -) from .airhumidifier import ( - MODEL_HUMIDIFIER_CB1, MODEL_HUMIDIFIER_CA1, + MODEL_HUMIDIFIER_CB1, MODEL_HUMIDIFIER_V1, ) +from .airqualitymonitor import ( + MODEL_AIRQUALITYMONITOR_B1, + MODEL_AIRQUALITYMONITOR_S1, + MODEL_AIRQUALITYMONITOR_V1, +) from .alarmclock import AlarmClock from .chuangmi_plug import ( + MODEL_CHUANGMI_PLUG_HMI205, + MODEL_CHUANGMI_PLUG_HMI206, + MODEL_CHUANGMI_PLUG_M1, + MODEL_CHUANGMI_PLUG_M3, MODEL_CHUANGMI_PLUG_V1, MODEL_CHUANGMI_PLUG_V2, MODEL_CHUANGMI_PLUG_V3, - MODEL_CHUANGMI_PLUG_M1, - MODEL_CHUANGMI_PLUG_M3, - MODEL_CHUANGMI_PLUG_HMI205, - MODEL_CHUANGMI_PLUG_HMI206, ) - from .fan import ( + MODEL_FAN_P5, + MODEL_FAN_SA1, MODEL_FAN_V2, MODEL_FAN_V3, - MODEL_FAN_SA1, MODEL_FAN_ZA1, MODEL_FAN_ZA3, MODEL_FAN_ZA4, - MODEL_FAN_P5, ) from .powerstrip import MODEL_POWER_STRIP_V1, MODEL_POWER_STRIP_V2 from .toiletlid import MODEL_TOILETLID_V1 diff --git a/miio/extract_tokens.py b/miio/extract_tokens.py index bbad6d04c..04653ab5b 100644 --- a/miio/extract_tokens.py +++ b/miio/extract_tokens.py @@ -1,10 +1,10 @@ +import json import logging import sqlite3 import tempfile -import json +import xml.etree.ElementTree as ET from pprint import pformat as pf from typing import Iterator -import xml.etree.ElementTree as ET import attr import click diff --git a/miio/fan.py b/miio/fan.py index 9d2436553..599c9417f 100644 --- a/miio/fan.py +++ b/miio/fan.py @@ -4,7 +4,7 @@ import click -from .click_common import command, format_output, EnumType +from .click_common import EnumType, command, format_output from .device import Device, DeviceException _LOGGER = logging.getLogger(__name__) diff --git a/miio/philips_moonlight.py b/miio/philips_moonlight.py index b3c356163..5f9b46d1a 100644 --- a/miio/philips_moonlight.py +++ b/miio/philips_moonlight.py @@ -6,7 +6,7 @@ from .click_common import command, format_output from .device import Device, DeviceException -from .utils import int_to_rgb, rgb_to_int +from .utils import int_to_rgb _LOGGER = logging.getLogger(__name__) diff --git a/miio/powerstrip.py b/miio/powerstrip.py index 9edc88723..128a90165 100644 --- a/miio/powerstrip.py +++ b/miio/powerstrip.py @@ -1,11 +1,11 @@ import enum import logging from collections import defaultdict -from typing import Dict, Any, Optional +from typing import Any, Dict, Optional import click -from .click_common import command, format_output, EnumType +from .click_common import EnumType, command, format_output from .device import Device, DeviceException _LOGGER = logging.getLogger(__name__) diff --git a/miio/protocol.py b/miio/protocol.py index 269203325..2ad60e99a 100644 --- a/miio/protocol.py +++ b/miio/protocol.py @@ -17,22 +17,21 @@ import logging from typing import Any, Dict, Tuple -import construct from construct import ( - Struct, + Adapter, Bytes, + Checksum, Const, + Default, + GreedyBytes, + Hex, + IfThenElse, Int16ub, Int32ub, - GreedyBytes, - Adapter, - Checksum, + Pointer, RawCopy, Rebuild, - IfThenElse, - Default, - Pointer, - Hex, + Struct, ) from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives import padding diff --git a/miio/pwzn_relay.py b/miio/pwzn_relay.py index 2e1efc826..428fcc0e6 100644 --- a/miio/pwzn_relay.py +++ b/miio/pwzn_relay.py @@ -1,6 +1,6 @@ import logging from collections import defaultdict -from typing import Dict, Any +from typing import Any, Dict import click diff --git a/miio/tests/test_airconditioningcompanion.py b/miio/tests/test_airconditioningcompanion.py index fa116bdde..8f8d61550 100644 --- a/miio/tests/test_airconditioningcompanion.py +++ b/miio/tests/test_airconditioningcompanion.py @@ -1,21 +1,21 @@ -import string import json import os +import string from unittest import TestCase import pytest from miio import AirConditioningCompanion, AirConditioningCompanionV3 from miio.airconditioningcompanion import ( - OperationMode, + MODEL_ACPARTNER_V3, + STORAGE_SLOT_ID, + AirConditioningCompanionException, + AirConditioningCompanionStatus, FanSpeed, + Led, + OperationMode, Power, SwingMode, - Led, - AirConditioningCompanionStatus, - AirConditioningCompanionException, - STORAGE_SLOT_ID, - MODEL_ACPARTNER_V3, ) STATE_ON = ["on"] diff --git a/miio/tests/test_airdehumidifier.py b/miio/tests/test_airdehumidifier.py index ea9bcea1a..5b8de7be0 100644 --- a/miio/tests/test_airdehumidifier.py +++ b/miio/tests/test_airdehumidifier.py @@ -4,15 +4,16 @@ from miio import AirDehumidifier from miio.airdehumidifier import ( - OperationMode, - FanSpeed, - AirDehumidifierStatus, - AirDehumidifierException, MODEL_DEHUMIDIFIER_V1, + AirDehumidifierException, + AirDehumidifierStatus, + FanSpeed, + OperationMode, ) -from .dummies import DummyDevice from miio.device import DeviceInfo +from .dummies import DummyDevice + class DummyAirDehumidifierV1(DummyDevice, AirDehumidifier): def __init__(self, *args, **kwargs): diff --git a/miio/tests/test_airfresh.py b/miio/tests/test_airfresh.py index bd675b70e..7972002ce 100644 --- a/miio/tests/test_airfresh.py +++ b/miio/tests/test_airfresh.py @@ -4,11 +4,12 @@ from miio import AirFresh from miio.airfresh import ( - OperationMode, - LedBrightness, - AirFreshStatus, AirFreshException, + AirFreshStatus, + LedBrightness, + OperationMode, ) + from .dummies import DummyDevice diff --git a/miio/tests/test_airhumidifier.py b/miio/tests/test_airhumidifier.py index 62e36d27f..b391a74af 100644 --- a/miio/tests/test_airhumidifier.py +++ b/miio/tests/test_airhumidifier.py @@ -4,17 +4,18 @@ from miio import AirHumidifier from miio.airhumidifier import ( - OperationMode, - LedBrightness, - AirHumidifierStatus, - AirHumidifierException, - MODEL_HUMIDIFIER_V1, MODEL_HUMIDIFIER_CA1, MODEL_HUMIDIFIER_CB1, + MODEL_HUMIDIFIER_V1, + AirHumidifierException, + AirHumidifierStatus, + LedBrightness, + OperationMode, ) -from .dummies import DummyDevice from miio.device import DeviceInfo +from .dummies import DummyDevice + class DummyAirHumidifierV1(DummyDevice, AirHumidifier): def __init__(self, *args, **kwargs): diff --git a/miio/tests/test_airpurifier.py b/miio/tests/test_airpurifier.py index 844dabcab..8691f7b78 100644 --- a/miio/tests/test_airpurifier.py +++ b/miio/tests/test_airpurifier.py @@ -4,13 +4,14 @@ from miio import AirPurifier from miio.airpurifier import ( - OperationMode, - LedBrightness, + AirPurifierException, + AirPurifierStatus, FilterType, + LedBrightness, + OperationMode, SleepMode, - AirPurifierStatus, - AirPurifierException, ) + from .dummies import DummyDevice diff --git a/miio/tests/test_airqualitymonitor.py b/miio/tests/test_airqualitymonitor.py index e984b6ea4..53a500b0c 100644 --- a/miio/tests/test_airqualitymonitor.py +++ b/miio/tests/test_airqualitymonitor.py @@ -4,11 +4,12 @@ from miio import AirQualityMonitor from miio.airqualitymonitor import ( - AirQualityMonitorStatus, - MODEL_AIRQUALITYMONITOR_V1, - MODEL_AIRQUALITYMONITOR_S1, MODEL_AIRQUALITYMONITOR_B1, + MODEL_AIRQUALITYMONITOR_S1, + MODEL_AIRQUALITYMONITOR_V1, + AirQualityMonitorStatus, ) + from .dummies import DummyDevice @@ -141,7 +142,8 @@ def __init__(self, *args, **kwargs): "temperature": 19.799999237060547, "temperature_unit": "c", "tvoc": 1.3948699235916138, - "tvoc_unit": "mg_m3"} + "tvoc_unit": "mg_m3", + } self.return_values = {"get_air_data": self._get_state} super().__init__(args, kwargs) @@ -179,4 +181,4 @@ def test_status(self): assert self.state().pm25 == self.device.start_state["pm25"] assert self.state().tvoc == self.device.start_state["tvoc"] assert self.state().display_clock is None - assert self.state().night_mode is None \ No newline at end of file + assert self.state().night_mode is None diff --git a/miio/tests/test_ceil.py b/miio/tests/test_ceil.py index 42deffd08..78892aece 100644 --- a/miio/tests/test_ceil.py +++ b/miio/tests/test_ceil.py @@ -3,7 +3,8 @@ import pytest from miio import Ceil -from miio.ceil import CeilStatus, CeilException +from miio.ceil import CeilException, CeilStatus + from .dummies import DummyDevice diff --git a/miio/tests/test_chuangmi_ir.py b/miio/tests/test_chuangmi_ir.py index b1dfa207c..fdc760df0 100644 --- a/miio/tests/test_chuangmi_ir.py +++ b/miio/tests/test_chuangmi_ir.py @@ -7,6 +7,7 @@ from miio import ChuangmiIr from miio.chuangmi_ir import ChuangmiIrException + from .dummies import DummyDevice with open(os.path.join(os.path.dirname(__file__), "test_chuangmi_ir.json")) as inp: diff --git a/miio/tests/test_chuangmi_plug.py b/miio/tests/test_chuangmi_plug.py index fdfa491bb..ae0f7cabe 100644 --- a/miio/tests/test_chuangmi_plug.py +++ b/miio/tests/test_chuangmi_plug.py @@ -4,11 +4,12 @@ from miio import ChuangmiPlug from miio.chuangmi_plug import ( - ChuangmiPlugStatus, + MODEL_CHUANGMI_PLUG_M1, MODEL_CHUANGMI_PLUG_V1, MODEL_CHUANGMI_PLUG_V3, - MODEL_CHUANGMI_PLUG_M1, + ChuangmiPlugStatus, ) + from .dummies import DummyDevice diff --git a/miio/tests/test_click_common.py b/miio/tests/test_click_common.py index 78a135a54..fa07e6840 100644 --- a/miio/tests/test_click_common.py +++ b/miio/tests/test_click_common.py @@ -1,4 +1,4 @@ -from miio.click_common import validate_token, validate_ip +from miio.click_common import validate_ip, validate_token def test_validate_token_empty(): diff --git a/miio/tests/test_fan.py b/miio/tests/test_fan.py index 9d131b006..19a092cb2 100644 --- a/miio/tests/test_fan.py +++ b/miio/tests/test_fan.py @@ -4,17 +4,18 @@ from miio import Fan, FanP5 from miio.fan import ( - MoveDirection, - LedBrightness, - OperationMode, - FanStatus, - FanStatusP5, - FanException, + MODEL_FAN_P5, + MODEL_FAN_SA1, MODEL_FAN_V2, MODEL_FAN_V3, - MODEL_FAN_SA1, - MODEL_FAN_P5, + FanException, + FanStatus, + FanStatusP5, + LedBrightness, + MoveDirection, + OperationMode, ) + from .dummies import DummyDevice diff --git a/miio/tests/test_philips_bulb.py b/miio/tests/test_philips_bulb.py index c07730213..8c33cec0f 100644 --- a/miio/tests/test_philips_bulb.py +++ b/miio/tests/test_philips_bulb.py @@ -3,7 +3,8 @@ import pytest from miio import PhilipsBulb -from miio.philips_bulb import PhilipsBulbStatus, PhilipsBulbException +from miio.philips_bulb import PhilipsBulbException, PhilipsBulbStatus + from .dummies import DummyDevice diff --git a/miio/tests/test_philips_eyecare.py b/miio/tests/test_philips_eyecare.py index 56149d3dd..9b829e0ee 100644 --- a/miio/tests/test_philips_eyecare.py +++ b/miio/tests/test_philips_eyecare.py @@ -3,7 +3,8 @@ import pytest from miio import PhilipsEyecare -from miio.philips_eyecare import PhilipsEyecareStatus, PhilipsEyecareException +from miio.philips_eyecare import PhilipsEyecareException, PhilipsEyecareStatus + from .dummies import DummyDevice diff --git a/miio/tests/test_philips_moonlight.py b/miio/tests/test_philips_moonlight.py index 400fd1f65..8096d5fef 100644 --- a/miio/tests/test_philips_moonlight.py +++ b/miio/tests/test_philips_moonlight.py @@ -3,8 +3,9 @@ import pytest from miio import PhilipsMoonlight -from miio.philips_moonlight import PhilipsMoonlightStatus, PhilipsMoonlightException +from miio.philips_moonlight import PhilipsMoonlightException, PhilipsMoonlightStatus from miio.utils import int_to_rgb, rgb_to_int + from .dummies import DummyDevice diff --git a/miio/tests/test_powerstrip.py b/miio/tests/test_powerstrip.py index d4b1a928f..57b947044 100644 --- a/miio/tests/test_powerstrip.py +++ b/miio/tests/test_powerstrip.py @@ -4,12 +4,13 @@ from miio import PowerStrip from miio.powerstrip import ( - PowerMode, - PowerStripStatus, - PowerStripException, MODEL_POWER_STRIP_V1, MODEL_POWER_STRIP_V2, + PowerMode, + PowerStripException, + PowerStripStatus, ) + from .dummies import DummyDevice diff --git a/miio/tests/test_toiletlid.py b/miio/tests/test_toiletlid.py index cf09d72a3..a226968c3 100644 --- a/miio/tests/test_toiletlid.py +++ b/miio/tests/test_toiletlid.py @@ -3,13 +3,15 @@ import pytest from miio.toiletlid import ( + MODEL_TOILETLID_V1, + AmbientLightColor, Toiletlid, ToiletlidStatus, - AmbientLightColor, - MODEL_TOILETLID_V1, ) + from .dummies import DummyDevice + """ Response instance >> status diff --git a/miio/tests/test_vacuum.py b/miio/tests/test_vacuum.py index f065799e2..8c628fa41 100644 --- a/miio/tests/test_vacuum.py +++ b/miio/tests/test_vacuum.py @@ -4,6 +4,7 @@ import pytest from miio import Vacuum, VacuumStatus + from .dummies import DummyDevice diff --git a/miio/tests/test_waterpurifier.py b/miio/tests/test_waterpurifier.py index 8185e1ca6..4e97218bb 100644 --- a/miio/tests/test_waterpurifier.py +++ b/miio/tests/test_waterpurifier.py @@ -4,6 +4,7 @@ from miio import WaterPurifier from miio.waterpurifier import WaterPurifierStatus + from .dummies import DummyDevice diff --git a/miio/tests/test_yeelight.py b/miio/tests/test_yeelight.py index c2f34ab82..c4d628438 100644 --- a/miio/tests/test_yeelight.py +++ b/miio/tests/test_yeelight.py @@ -3,7 +3,8 @@ import pytest from miio import Yeelight -from miio.yeelight import YeelightMode, YeelightStatus, YeelightException +from miio.yeelight import YeelightException, YeelightMode, YeelightStatus + from .dummies import DummyDevice diff --git a/miio/toiletlid.py b/miio/toiletlid.py index 84b08c66b..1fa724347 100644 --- a/miio/toiletlid.py +++ b/miio/toiletlid.py @@ -4,7 +4,7 @@ import click -from .click_common import command, format_output, EnumType +from .click_common import EnumType, command, format_output from .device import Device _LOGGER = logging.getLogger(__name__) diff --git a/miio/updater.py b/miio/updater.py index 331c573e3..1958be9f5 100644 --- a/miio/updater.py +++ b/miio/updater.py @@ -1,9 +1,10 @@ import hashlib import logging -import netifaces -from http.server import HTTPServer, BaseHTTPRequestHandler +from http.server import BaseHTTPRequestHandler, HTTPServer from os.path import basename +import netifaces + _LOGGER = logging.getLogger(__name__) diff --git a/miio/utils.py b/miio/utils.py index 7ebc9ffe5..0fd5e877a 100644 --- a/miio/utils.py +++ b/miio/utils.py @@ -1,7 +1,7 @@ import functools import inspect import warnings -from datetime import timedelta, datetime +from datetime import datetime, timedelta from typing import Tuple diff --git a/miio/vacuum.py b/miio/vacuum.py index e7e238bda..5c1718ea6 100644 --- a/miio/vacuum.py +++ b/miio/vacuum.py @@ -12,18 +12,18 @@ import pytz from appdirs import user_cache_dir -from .click_common import DeviceGroup, command, GlobalContextObject, LiteralParamType +from .click_common import DeviceGroup, GlobalContextObject, LiteralParamType, command from .device import Device, DeviceException from .vacuumcontainers import ( - VacuumStatus, + CarpetModeStatus, + CleaningDetails, + CleaningSummary, ConsumableStatus, DNDStatus, - CleaningSummary, - CleaningDetails, - Timer, - SoundStatus, SoundInstallStatus, - CarpetModeStatus, + SoundStatus, + Timer, + VacuumStatus, ) _LOGGER = logging.getLogger(__name__) diff --git a/miio/vacuum_cli.py b/miio/vacuum_cli.py index 43cfde708..636473fb8 100644 --- a/miio/vacuum_cli.py +++ b/miio/vacuum_cli.py @@ -16,10 +16,11 @@ import miio # noqa: E402 from miio.click_common import ( ExceptionHandlerGroup, + LiteralParamType, validate_ip, validate_token, - LiteralParamType, ) + from .device import UpdateState from .updater import OneShotServer @@ -618,7 +619,7 @@ def update_firmware(vac: miio.Vacuum, url: str, md5: str, ip: str): try: state = vac.update_state() progress = vac.update_progress() - except: # we may not get our messages through during upload + except: # we may not get our messages through during upload # noqa continue if state == UpdateState.Installing: diff --git a/miio/vacuumcontainers.py b/miio/vacuumcontainers.py index b1f6c661a..00daf58a6 100644 --- a/miio/vacuumcontainers.py +++ b/miio/vacuumcontainers.py @@ -1,9 +1,9 @@ # -*- coding: UTF-8 -*# -from datetime import datetime, timedelta, time +from datetime import datetime, time, timedelta from enum import IntEnum from typing import Any, Dict, List -from .utils import deprecated, pretty_time, pretty_seconds +from .utils import deprecated, pretty_seconds, pretty_time def pretty_area(x: float) -> float: diff --git a/miio/waterpurifier.py b/miio/waterpurifier.py index 358a6199d..742558036 100644 --- a/miio/waterpurifier.py +++ b/miio/waterpurifier.py @@ -1,5 +1,4 @@ import logging -from collections import defaultdict from typing import Any, Dict from .click_common import command, format_output diff --git a/miio/yeelight.py b/miio/yeelight.py index ab055739b..c9ab452d2 100644 --- a/miio/yeelight.py +++ b/miio/yeelight.py @@ -1,7 +1,8 @@ import warnings -import click from enum import IntEnum -from typing import Tuple, Optional +from typing import Optional, Tuple + +import click from .click_common import command, format_output from .device import Device, DeviceException diff --git a/setup.py b/setup.py index 6159b337f..ae1325b58 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ import re + from setuptools import setup with open("miio/version.py") as f: @@ -15,7 +16,7 @@ def readme(): setup( name="python-miio", - version=__version__, + version=__version__, # type: ignore # noqa: F821 description="Python library for interfacing with Xiaomi smart appliances", long_description=readme(), url="https://github.com/rytilahti/python-miio", diff --git a/tox.ini b/tox.ini index 58ab03564..e22690c0d 100644 --- a/tox.ini +++ b/tox.ini @@ -35,12 +35,35 @@ commands=flake8 miio [flake8] exclude = .git,.tox,__pycache__ -max-line-length = 100 +max-line-length = 88 +select = C,E,F,W,B,B950 +ignore = E501,W503,E203 [testenv:typing] deps=mypy commands=mypy --ignore-missing-imports miio +[isort] +multi_line_output=3 +include_trailing_comma=True +force_grid_wrap=0 +use_parentheses=True +line_length=88 +known_first_party=miio +forced_separate=miio.discover +known_third_party= + appdirs + attr + click + construct + cryptography + netifaces + pytest + pytz + setuptools + tqdm + zeroconf + [coverage:run] source = miio branch = True @@ -49,7 +72,7 @@ omit = miio/extract_tokens.py miio/tests/* miio/version.py + [coverage:report] exclude_lines = def __repr__ -