Skip to content

Commit 433b2c3

Browse files
authored
Add basic pre-commit checks (#197)
1 parent fe60bca commit 433b2c3

File tree

7 files changed

+61
-7
lines changed

7 files changed

+61
-7
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,6 @@ cython_debug/
165165
.DS_Store
166166
credentials/
167167
venv39/
168+
169+
# ruff
170+
.ruff_cache/

.pre-commit-config.yaml

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
repos:
4+
- repo: https://github.com/psf/black
5+
rev: 23.1.0
6+
hooks:
7+
- id: black
8+
args:
9+
- --quiet
10+
files: ^(matter_server|scripts)/.+\.py$
11+
- repo: https://github.com/codespell-project/codespell
12+
rev: v2.2.2
13+
hooks:
14+
- id: codespell
15+
args: []
16+
exclude_types: [csv, json]
17+
exclude: ^tests/fixtures/
18+
- repo: https://github.com/PyCQA/flake8
19+
rev: 6.0.0
20+
hooks:
21+
- id: flake8
22+
files: ^(matter_server|scripts)/.+\.py$
23+
- repo: https://github.com/PyCQA/isort
24+
rev: 5.12.0
25+
hooks:
26+
- id: isort
27+
files: ^(matter_server|scripts)/.+\.py$
28+
- repo: https://github.com/pre-commit/pre-commit-hooks
29+
rev: v4.4.0
30+
hooks:
31+
- id: no-commit-to-branch
32+
args:
33+
- --branch=main
34+
- id: trailing-whitespace
35+
# - repo: local
36+
# hooks:
37+
# - id: mypy
38+
# name: mypy
39+
# entry: mypy
40+
# types: [python]
41+
# language: script
42+
# files: ^(matter_server)/.+\.py$
43+
# require_serial: true
44+
# - id: pylint
45+
# name: pylint
46+
# entry: pylint -j 0
47+
# types: [python]
48+
# language: script
49+
# files: ^(matter_server)/.+\.py$
50+
# require_serial: true

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ The server runs a Matter Controller and includes all logic for storing node info
3939

4040
### Test devices
4141

42-
Now that the Matter Specification is offically released in its 1.0 version, devices will be available in stores from 2023 that actually have Matter support or least manufacturers run a beta program which you can join to run Matter firmware on your device. Please refer to the documentation of your device if its already Matter enabled out of the box or you need to enable some special firmware(mode).
42+
Now that the Matter Specification is officially released in its 1.0 version, devices will be available in stores from 2023 that actually have Matter support or least manufacturers run a beta program which you can join to run Matter firmware on your device. Please refer to the documentation of your device if its already Matter enabled out of the box or you need to enable some special firmware(mode).
4343

4444
Besides that it is possible to run Matter firmware on common microcontrollers such as the ESP32 and there is even a whole device emulator available which runs on a regular desktop OS. To make things easier we've prepared a [special page](https://nabucasa.github.io/matter-example-apps) where you can quickly try out running the Matter example apps on ESP32.
4545

@@ -76,7 +76,7 @@ Inform the controller about the Thread credentials it needs to use when commissi
7676

7777
**Commission with code**
7878
Commission a new device. For WiFi or Thread based devices, the credentials need to be set upfront, otherwise commisisoning will fail.
79-
The controller will use bluetooth for the commissioning of wireless devices. If the machine running the Python Matter Server controller lacks bluetooth support, comissioning will only work for devices already connected to the network (by cable or another controller).
79+
The controller will use bluetooth for the commissioning of wireless devices. If the machine running the Python Matter Server controller lacks bluetooth support, commissioning will only work for devices already connected to the network (by cable or another controller).
8080

8181
```
8282
{

matter_server/common/helpers/util.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141

4242
try:
4343
# python 3.10
44-
from types import NoneType, UnionType # type: ignore[attr-defined]
45-
except: # noqa
44+
from types import NoneType, UnionType # type:ignore[attr-defined]
45+
except ImportError: # noqa
4646
# older python version
4747
NoneType = type(None)
4848
UnionType = type(Union)

matter_server/common/models/node.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def _get_attr_value(attr_name: str) -> str:
189189
return attr_name[:1].lower() + attr_name[1:]
190190

191191
# instantiate a Cluster object from the properties
192-
# TODO: find another way to do this without loosing the individual cluster attributes
192+
# TODO: find another way to do this without losing the individual cluster attributes
193193
# pylint: disable=import-outside-toplevel
194194
from ..helpers.util import dataclass_from_dict
195195

matter_server/server/client_handler.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ class WebSocketLogAdapter(logging.LoggerAdapter):
4242

4343
def process(self, msg: str, kwargs: Any) -> tuple[str, Any]:
4444
"""Add connid to websocket log messages."""
45-
return f'[{self.extra["connid"]}] {msg}', kwargs
45+
assert self.extra is not None
46+
return f"[{self.extra['connid']}] {msg}", kwargs
4647

4748

4849
class WebsocketClientHandler:

matter_server/server/device_controller.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ def _parse_attributes_from_read_result(
443443
result = {}
444444
for endpoint, cluster_dict in attributes.items():
445445
# read result output is in format {endpoint: {ClusterClass: {AttributeClass: value}}}
446-
# we parse this to our own much more useable format
446+
# we parse this to our own much more usable format
447447
for cluster_cls, attr_dict in cluster_dict.items():
448448
for attr_cls, attr_value in attr_dict.items():
449449
if attr_cls == Attribute.DataVersion:

0 commit comments

Comments
 (0)