From 122cd4c19f5f5bbb54eb9631d114c2b3dcfc3678 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Thu, 12 Dec 2019 10:41:52 +0100 Subject: [PATCH] run pre-commit run --all --- .gitignore | 2 - .pre-commit-config.yaml | 16 ++++++++ CHANGELOG | 40 +++++++++---------- pyHS100/cli.py | 6 +-- pyHS100/smartdevice.py | 2 + pyHS100/tests/fixtures/HS100(US)_1.0.json | 2 +- pyHS100/tests/fixtures/HS105(US)_1.0.json | 2 +- .../tests/fixtures/HS110(EU)_1.0_real.json | 2 +- pyHS100/tests/fixtures/HS110(EU)_2.0.json | 2 +- pyHS100/tests/fixtures/HS110(US)_1.0.json | 2 +- pyHS100/tests/fixtures/HS200(US)_1.0.json | 2 +- pyHS100/tests/fixtures/HS220(US)_1.0.json | 2 +- pyHS100/tests/fixtures/HS300(US)_1.0.json | 2 +- .../tests/fixtures/KL120(US)_1.0_real.json | 2 +- pyHS100/tests/fixtures/LB100(US)_1.0.json | 2 +- pyHS100/tests/fixtures/LB120(US)_1.0.json | 2 +- pyHS100/tests/fixtures/LB130(US)_1.0.json | 2 +- pyHS100/tests/test_fixtures.py | 1 + tox.ini | 2 +- 19 files changed, 54 insertions(+), 39 deletions(-) diff --git a/.gitignore b/.gitignore index fe680aec..10deab0b 100644 --- a/.gitignore +++ b/.gitignore @@ -24,5 +24,3 @@ venv .venv /build - - diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d573211e..bbdf8a9f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,20 @@ repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.4.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-docstring-first + - id: check-yaml + - id: debug-statements + - id: check-ast + +- repo: https://github.com/asottile/pyupgrade + rev: v1.25.2 + hooks: + - id: pyupgrade + args: ['--py36-plus'] + - repo: https://github.com/python/black rev: stable hooks: diff --git a/CHANGELOG b/CHANGELOG index 2eabe3ac..aa634aef 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -96,11 +96,11 @@ There are two notable changes (and other small fixes) in this minor release than 0.3.3 (2018-09-06) ------------------ -This release contains a breaking change for hsv setter, which is changed to accept +This release contains a breaking change for hsv setter, which is changed to accept the new brightness value in percentage instead of an integer between 1 and 255. The alias support has been extended to allow changing the alias, as well as accessing -the device using it (without specifying an IP address or a hostname), which can be +the device using it (without specifying an IP address or a hostname), which can be useful in some setups. Furthermore utf8-encoded aliases are now handled correctly. - Fix bug that changed brightness at each HSV update (#124) [Sebastian Templ] @@ -126,7 +126,7 @@ useful in some setups. Furthermore utf8-encoded aliases are now handled correctl within their valid ranges (0..255, 0..100, 0..100) and raise SmartDeviceException if they are not - add test function for the hsv setter - + - Allow using alias instead of IP address or hostname (#127) [kwazel] * Added option to control devices by device name @@ -140,7 +140,7 @@ useful in some setups. Furthermore utf8-encoded aliases are now handled correctl * processed review comments * Return when no device with alias has been found - + - Add 'alias' command for querying and setting the alias (#126) [Teemu R] * add 'alias' command for querying and setting the alias @@ -152,7 +152,7 @@ useful in some setups. Furthermore utf8-encoded aliases are now handled correctl * readd py33, remove it from travis as it seems to be a travis limitation only * use xenial dist for travis, regular does not support py37.. - + - Support Unicode strings in encrypt/decrypt (#125) [Anders Melchiorsen] @@ -193,18 +193,18 @@ Breaking changes: * Adds a new 'kwh' parameter for those calls, which defaults to True * This changes the behavior of bulbs emeter reporting, use False if you prefer the preciser values - + - Update pypi description (#102) [Teemu R] * update pypi description * add wall switches - + - Update smartplug.py to support dimming in HS220 (#115) [JsChiSurf] * Update smartplug.py to support dimming in HS220 - Switch functions essentially as a "plug" with the addition to support for dimming, for which can be test for by verifying existence of + Switch functions essentially as a "plug" with the addition to support for dimming, for which can be test for by verifying existence of 'brightness' array value. * Attempt at updates to pass validator @@ -213,7 +213,7 @@ Breaking changes: * Add more detail to comment blocks - Make clear in requests for current brightness level the expected return values, and note that light will turn on when setting a brightness + Make clear in requests for current brightness level the expected return values, and note that light will turn on when setting a brightness level, if not already on. This makes clear that a state change request (turn_on) does NOT have to be made first when setting brightness. * Update smartplug.py @@ -221,22 +221,22 @@ level, if not already on. This makes clear that a state change request (turn_on * Update smartplug.py Fixes #114 - + - Add python_requires for >= 3.4. [Teemu Rytilahti] - Add hs210. [Teemu R] Based on user report: https://community.home-assistant.io/t/tp-link-hs210-3-way-kit/39762/6 - + - Add support for DNS host names (#104) [K Henriksson] - Use direct device type discovery for devices (#106) [K Henriksson] This is more efficient than enumerating all devices and checking the IP. - + - Cli: add 'time' command to get the current time from the device. [Teemu Rytilahti] - + - Created a docker file to aid dev setup (#99) [TheSmokingGnu] * created a docker file to aid dev setup @@ -361,31 +361,31 @@ Other changes: * Check for mic_mac on mac, based on work by kdschloesser on issue #59 * make hound happy, __init__ on SmartDevice cannot error out so removing 'raises' documentation - + - Add LB110 sysinfo (#75) [Sean Gollschewsky] * Add LB110 sysinfo * Linting. - + - Add @pass_dev to hsv, adjust ranges (#70) [Teemu R] * add @pass_dev to hsv command, it was always broken * Hue goes up to 360, saturation and value are up to 100(%) - + - Extract shared types (exceptions, enums), add module level doc, rename exception to be generic. [Teemu Rytilahti] - + - Add check to ensure devices with lat/lon with `_i` suffix are supported (#54) (#56) [Matt LeBrun] * Add check to ensure devices with lat/lon with `_i` suffix are supported (#54) * Add .gitignore for posterity - + - Generalize smartdevice class and add bulb support for the cli tool (#50) [Teemu R] Fixes #48 and #51. The basic functionality should work on all types of supported devices, for bulb specific commands it is currently necessary to specify ```--bulb```. - + - Refactor and drop py2 support (#49) [Teemu R] * move is_off property to SmartDevice, implement is_on for bulb and use it @@ -699,5 +699,3 @@ Other changes: - Create pyHS100.py. [GadgetReactor] - Initial commit. [GadgetReactor] - - diff --git a/pyHS100/cli.py b/pyHS100/cli.py index 594ec165..fe395ffd 100755 --- a/pyHS100/cli.py +++ b/pyHS100/cli.py @@ -172,7 +172,7 @@ def sysinfo(dev): def state(ctx, dev: SmartDevice): """Print out device state and versions.""" dev.sync.update() - click.echo(click.style("== {} - {} ==".format(dev.alias, dev.model), bold=True)) + click.echo(click.style(f"== {dev.alias} - {dev.model} ==", bold=True)) click.echo( click.style( @@ -199,8 +199,8 @@ def state(ctx, dev: SmartDevice): click.echo("Time: {}".format(dev.sync.get_time())) click.echo("Hardware: {}".format(dev.hw_info["hw_ver"])) click.echo("Software: {}".format(dev.hw_info["sw_ver"])) - click.echo("MAC (rssi): {} ({})".format(dev.mac, dev.rssi)) - click.echo("Location: {}".format(dev.location)) + click.echo(f"MAC (rssi): {dev.mac} ({dev.rssi})") + click.echo(f"Location: {dev.location}") ctx.invoke(emeter) diff --git a/pyHS100/smartdevice.py b/pyHS100/smartdevice.py index f80f54d3..ae4bf1cc 100755 --- a/pyHS100/smartdevice.py +++ b/pyHS100/smartdevice.py @@ -82,6 +82,7 @@ class EmeterStatus(dict): def requires_update(f): """Indicate that `update` should be called before accessing this method.""" # noqa: D202 if inspect.iscoroutinefunction(f): + @functools.wraps(f) async def wrapped(*args, **kwargs): self = args[0] @@ -89,6 +90,7 @@ def requires_update(f): return await f(*args, **kwargs) else: + @functools.wraps(f) def wrapped(*args, **kwargs): self = args[0] diff --git a/pyHS100/tests/fixtures/HS100(US)_1.0.json b/pyHS100/tests/fixtures/HS100(US)_1.0.json index 464c5b99..cf9b0ba0 100644 --- a/pyHS100/tests/fixtures/HS100(US)_1.0.json +++ b/pyHS100/tests/fixtures/HS100(US)_1.0.json @@ -44,4 +44,4 @@ "updating": 0 } } -} \ No newline at end of file +} diff --git a/pyHS100/tests/fixtures/HS105(US)_1.0.json b/pyHS100/tests/fixtures/HS105(US)_1.0.json index c33fa793..cf2aa5f4 100644 --- a/pyHS100/tests/fixtures/HS105(US)_1.0.json +++ b/pyHS100/tests/fixtures/HS105(US)_1.0.json @@ -44,4 +44,4 @@ "updating": 0 } } -} \ No newline at end of file +} diff --git a/pyHS100/tests/fixtures/HS110(EU)_1.0_real.json b/pyHS100/tests/fixtures/HS110(EU)_1.0_real.json index 111286fe..1a8ced8f 100644 --- a/pyHS100/tests/fixtures/HS110(EU)_1.0_real.json +++ b/pyHS100/tests/fixtures/HS110(EU)_1.0_real.json @@ -46,4 +46,4 @@ "updating": 0 } } -} \ No newline at end of file +} diff --git a/pyHS100/tests/fixtures/HS110(EU)_2.0.json b/pyHS100/tests/fixtures/HS110(EU)_2.0.json index 0b4e4932..9fa57d3b 100644 --- a/pyHS100/tests/fixtures/HS110(EU)_2.0.json +++ b/pyHS100/tests/fixtures/HS110(EU)_2.0.json @@ -47,4 +47,4 @@ "updating": 0 } } -} \ No newline at end of file +} diff --git a/pyHS100/tests/fixtures/HS110(US)_1.0.json b/pyHS100/tests/fixtures/HS110(US)_1.0.json index f7cc3414..562b28a3 100644 --- a/pyHS100/tests/fixtures/HS110(US)_1.0.json +++ b/pyHS100/tests/fixtures/HS110(US)_1.0.json @@ -47,4 +47,4 @@ "updating": 0 } } -} \ No newline at end of file +} diff --git a/pyHS100/tests/fixtures/HS200(US)_1.0.json b/pyHS100/tests/fixtures/HS200(US)_1.0.json index 12ebd3b4..5e9e8b8e 100644 --- a/pyHS100/tests/fixtures/HS200(US)_1.0.json +++ b/pyHS100/tests/fixtures/HS200(US)_1.0.json @@ -44,4 +44,4 @@ "updating": 0 } } -} \ No newline at end of file +} diff --git a/pyHS100/tests/fixtures/HS220(US)_1.0.json b/pyHS100/tests/fixtures/HS220(US)_1.0.json index 64460f3b..15afc613 100644 --- a/pyHS100/tests/fixtures/HS220(US)_1.0.json +++ b/pyHS100/tests/fixtures/HS220(US)_1.0.json @@ -72,4 +72,4 @@ "updating": 0 } } -} \ No newline at end of file +} diff --git a/pyHS100/tests/fixtures/HS300(US)_1.0.json b/pyHS100/tests/fixtures/HS300(US)_1.0.json index bf50a1e2..997919c1 100644 --- a/pyHS100/tests/fixtures/HS300(US)_1.0.json +++ b/pyHS100/tests/fixtures/HS300(US)_1.0.json @@ -99,4 +99,4 @@ "updating": 0 } } -} \ No newline at end of file +} diff --git a/pyHS100/tests/fixtures/KL120(US)_1.0_real.json b/pyHS100/tests/fixtures/KL120(US)_1.0_real.json index 65115c46..c251f2fa 100644 --- a/pyHS100/tests/fixtures/KL120(US)_1.0_real.json +++ b/pyHS100/tests/fixtures/KL120(US)_1.0_real.json @@ -90,4 +90,4 @@ "sw_ver": "1.8.6 Build 180809 Rel.091659" } } -} \ No newline at end of file +} diff --git a/pyHS100/tests/fixtures/LB100(US)_1.0.json b/pyHS100/tests/fixtures/LB100(US)_1.0.json index 1be93df8..8f5026e2 100644 --- a/pyHS100/tests/fixtures/LB100(US)_1.0.json +++ b/pyHS100/tests/fixtures/LB100(US)_1.0.json @@ -100,4 +100,4 @@ "sw_ver": "1.4.3 Build 170504 Rel.144921" } } -} \ No newline at end of file +} diff --git a/pyHS100/tests/fixtures/LB120(US)_1.0.json b/pyHS100/tests/fixtures/LB120(US)_1.0.json index fad65cc8..e9d1dce2 100644 --- a/pyHS100/tests/fixtures/LB120(US)_1.0.json +++ b/pyHS100/tests/fixtures/LB120(US)_1.0.json @@ -100,4 +100,4 @@ "sw_ver": "1.1.0 Build 160630 Rel.085319" } } -} \ No newline at end of file +} diff --git a/pyHS100/tests/fixtures/LB130(US)_1.0.json b/pyHS100/tests/fixtures/LB130(US)_1.0.json index bee102d9..dcd441ce 100644 --- a/pyHS100/tests/fixtures/LB130(US)_1.0.json +++ b/pyHS100/tests/fixtures/LB130(US)_1.0.json @@ -101,4 +101,4 @@ "sw_ver": "1.6.0 Build 170703 Rel.141938" } } -} \ No newline at end of file +} diff --git a/pyHS100/tests/test_fixtures.py b/pyHS100/tests/test_fixtures.py index fa1d7661..ce7a03e5 100644 --- a/pyHS100/tests/test_fixtures.py +++ b/pyHS100/tests/test_fixtures.py @@ -604,5 +604,6 @@ def test_children_get_emeter_monthly(dev): def test_representation(dev): import re + pattern = re.compile("<.* model .* at .* (.*), is_on: .* - dev specific: .*>") assert pattern.match(str(dev)) diff --git a/tox.ini b/tox.ini index 6e010f45..2fe21c69 100644 --- a/tox.ini +++ b/tox.ini @@ -15,7 +15,7 @@ deps= voluptuous typing deprecation - flake8 + flake8 commands= py.test --cov --cov-config=tox.ini pyHS100