python-ember-mug 1.4.0b1__tar.gz → 1.4.0b3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-ember-mug
3
- Version: 1.4.0b1
3
+ Version: 1.4.0b3
4
4
  Summary: Python Library for Ember Mugs.
5
5
  Project-URL: Changelog, https://sopelj.github.io/python-ember-mug/changelog/
6
6
  Project-URL: Documentation, https://sopelj.github.io/python-ember-mug/
@@ -18,8 +18,8 @@ Classifier: Programming Language :: Python :: 3.12
18
18
  Classifier: Programming Language :: Python :: 3.13
19
19
  Classifier: Programming Language :: Python :: 3.14
20
20
  Requires-Python: >=3.11
21
- Requires-Dist: bleak-retry-connector>=4.0.2
22
- Requires-Dist: bleak>=1.0.1
21
+ Requires-Dist: bleak-retry-connector>=4.6.0
22
+ Requires-Dist: bleak>=3.0.2
23
23
  Provides-Extra: dev
24
24
  Requires-Dist: ipython; extra == 'dev'
25
25
  Provides-Extra: docs
@@ -6,4 +6,4 @@ __all__ = ("EmberMug",)
6
6
 
7
7
  __author__ = """Jesse Sopel"""
8
8
  __email__ = "jesse@sopelj.ca"
9
- __version__ = "1.4.0b1"
9
+ __version__ = "1.4.0b3"
@@ -7,8 +7,9 @@ import contextlib
7
7
  import logging
8
8
  import re
9
9
  import sys
10
- from argparse import ArgumentParser, ArgumentTypeError, FileType, Namespace
11
- from typing import TYPE_CHECKING, ClassVar
10
+ from argparse import ArgumentParser, ArgumentTypeError, Namespace
11
+ from pathlib import Path
12
+ from typing import IO, TYPE_CHECKING, ClassVar
12
13
 
13
14
  from bleak import BleakError
14
15
 
@@ -216,9 +217,8 @@ class EmberMugCli:
216
217
  )
217
218
  self.parser.add_argument(
218
219
  "--log-file",
219
- type=FileType("w", encoding="utf-8"),
220
+ type=Path,
220
221
  nargs="?",
221
- default=sys.stdout,
222
222
  help="File to write logs too (Will be overwritten)",
223
223
  )
224
224
  self.parser.add_argument("--version", action="version", version=__version__)
@@ -256,12 +256,23 @@ class EmberMugCli:
256
256
  async def run(self) -> None:
257
257
  """Run the specified command based on subparser."""
258
258
  args = self.parser.parse_args()
259
+ out_file: IO[str] | None = None
259
260
  if IS_LINUX is False:
260
261
  args.adapter = None # Set for other platforms
261
262
  if args.debug:
263
+ if args.log_file:
264
+ try:
265
+ out_file = args.log_file.open("w")
266
+ except OSError as e:
267
+ self.parser.error(f"Failed to open '{args.log_file}': {e}")
268
+
262
269
  logging.basicConfig(
263
- stream=args.log_file,
270
+ stream=out_file or sys.stdout,
264
271
  level=logging.DEBUG,
265
272
  format="[%(asctime)s] %(levelname)s [%(filename)s.%(funcName)s:%(lineno)d] %(message)s",
266
273
  )
267
- await self._commands[args.command](args)
274
+ try:
275
+ await self._commands[args.command](args)
276
+ finally:
277
+ if out_file is not None:
278
+ out_file.close()
@@ -435,9 +435,19 @@ class EmberMug:
435
435
  """Update a list of attributes from the mug."""
436
436
  logger.debug("Updating the following attributes: %s", attrs)
437
437
  await self._ensure_connection()
