Skip to content

Commit

Permalink
Also test Python 3.12, improve typing, use debug logger for connection
Browse files Browse the repository at this point in the history
timeout
  • Loading branch information
sopelj committed Nov 1, 2023
1 parent f05a4dc commit e502c00
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 117 deletions.
16 changes: 8 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
---
repos:
- repo: https://github.com/asottile/add-trailing-comma
rev: v2.4.0
rev: v3.1.0
hooks:
- id: add-trailing-comma
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.1
rev: v1.5.4
hooks:
- id: forbid-crlf
- id: remove-crlf
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -21,16 +21,16 @@ repos:
- id: check-case-conflict
- id: trailing-whitespace
- repo: https://github.com/ambv/black
rev: 23.3.0
rev: 23.10.1
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.270
rev: v0.1.3
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.3.0
rev: v1.6.1
hooks:
- id: mypy
args:
Expand All @@ -43,11 +43,11 @@ repos:
- bleak-retry-connector
- pytest-asyncio
- repo: https://github.com/adrienverge/yamllint
rev: 'v1.31.0'
rev: 'v1.32.0'
hooks:
- id: yamllint
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.34.0
rev: v0.37.0
hooks:
- id: markdownlint-fix
args: [--disable, MD013]
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## [0.8.2]

### Added

* Tests for Python 3.12

### Changed

* Use debug level for connection timeout logger instead or error

## [0.8.1]

### Changed
Expand Down
6 changes: 4 additions & 2 deletions ember_mug/cli/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import re
import sys
from argparse import ArgumentParser, ArgumentTypeError, FileType, Namespace
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, ClassVar

from bleak import BleakError

Expand All @@ -19,6 +19,8 @@
from .helpers import CommandLoop, print_changes, print_info, print_table, validate_mac

if TYPE_CHECKING:
from collections.abc import Awaitable, Callable

from bleak.backends.device import BLEDevice

all_attrs = list(ATTR_LABELS) + list(EXTRA_ATTRS)
Expand Down Expand Up @@ -160,7 +162,7 @@ def colour_type(value: str) -> Colour:
class EmberMugCli:
"""Very simple CLI Interface to interact with a mug."""

_commands = {
_commands: ClassVar[dict[str, Callable[[Namespace], Awaitable]]] = {
"find": find_device,
"discover": discover,
"info": fetch_info,
Expand Down
2 changes: 1 addition & 1 deletion ember_mug/cli/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def print_table(data: list[tuple[str, ...]]) -> None:
def print_info(mug: EmberMug) -> None:
"""Print all mug data."""
print("Mug Data")
print_table([(k, v) for (k, v) in mug.data.formatted.items()])
print_table(list(mug.data.formatted.items()))


def print_changes(changes: list[Change], metric: bool = True) -> None:
Expand Down
2 changes: 1 addition & 1 deletion ember_mug/mug.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ async def _ensure_connection(self) -> None:
await discover_services(client)
self._expected_disconnect = False
except (asyncio.TimeoutError, BleakError) as error:
logger.error("%s: Failed to connect to the mug: %s", self.device, error)
logger.debug("%s: Failed to connect to the mug: %s", self.device, error)
raise error
# Attempt to pair for good measure
try:
Expand Down
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ test = [
"pytest>=7.2.1",
"pytest-cov",
"pytest-asyncio",
"aiohttp==3.9.0b0",
]
docs = [
"mkdocs>=1.1.21",
Expand Down Expand Up @@ -61,13 +62,13 @@ packages = ["ember_mug", "tests"]
exclude = [".gitignore"]

[tool.hatch.envs.default]
python = "3.11"
python = "3.12"

[tool.hatch.envs.test]
features = ["test"]

[[tool.hatch.envs.test.matrix]]
python = ["3.10", "3.11"]
python = ["3.10", "3.11", "3.12"]

[tool.hatch.envs.test.scripts]
cov = "pytest --asyncio-mode=auto --cov=ember_mug --cov-branch --cov-report=xml --cov-report=term-missing tests"
Expand All @@ -83,7 +84,7 @@ serve = "mkdocs serve --dev-addr localhost:8000"
[tool.black]
line-length = 120
skip-string-normalization = true
target-version = ['py310', 'py311']
target-version = ['py310', 'py311', 'py312']
include = '\.pyi?$'
exclude = '''
/(
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from collections.abc import AsyncGenerator, Generator
from unittest.mock import AsyncMock, MagicMock
from collections.abc import AsyncGenerator
from unittest.mock import AsyncMock, MagicMock, Mock

import pytest
import pytest_asyncio
Expand Down Expand Up @@ -41,7 +41,7 @@ def mug_data(ble_device: BLEDevice) -> MugData:


@pytest_asyncio.fixture
async def ember_mug(ble_device: BLEDevice) -> AsyncGenerator[EmberMug | AsyncMock, None]:
async def ember_mug(ble_device: BLEDevice) -> AsyncGenerator[EmberMug | Mock, None]:
mug = EmberMug(ble_device)
mug._client = AsyncMock()
yield mug
Loading

0 comments on commit e502c00

Please sign in to comment.