Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pre-commit-config hooks #155

Merged
merged 1 commit into from
Sep 30, 2023
Merged
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
44 changes: 36 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,54 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py38-plus]

- repo: https://github.com/PyCQA/autoflake
rev: v2.0.2
hooks:
- id: autoflake

- repo: https://github.com/psf/black
rev: 23.1.0
rev: 23.3.0
hooks:
- id: black
args:
- --safe
- --quiet
- --safe

- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies:
- Flake8-pyproject==1.2.3

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0

- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
hooks:
- id: codespell
args:
- --ignore-words-list=ser,nd,hass
- --skip="./.*"
- --quiet-level=2

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.3.0
hooks:
- id: mypy
additional_dependencies:
- zigpy

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.261
hooks:
- id: no-commit-to-branch
- id: ruff
args:
- --branch=dev
- --branch=master
- --branch=rc
- --fix
4 changes: 2 additions & 2 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def test_frame_received(api, monkeypatch):
cmd_id = cmd_opts[0]
payload = b"\x01\x02\x03\x04"
data = cmd_id.to_bytes(1, "big") + payload
setattr(api, "_handle_{}".format(cmd), my_handler)
setattr(api, f"_handle_{cmd}", my_handler)
api.frame_received(data)
assert t.deserialize.call_count == 1
assert t.deserialize.call_args[0][0] == payload
Expand Down Expand Up @@ -268,7 +268,7 @@ def test_frame_received_no_handler(api, monkeypatch):


def _handle_at_response(api, tsn, status, at_response=b""):
data = (tsn, "AI".encode("ascii"), status, at_response)
data = (tsn, b"AI", status, at_response)
response = asyncio.Future()
api._awaiting[tsn] = (response,)
api._handle_at_response(*data)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_bytes_deserialize():


def test_atcommand():
cmd = "AI".encode("ascii")
cmd = b"AI"
data = 0x06.to_bytes(4, "big")
r_cmd, r_data = t.ATCommand.deserialize(cmd + data)

Expand Down
19 changes: 7 additions & 12 deletions zigpy_xbee/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ class ModemStatus(t.uint8_t, t.UndefinedEnum):
"RE": None,
"FR": None,
"NR": t.Bool,
"SI": None,
"CB": t.uint8_t,
"ND": t, # "optional 2-Byte NI value"
"DN": t.Bytes, # "up to 20-Byte printable ASCII string"
Expand Down Expand Up @@ -407,7 +406,7 @@ def frame_received(self, data):
LOGGER.debug("Frame received: %s", command)
data, rest = t.deserialize(data[1:], COMMAND_RESPONSES[command][1])
try:
getattr(self, "_handle_%s" % (command,))(*data)
getattr(self, f"_handle_{command}")(*data)
except AttributeError:
LOGGER.error("No '%s' handler. Data: %s", command, binascii.hexlify(data))

Expand All @@ -419,9 +418,7 @@ def _handle_at_response(self, frame_id, cmd, status, value):
status = ATCommandResult.ERROR

if status:
fut.set_exception(
RuntimeError("AT Command response: {}".format(status.name))
)
fut.set_exception(RuntimeError(f"AT Command response: {status.name}"))
return

response_type = AT_COMMANDS[cmd.decode("ascii")]
Expand Down Expand Up @@ -496,7 +493,7 @@ def _handle_tx_status(self, frame_id, nwk, tries, tx_status, dsc_status):
):
fut.set_result(tx_status)
else:
fut.set_exception(DeliveryError("%s" % (tx_status,)))
fut.set_exception(DeliveryError(f"{tx_status}"))
except asyncio.InvalidStateError as ex:
LOGGER.debug("duplicate tx_status for %s nwk? State: %s", nwk, ex)

Expand Down Expand Up @@ -544,7 +541,7 @@ async def api_mode_at_commands(self, baudrate):
if not await self.command_mode_at_cmd(cmd + "\r"):
LOGGER.debug("No response to %s cmd", cmd)
return None
LOGGER.debug("Successfuly sent %s cmd", cmd)
LOGGER.debug("Successfully sent %s cmd", cmd)
self._uart.reset_command_mode()
return True

Expand All @@ -569,10 +566,8 @@ async def init_api_mode(self):
return res

LOGGER.debug(
(
"Couldn't enter AT command mode at any known baudrate."
"Configure XBee manually for escaped API mode ATAP2"
)
"Couldn't enter AT command mode at any known baudrate."
"Configure XBee manually for escaped API mode ATAP2"
)
return False

Expand Down Expand Up @@ -609,4 +604,4 @@ async def _probe(self) -> None:
def __getattr__(self, item):
if item in COMMAND_REQUESTS:
return functools.partial(self._command, item)
raise AttributeError("Unknown command {}".format(item))
raise AttributeError(f"Unknown command {item}")
4 changes: 2 additions & 2 deletions zigpy_xbee/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ class FrameId(uint8_t):

class NWK(uint16_t):
def __repr__(self):
return "0x{:04x}".format(self)
return f"0x{self:04x}"

def __str__(self):
return "0x{:04x}".format(self)
return f"0x{self:04x}"


class Relays(zigpy.types.LVList, item_type=NWK, length_type=uint8_t):
Expand Down
2 changes: 1 addition & 1 deletion zigpy_xbee/uart.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def baudrate(self, baudrate):
self._transport.serial.baudrate = baudrate
else:
raise ValueError(
"baudrate must be one of {}".format(self._transport.serial.BAUDRATES)
f"baudrate must be one of {self._transport.serial.BAUDRATES}"
)

def connection_lost(self, exc) -> None:
Expand Down
1 change: 0 additions & 1 deletion zigpy_xbee/zigbee/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ async def energy_scan(

async def force_remove(self, dev):
"""Forcibly remove device from NCP."""
pass

async def add_endpoint(self, descriptor: zdo_t.SimpleDescriptor) -> None:
"""Register a new endpoint on the device."""
Expand Down