438
- changes = self.data.update_info(**{attr: await getattr(self, f"get_{attr}")() for attr in attrs})
438
+ updates = {}
439
+ failed_attrs = set()
440
+ for attr in attrs:
441
+ try:
442
+ updates[attr] = await getattr(self, f"get_{attr}")()
443
+ except BleakError as e:
444
+ failed_attrs |= {attr}
445
+ logger.debug("Failed to fetch %s: %s", attr, e)
446
+ changes = self.data.update_info(**updates)
439
447
  if changes:
440
448
  self._fire_callbacks()
449
+ if failed_attrs:
450
+ logger.warning("Failed to fetch some attributes: %s", failed_attrs)
441
451
  logger.debug("Attributes updated: %s", changes)
442
452
  return changes
443
453
 
@@ -5,7 +5,7 @@ from __future__ import annotations
5
5
  import asyncio
6
6
  import contextlib
7
7
  import logging
8
- from typing import TYPE_CHECKING, cast
8
+ from typing import TYPE_CHECKING
9
9
 
10
10
  from bleak import BleakScanner
11
11
 
@@ -14,13 +14,14 @@ from .consts import DEVICE_SERVICE_UUIDS, IS_LINUX
14
14
  if TYPE_CHECKING:
15
15
  from typing import NotRequired, TypedDict
16
16
 
17
+ from bleak import BlueZScannerArgs
17
18
  from bleak.backends.device import BLEDevice
18
19
  from bleak.backends.scanner import AdvertisementData
19
20
 
20
- class ScannerKwargs(TypedDict):
21
+ class BleakScannerKwargs(TypedDict):
21
22
  """Optional kwargs for scanner."""
22
23
 
23
- adapter: NotRequired[str]
24
+ bluez: NotRequired[BlueZScannerArgs]
24
25
  service_uuids: NotRequired[list[str]]
25
26
 
26
27
 
@@ -29,13 +30,17 @@ DEFAULT_TIMEOUT = 30
29
30
  logger = logging.getLogger(__name__)
30
31
 
31
32
 
32
- def build_scanner_kwargs(adapter: str | None = None, *, service_uuids: list[str] | None = None) -> ScannerKwargs:
33
+ def build_scanner_kwargs(adapter: str | None = None, *, service_uuids: list[str] | None = None) -> BleakScannerKwargs:
33
34
  """Add Adapter to kwargs for scanner if specified and using BlueZ."""
34
35
  if adapter and IS_LINUX is not True:
35
36
  msg = "The adapter option is only valid for the Linux BlueZ Backend."
36
37
  raise ValueError(msg)
37
- kwargs = {"service_uuids": service_uuids} if service_uuids else {}
38
- return cast("ScannerKwargs", kwargs | {"adapter": adapter} if adapter else kwargs)
38
+ kwargs: BleakScannerKwargs = {}
39
+ if service_uuids:
40
+ kwargs |= {"service_uuids": service_uuids}
41
+ if adapter:
42
+ kwargs |= {"bluez": {"adapter": adapter}}
43
+ return kwargs
39
44
 
40
45
 
41
46
  async def discover_devices(
@@ -17,8 +17,8 @@ classifiers = [
17
17
  'Programming Language :: Python :: 3.14',
18
18
  ]
19
19
  dependencies = [
20
- "bleak-retry-connector>=4.0.2",
21
- "bleak>=1.0.1",
20
+ "bleak-retry-connector>=4.6.0",
21
+ "bleak>=3.0.2",
22
22
  ]
23
23
 
24
24
  [project.optional-dependencies]
@@ -76,7 +76,7 @@ features = ["test"]
76
76
 
77
77
  [[tool.hatch.envs.test.matrix]]
78
78
  python = ["3.11", "3.12", "3.13", "3.14"]
79
- bleak = ["1.0.1", "2.0.0", "3.0.2"]
79
+ bleak = ["3.0.2"]
80
80
 
81
81
  [tool.hatch.envs.test.scripts]
82
82
  cov = "pytest -vvv --asyncio-mode=auto --cov=ember_mug --cov-branch --cov-report=xml --cov-report=term-missing tests"