4 Commits c59ef80bc9 ... 547befdb1d

Author SHA1 Message Date
  J. Nick Koston 547befdb1d Release 0.68.0 (#367) 1 week ago
  pre-commit-ci[bot] 2fb9a18a16 chore(pre-commit.ci): pre-commit autoupdate (#364) 1 week ago
  J. Nick Koston bf4139e037 Remove rssi call on the BLEDevice (#366) 1 week ago
  Retha Runolfsson 02174ed12c Add press function for garage door opener (#365) 1 week ago

+ 1 - 1
.pre-commit-config.yaml

@@ -38,7 +38,7 @@ repos:
       - id: pyupgrade
         args: [--py311-plus]
   - repo: https://github.com/astral-sh/ruff-pre-commit
-    rev: v0.12.0
+    rev: v0.12.1
     hooks:
       - id: ruff
         args: [--fix]

+ 1 - 1
setup.py

@@ -20,7 +20,7 @@ setup(
         "cryptography>=39.0.0",
         "pyOpenSSL>=23.0.0",
     ],
-    version="0.67.0",
+    version="0.68.0",
     description="A library to communicate with Switchbot",
     long_description=long_description,
     long_description_content_type="text/markdown",

+ 6 - 1
switchbot/__init__.py

@@ -32,7 +32,11 @@ from .devices.bot import Switchbot
 from .devices.bulb import SwitchbotBulb
 from .devices.ceiling_light import SwitchbotCeilingLight
 from .devices.curtain import SwitchbotCurtain
-from .devices.device import SwitchbotDevice, SwitchbotEncryptedDevice
+from .devices.device import (
+    SwitchbotDevice,
+    SwitchbotEncryptedDevice,
+    SwitchbotOperationError,
+)
 from .devices.evaporative_humidifier import SwitchbotEvaporativeHumidifier
 from .devices.fan import SwitchbotFan
 from .devices.humidifier import SwitchbotHumidifier
@@ -78,6 +82,7 @@ __all__ = [
     "SwitchbotLock",
     "SwitchbotModel",
     "SwitchbotModel",
+    "SwitchbotOperationError",
     "SwitchbotPlugMini",
     "SwitchbotPlugMini",
     "SwitchbotRelaySwitch",

+ 9 - 1
switchbot/devices/device.py

@@ -127,6 +127,7 @@ class SwitchbotBaseDevice:
 
     _turn_on_command: str | None = None
     _turn_off_command: str | None = None
+    _press_command: str | None = None
 
     def __init__(
         self,
@@ -294,7 +295,7 @@ class SwitchbotBaseDevice:
         """Return RSSI of device."""
         if self._sb_adv_data:
             return self._sb_adv_data.rssi
-        return self._device.rssi
+        return -127
 
     async def _ensure_connected(self):
         """Ensure connection to device is established."""
@@ -718,6 +719,13 @@ class SwitchbotBaseDevice:
         result = await self._send_command(self._turn_off_command)
         return self._check_command_result(result, 0, {1})
 
+    @update_after_operation
+    async def press(self) -> bool:
+        """Press the device."""
+        self._check_function_support(self._press_command)
+        result = await self._send_command(self._press_command)
+        return self._check_command_result(result, 0, {1})
+
 
 class SwitchbotDevice(SwitchbotBaseDevice):
     """

+ 1 - 0
switchbot/devices/relay_switch.py

@@ -61,6 +61,7 @@ class SwitchbotRelaySwitch(SwitchbotSequenceDevice, SwitchbotEncryptedDevice):
 
     _turn_on_command = f"{COMMAND_CONTROL}010100"
     _turn_off_command = f"{COMMAND_CONTROL}010000"
+    _press_command = f"{COMMAND_CONTROL}110329"  # for garage door opener toggle
 
     def __init__(
         self,

+ 11 - 0
tests/test_relay_switch.py

@@ -451,3 +451,14 @@ def test_merge_data(old_data, new_data, expected_result):
     """Test merging of data dictionaries."""
     result = merge_data(old_data, new_data)
     assert result == expected_result
+
+
+@pytest.mark.asyncio
+async def test_press():
+    """Test the press command for garage door opener."""
+    device = create_device_for_command_testing(
+        b">\x00\x00\x00", SwitchbotModel.GARAGE_DOOR_OPENER
+    )
+
+    await device.press()
+    device._send_command.assert_awaited_once_with(device._press_command)