Skip to content

Commit 09917f1

Browse files
authored
Update .pre-commit-config.yaml (#155)
1 parent f85233f commit 09917f1

File tree

7 files changed

+49
-27
lines changed

7 files changed

+49
-27
lines changed

.pre-commit-config.yaml

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,54 @@
11
repos:
2+
- repo: https://github.com/asottile/pyupgrade
3+
rev: v3.3.1
4+
hooks:
5+
- id: pyupgrade
6+
args: [--py38-plus]
7+
8+
- repo: https://github.com/PyCQA/autoflake
9+
rev: v2.0.2
10+
hooks:
11+
- id: autoflake
12+
213
- repo: https://github.com/psf/black
3-
rev: 23.1.0
14+
rev: 23.3.0
415
hooks:
516
- id: black
617
args:
7-
- --safe
818
- --quiet
19+
- --safe
20+
921
- repo: https://github.com/pycqa/flake8
1022
rev: 6.0.0
1123
hooks:
1224
- id: flake8
1325
additional_dependencies:
1426
- Flake8-pyproject==1.2.3
27+
1528
- repo: https://github.com/PyCQA/isort
1629
rev: 5.12.0
1730
hooks:
1831
- id: isort
19-
- repo: https://github.com/pre-commit/pre-commit-hooks
20-
rev: v4.4.0
32+
33+
- repo: https://github.com/codespell-project/codespell
34+
rev: v2.2.4
35+
hooks:
36+
- id: codespell
37+
args:
38+
- --ignore-words-list=ser,nd,hass
39+
- --skip="./.*"
40+
- --quiet-level=2
41+
42+
- repo: https://github.com/pre-commit/mirrors-mypy
43+
rev: v1.3.0
44+
hooks:
45+
- id: mypy
46+
additional_dependencies:
47+
- zigpy
48+
49+
- repo: https://github.com/charliermarsh/ruff-pre-commit
50+
rev: v0.0.261
2151
hooks:
22-
- id: no-commit-to-branch
52+
- id: ruff
2353
args:
24-
- --branch=dev
25-
- --branch=master
26-
- --branch=rc
54+
- --fix

tests/test_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def test_frame_received(api, monkeypatch):
234234
cmd_id = cmd_opts[0]
235235
payload = b"\x01\x02\x03\x04"
236236
data = cmd_id.to_bytes(1, "big") + payload
237-
setattr(api, "_handle_{}".format(cmd), my_handler)
237+
setattr(api, f"_handle_{cmd}", my_handler)
238238
api.frame_received(data)
239239
assert t.deserialize.call_count == 1
240240
assert t.deserialize.call_args[0][0] == payload
@@ -268,7 +268,7 @@ def test_frame_received_no_handler(api, monkeypatch):
268268

269269

270270
def _handle_at_response(api, tsn, status, at_response=b""):
271-
data = (tsn, "AI".encode("ascii"), status, at_response)
271+
data = (tsn, b"AI", status, at_response)
272272
response = asyncio.Future()
273273
api._awaiting[tsn] = (response,)
274274
api._handle_at_response(*data)

tests/test_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_bytes_deserialize():
3636

3737

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

zigpy_xbee/api.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ class ModemStatus(t.uint8_t, t.UndefinedEnum):
217217
"RE": None,
218218
"FR": None,
219219
"NR": t.Bool,
220-
"SI": None,
221220
"CB": t.uint8_t,
222221
"ND": t, # "optional 2-Byte NI value"
223222
"DN": t.Bytes, # "up to 20-Byte printable ASCII string"
@@ -407,7 +406,7 @@ def frame_received(self, data):
407406
LOGGER.debug("Frame received: %s", command)
408407
data, rest = t.deserialize(data[1:], COMMAND_RESPONSES[command][1])
409408
try:
410-
getattr(self, "_handle_%s" % (command,))(*data)
409+
getattr(self, f"_handle_{command}")(*data)
411410
except AttributeError:
412411
LOGGER.error("No '%s' handler. Data: %s", command, binascii.hexlify(data))
413412

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

421420
if status:
422-
fut.set_exception(
423-
RuntimeError("AT Command response: {}".format(status.name))
424-
)
421+
fut.set_exception(RuntimeError(f"AT Command response: {status.name}"))
425422
return
426423

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

@@ -544,7 +541,7 @@ async def api_mode_at_commands(self, baudrate):
544541
if not await self.command_mode_at_cmd(cmd + "\r"):
545542
LOGGER.debug("No response to %s cmd", cmd)
546543
return None
547-
LOGGER.debug("Successfuly sent %s cmd", cmd)
544+
LOGGER.debug("Successfully sent %s cmd", cmd)
548545
self._uart.reset_command_mode()
549546
return True
550547

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

571568
LOGGER.debug(
572-
(
573-
"Couldn't enter AT command mode at any known baudrate."
574-
"Configure XBee manually for escaped API mode ATAP2"
575-
)
569+
"Couldn't enter AT command mode at any known baudrate."
570+
"Configure XBee manually for escaped API mode ATAP2"
576571
)
577572
return False
578573

@@ -609,4 +604,4 @@ async def _probe(self) -> None:
609604
def __getattr__(self, item):
610605
if item in COMMAND_REQUESTS:
611606
return functools.partial(self._command, item)
612-
raise AttributeError("Unknown command {}".format(item))
607+
raise AttributeError(f"Unknown command {item}")

zigpy_xbee/types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ class FrameId(uint8_t):
155155

156156
class NWK(uint16_t):
157157
def __repr__(self):
158-
return "0x{:04x}".format(self)
158+
return f"0x{self:04x}"
159159

160160
def __str__(self):
161-
return "0x{:04x}".format(self)
161+
return f"0x{self:04x}"
162162

163163

164164
class Relays(zigpy.types.LVList, item_type=NWK, length_type=uint8_t):

zigpy_xbee/uart.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def baudrate(self, baudrate):
4545
self._transport.serial.baudrate = baudrate
4646
else:
4747
raise ValueError(
48-
"baudrate must be one of {}".format(self._transport.serial.BAUDRATES)
48+
f"baudrate must be one of {self._transport.serial.BAUDRATES}"
4949
)
5050

5151
def connection_lost(self, exc) -> None:

zigpy_xbee/zigbee/application.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ async def energy_scan(
187187

188188
async def force_remove(self, dev):
189189
"""Forcibly remove device from NCP."""
190-
pass
191190

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

0 commit comments

Comments
 (0)