Browse Source

feat: expose get_device api (#106)

J. Nick Koston 1 year ago
parent
commit
6159f90e74
4 changed files with 11 additions and 3 deletions
  1. 1 1
      setup.py
  2. 3 0
      switchbot/__init__.py
  3. 1 1
      switchbot/adv_parser.py
  4. 6 1
      switchbot/devices/device.py

+ 1 - 1
setup.py

@@ -3,7 +3,7 @@ from setuptools import setup
 setup(
     name="PySwitchbot",
     packages=["switchbot", "switchbot.devices", "switchbot.adv_parsers"],
-    install_requires=["async_timeout>=4.0.1", "bleak", "bleak-retry-connector>=1.11.0"],
+    install_requires=["async_timeout>=4.0.1", "bleak", "bleak-retry-connector>=1.12.2"],
     version="0.19.1",
     description="A library to communicate with Switchbot",
     author="Daniel Hjelseth Hoyer",

+ 3 - 0
switchbot/__init__.py

@@ -1,6 +1,8 @@
 """Library to handle connection with Switchbot."""
 from __future__ import annotations
 
+from bleak_retry_connector import get_device
+
 from .adv_parser import SwitchbotSupportedType, parse_advertisement_data
 from .const import SwitchbotModel
 from .devices.base_light import SwitchbotBaseLight
@@ -16,6 +18,7 @@ from .discovery import GetSwitchbotDevices
 from .models import SwitchBotAdvertisement
 
 __all__ = [
+    "get_device",
     "parse_advertisement_data",
     "GetSwitchbotDevices",
     "SwitchBotAdvertisement",

+ 1 - 1
switchbot/adv_parser.py

@@ -1,9 +1,9 @@
 """Library to handle connection with Switchbot."""
 from __future__ import annotations
-from functools import lru_cache
 
 import logging
 from collections.abc import Callable
+from functools import lru_cache
 from typing import TypedDict
 
 from bleak.backends.device import BLEDevice

+ 6 - 1
switchbot/devices/device.py

@@ -37,7 +37,12 @@ DEVICE_SET_EXTENDED_KEY = REQ_HEADER
 # Base key when encryption is set
 KEY_PASSWORD_PREFIX = "571"
 
-BLEAK_EXCEPTIONS = (AttributeError, BleakError, EOFError, asyncio.exceptions.TimeoutError)
+BLEAK_EXCEPTIONS = (
+    AttributeError,
+    BleakError,
+    EOFError,
+    asyncio.exceptions.TimeoutError,
+)
 
 # How long to hold the connection
 # to wait for additional commands for