Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions .github/workflows/matchers/flake8.json

This file was deleted.

38 changes: 6 additions & 32 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,17 @@ repos:
hooks:
- id: debug-statements

- repo: https://github.com/psf/black
rev: 26.3.1
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.16.9
hooks:
- id: black

- repo: https://github.com/PyCQA/flake8
rev: 7.3.0
hooks:
- id: flake8
additional_dependencies:
- Flake8-pyproject
- flake8-bugbear==25.11.29
- flake8-comprehensions==3.17.0
- flake8_2020==1.8.1
- mccabe==0.7.0
- pycodestyle==2.14.0
- pyflakes==3.4.0

- repo: https://github.com/PyCQA/isort
rev: 8.0.1
hooks:
- id: isort
- id: ruff-check
args: ["--fix", "--exit-non-zero-on-fix"]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.20.1
rev: v2.3.1
hooks:
- id: mypy
additional_dependencies:
- zigpy
- types-setuptools

- repo: https://github.com/asottile/pyupgrade
rev: v3.21.2
hooks:
- id: pyupgrade

- repo: https://github.com/fsouza/autoflake8
rev: v0.4.1
hooks:
- id: autoflake8
52 changes: 31 additions & 21 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,40 @@ testing = [
[tool.setuptools-git-versioning]
enabled = true

[tool.isort]
profile = "black"
# will group `import x` and `from x import` of the same module.
force_sort_within_sections = true
known_first_party = ["zigpy_zigate", "tests"]
forced_separate = "tests"
combine_as_imports = true
[tool.ruff]
target-version = "py311"
line-length = 88

[tool.ruff.lint]
select = [
"B", # flake8-bugbear
"C", # complexity
"E", # pycodestyle
"F", # pyflakes/autoflake
"I", # isort
"SIM", # flake8-simplify
"UP", # pyupgrade
"W", # pycodestyle
"YTT", # flake8-2020
]
ignore = [
"E501", # line too long
]

[tool.ruff.lint.per-file-ignores]
"tests/*" = ["F811", "F401", "F403"]

[tool.ruff.lint.mccabe]
max-complexity = 25

[tool.ruff.lint.isort]
force-sort-within-sections = true
known-first-party = ["zigpy_zigate", "tests"]
forced-separate = ["tests"]
combine-as-imports = true

[tool.mypy]
ignore_errors = true

[tool.pytest.ini_options]
asyncio_mode = "auto"

[tool.flake8]
exclude = [".venv", ".git", ".tox", "docs", "venv", "bin", "lib", "deps", "build"]
# To work with Black
max-line-length = 88
# W503: Line break occurred before a binary operator
# E203: Whitespace before ':'
# E501: line too long
# D202 No blank lines allowed after function docstring
ignore = [
"W503", "E203", "E501", "D202",
"D103", "D102", "D101", # TODO: remove these once docstrings are added
]
per-file-ignores = ["tests/*:F811,F401,F403"]
6 changes: 1 addition & 5 deletions requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Test dependencies.

asynctest
isort
black
flake8
codecov
colorlog
codespell
Expand All @@ -16,5 +13,4 @@ pytest-timeout
pytest-asyncio>=0.17
pytest>=7.1.3
zigpy>=0.54.1
ruff==0.0.261
Flake8-pyproject
ruff==0.16.9
5 changes: 2 additions & 3 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import contextlib
from unittest.mock import AsyncMock, MagicMock, patch, sentinel

import pytest
Expand Down Expand Up @@ -60,8 +61,6 @@ async def test_api_new(conn_mck):
@patch.object(asyncio, "wait", return_value=([], []))
async def test_api_command(mock_command, api):
"""Test command method."""
try:
with contextlib.suppress(zigate_api.NoResponseError):
await api.set_raw_mode()
except zigate_api.NoResponseError:
pass
assert mock_command.call_count == 3
21 changes: 10 additions & 11 deletions zigpy_zigate/api.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import asyncio
import binascii
from datetime import datetime, timezone
from datetime import UTC, datetime
import enum
import functools
import logging
from typing import Any, Dict
from typing import Any

from zigpy.datastructures import PriorityLock
import zigpy.exceptions
Expand Down Expand Up @@ -220,7 +220,7 @@ class CommandNotSupportedError(CommandError):


class ZiGate:
def __init__(self, device_config: Dict[str, Any]):
def __init__(self, device_config: dict[str, Any]):
self._app = None
self._config = device_config
self._uart = None
Expand All @@ -231,7 +231,7 @@ def __init__(self, device_config: Dict[str, Any]):
self.network_state = None

@classmethod
async def new(cls, config: Dict[str, Any], application=None) -> "ZiGate":
async def new(cls, config: dict[str, Any], application=None) -> "ZiGate":
api = cls(config)
await api.connect()
api.set_application(application)
Expand Down Expand Up @@ -263,10 +263,9 @@ def data_received(self, cmd, data, lqi):
cmd = ResponseId(cmd)
data, rest = t.deserialize(data, RESPONSES[cmd])
LOGGER.debug("Response received: %s %s %s (LQI:%s)", cmd, data, rest, lqi)
if cmd == ResponseId.STATUS:
if data[2] in self._status_awaiting:
fut = self._status_awaiting.pop(data[2])
fut.set_result((data, lqi))
if cmd == ResponseId.STATUS and data[2] in self._status_awaiting:
fut = self._status_awaiting.pop(data[2])
fut.set_result((data, lqi))
if cmd in self._awaiting:
fut = self._awaiting.pop(cmd)
fut.set_result((data, lqi))
Expand Down Expand Up @@ -386,8 +385,8 @@ async def version(self):

async def version_str(self):
version, lqi = await self.version()
version = "{:x}".format(version[1])
version = "{}.{}".format(version[0], version[1:])
version = f"{version[1]:x}"
version = f"{version[0]}.{version[1:]}"
return version

async def get_network_state(self):
Expand Down Expand Up @@ -418,7 +417,7 @@ async def erase_persistent_data(self):
async def set_time(self):
"""set internal time"""
timestamp = (
datetime.now(timezone.utc) - datetime(2000, 1, 1, tzinfo=timezone.utc)
datetime.now(UTC) - datetime(2000, 1, 1, tzinfo=UTC)
).total_seconds()

data = t.serialize([int(timestamp)], COMMANDS[CommandId.SET_TIMESERVER])
Expand Down
Loading
Loading