| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5b7e590 commit 416d311
17 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,6 +27,7 @@ jobs: | |||
| 27 | 27 | python-version: ${{ matrix.python-version }} | |
| 28 | 28 | cache-pre-commit: true | |
| 29 | 29 | poetry-version: ${{ env.POETRY_VERSION }} | |
| 30 | + poetry-install-options: "--all-extras" | ||
| 30 | 31 | - name: "Check supported device md files are up to date" | |
| 31 | 32 | run: | | |
| 32 | 33 | poetry run pre-commit run generate-supported --all-files | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,17 +16,6 @@ repos: | |||
| 16 | 16 | args: [--fix, --exit-non-zero-on-fix] | |
| 17 | 17 | - id: ruff-format | |
| 18 | 18 | ||
| 19 | - - repo: https://github.com/pre-commit/mirrors-mypy | ||
| 20 | - rev: v1.9.0 | ||
| 21 | - hooks: | ||
| 22 | - - id: mypy | ||
| 23 | - additional_dependencies: [types-click] | ||
| 24 | - exclude: | | ||
| 25 | - (?x)^( | ||
| 26 | - kasa/modulemapping\.py| | ||
| 27 | - )$ | ||
| 28 | - | ||
| 29 | - | ||
| 30 | 19 | - repo: https://github.com/PyCQA/doc8 | |
| 31 | 20 | rev: 'v1.1.1' | |
| 32 | 21 | hooks: | |
@@ -35,6 +24,18 @@ repos: | |||
| 35 | 24 | ||
| 36 | 25 | - repo: local | |
| 37 | 26 | hooks: | |
| 27 | + # Run mypy in the virtual environment so it uses the installed dependencies | ||
| 28 | + # for more accurate checking than using the pre-commit mypy mirror | ||
| 29 | + - id: mypy | ||
| 30 | + name: mypy | ||
| 31 | + entry: devtools/run-in-env.sh mypy | ||
| 32 | + language: script | ||
| 33 | + types_or: [python, pyi] | ||
| 34 | + require_serial: true | ||
| 35 | + exclude: | # exclude required because --all-files passes py and pyi | ||
| 36 | + (?x)^( | ||
| 37 | + kasa/modulemapping\.py| | ||
| 38 | + )$ | ||
| 38 | 39 | - id: generate-supported | |
| 39 | 40 | name: Generate supported devices | |
| 40 | 41 | description: This hook generates the supported device sections of README.md and SUPPORTED.md | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,8 +5,9 @@ | |||
| 5 | 5 | ||
| 6 | 6 | import orjson | |
| 7 | 7 | from kasa_crypt import decrypt, encrypt | |
| 8 | - from utils.data import REQUEST, WIRE_RESPONSE | ||
| 9 | - from utils.original import OriginalTPLinkSmartHomeProtocol | ||
| 8 | + | ||
| 9 | + from devtools.bench.utils.data import REQUEST, WIRE_RESPONSE | ||
| 10 | + from devtools.bench.utils.original import OriginalTPLinkSmartHomeProtocol | ||
| 10 | 11 | ||
| 11 | 12 | ||
| 12 | 13 | def original_request_response() -> None: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + #!/bin/bash | ||
| 2 | + source $(poetry env info --path)/bin/activate | ||
| 3 | + exec "$@" | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -371,7 +371,10 @@ def create_from_keypair(handshake_key: str, keypair): | |||
| 371 | 371 | handshake_key_bytes: bytes = base64.b64decode(handshake_key.encode("UTF-8")) | |
| 372 | 372 | private_key_data = base64.b64decode(keypair.get_private_key().encode("UTF-8")) | |
| 373 | 373 | ||
| 374 | - private_key = serialization.load_der_private_key(private_key_data, None, None) | ||
| 374 | + private_key = cast( | ||
| 375 | + rsa.RSAPrivateKey, | ||
| 376 | + serialization.load_der_private_key(private_key_data, None, None), | ||
| 377 | + ) | ||
| 375 | 378 | key_and_iv = private_key.decrypt( | |
| 376 | 379 | handshake_key_bytes, asymmetric_padding.PKCS1v15() | |
| 377 | 380 | ) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -101,9 +101,7 @@ def error(msg: str): | |||
| 101 | 101 | # Block list of commands which require no update | |
| 102 | 102 | SKIP_UPDATE_COMMANDS = ["raw-command", "command"] | |
| 103 | 103 | ||
| 104 | - click.anyio_backend = "asyncio" | ||
| 105 | - | ||
| 106 | - pass_dev = click.make_pass_decorator(Device) | ||
| 104 | + pass_dev = click.make_pass_decorator(Device) # type: ignore[type-abstract] | ||
| 107 | 105 | ||
| 108 | 106 | ||
| 109 | 107 | def CatchAllExceptions(cls): | |
@@ -1005,7 +1003,7 @@ async def time_get(dev: Device): | |||
| 1005 | 1003 | ||
| 1006 | 1004 | @time.command(name="sync") | |
| 1007 | 1005 | @pass_dev | |
| 1008 | - async def time_sync(dev: SmartDevice): | ||
| 1006 | + async def time_sync(dev: Device): | ||
| 1009 | 1007 | """Set the device time to current time.""" | |
| 1010 | 1008 | if not isinstance(dev, SmartDevice): | |
| 1011 | 1009 | raise NotImplementedError("setting time currently only implemented on smart") | |
@@ -1143,7 +1141,7 @@ async def presets(ctx): | |||
| 1143 | 1141 | ||
| 1144 | 1142 | @presets.command(name="list") | |
| 1145 | 1143 | @pass_dev | |
| 1146 | - def presets_list(dev: IotBulb): | ||
| 1144 | + def presets_list(dev: Device): | ||
| 1147 | 1145 | """List presets.""" | |
| 1148 | 1146 | if not dev.is_bulb or not isinstance(dev, IotBulb): | |
| 1149 | 1147 | error("Presets only supported on iot bulbs") | |
@@ -1162,7 +1160,7 @@ def presets_list(dev: IotBulb): | |||
| 1162 | 1160 | @click.option("--saturation", type=int) | |
| 1163 | 1161 | @click.option("--temperature", type=int) | |
| 1164 | 1162 | @pass_dev | |
| 1165 | - async def presets_modify(dev: IotBulb, index, brightness, hue, saturation, temperature): | ||
| 1163 | + async def presets_modify(dev: Device, index, brightness, hue, saturation, temperature): | ||
| 1166 | 1164 | """Modify a preset.""" | |
| 1167 | 1165 | for preset in dev.presets: | |
| 1168 | 1166 | if preset.index == index: | |
@@ -1190,7 +1188,7 @@ async def presets_modify(dev: IotBulb, index, brightness, hue, saturation, tempe | |||
| 1190 | 1188 | @click.option("--type", type=click.Choice(["soft", "hard"], case_sensitive=False)) | |
| 1191 | 1189 | @click.option("--last", is_flag=True) | |
| 1192 | 1190 | @click.option("--preset", type=int) | |
| 1193 | - async def turn_on_behavior(dev: IotBulb, type, last, preset): | ||
| 1191 | + async def turn_on_behavior(dev: Device, type, last, preset): | ||
| 1194 | 1192 | """Modify bulb turn-on behavior.""" | |
| 1195 | 1193 | if not dev.is_bulb or not isinstance(dev, IotBulb): | |
| 1196 | 1194 | error("Presets only supported on iot bulbs") | |
@@ -1248,7 +1246,7 @@ async def shell(dev: Device): | |||
| 1248 | 1246 | logging.getLogger("asyncio").setLevel(logging.WARNING) | |
| 1249 | 1247 | loop = asyncio.get_event_loop() | |
| 1250 | 1248 | try: | |
| 1251 | - await embed( | ||
| 1249 | + await embed( # type: ignore[func-returns-value] | ||
| 1252 | 1250 | globals=globals(), | |
| 1253 | 1251 | locals=locals(), | |
| 1254 | 1252 | return_asyncio_coroutine=True, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,7 +36,7 @@ class HttpClient: | |||
| 36 | 36 | ||
| 37 | 37 | def __init__(self, config: DeviceConfig) -> None: | |
| 38 | 38 | self._config = config | |
| 39 | - self._client_session: aiohttp.ClientSession = None | ||
| 39 | + self._client_session: aiohttp.ClientSession | None = None | ||
| 40 | 40 | self._jar = aiohttp.CookieJar(unsafe=True, quote_cookie=False) | |
| 41 | 41 | self._last_url = URL(f"http://{self._config.host}/") | |
| 42 | 42 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -231,7 +231,9 @@ def discovery_data(request, mocker): | |||
| 231 | 231 | return {"system": {"get_sysinfo": fixture_data["system"]["get_sysinfo"]}} | |
| 232 | 232 | ||
| 233 | 233 | ||
| 234 | - @pytest.fixture(params=UNSUPPORTED_DEVICES.values(), ids=UNSUPPORTED_DEVICES.keys()) | ||
| 234 | + @pytest.fixture( | ||
| 235 | + params=UNSUPPORTED_DEVICES.values(), ids=list(UNSUPPORTED_DEVICES.keys()) | ||
| 236 | + ) | ||
| 235 | 237 | def unsupported_device_info(request, mocker): | |
| 236 | 238 | """Return unsupported devices for cli and discovery tests.""" | |
| 237 | 239 | discovery_data = request.param | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -276,7 +276,7 @@ def _send_request(self, request_dict: dict): | |||
| 276 | 276 | ): | |
| 277 | 277 | result["sum"] = len(result[list_key]) | |
| 278 | 278 | if self.warn_fixture_missing_methods: | |
| 279 | - pytest.fixtures_missing_methods.setdefault( | ||
| 279 | + pytest.fixtures_missing_methods.setdefault( # type: ignore[attr-defined] | ||
| 280 | 280 | self.fixture_name, set() | |
| 281 | 281 | ).add(f"{method} (incomplete '{list_key}' list)") | |
| 282 | 282 | ||
@@ -305,7 +305,7 @@ def _send_request(self, request_dict: dict): | |||
| 305 | 305 | } | |
| 306 | 306 | # Reduce warning spam by consolidating and reporting at the end of the run | |
| 307 | 307 | if self.warn_fixture_missing_methods: | |
| 308 | - pytest.fixtures_missing_methods.setdefault( | ||
| 308 | + pytest.fixtures_missing_methods.setdefault( # type: ignore[attr-defined] | ||
| 309 | 309 | self.fixture_name, set() | |
| 310 | 310 | ).add(method) | |
| 311 | 311 | return retval | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,6 +2,7 @@ | |||
| 2 | 2 | ||
| 3 | 3 | import asyncio | |
| 4 | 4 | import logging | |
| 5 | + from typing import TypedDict | ||
| 5 | 6 | ||
| 6 | 7 | import pytest | |
| 7 | 8 | from pytest_mock import MockerFixture | |
@@ -71,7 +72,17 @@ async def test_firmware_update( | |||
| 71 | 72 | assert fw | |
| 72 | 73 | ||
| 73 | 74 | upgrade_time = 5 | |
| 74 | - extras = {"reboot_time": 5, "upgrade_time": upgrade_time, "auto_upgrade": False} | ||
| 75 | + | ||
| 76 | + class Extras(TypedDict): | ||
| 77 | + reboot_time: int | ||
| 78 | + upgrade_time: int | ||
| 79 | + auto_upgrade: bool | ||
| 80 | + | ||
| 81 | + extras: Extras = { | ||
| 82 | + "reboot_time": 5, | ||
| 83 | + "upgrade_time": upgrade_time, | ||
| 84 | + "auto_upgrade": False, | ||
| 85 | + } | ||
| 75 | 86 | update_states = [ | |
| 76 | 87 | # Unknown 1 | |
| 77 | 88 | DownloadState(status=1, download_progress=0, **extras), | |
| Back | FazBrowse Home | New Git URL |
0 commit comments