Skip to content

Commit 02174ed

Browse files
Add press function for garage door opener (#365)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent c59ef80 commit 02174ed

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

switchbot/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@
3232
from .devices.bulb import SwitchbotBulb
3333
from .devices.ceiling_light import SwitchbotCeilingLight
3434
from .devices.curtain import SwitchbotCurtain
35-
from .devices.device import SwitchbotDevice, SwitchbotEncryptedDevice
35+
from .devices.device import (
36+
SwitchbotDevice,
37+
SwitchbotEncryptedDevice,
38+
SwitchbotOperationError,
39+
)
3640
from .devices.evaporative_humidifier import SwitchbotEvaporativeHumidifier
3741
from .devices.fan import SwitchbotFan
3842
from .devices.humidifier import SwitchbotHumidifier
@@ -78,6 +82,7 @@
7882
"SwitchbotLock",
7983
"SwitchbotModel",
8084
"SwitchbotModel",
85+
"SwitchbotOperationError",
8186
"SwitchbotPlugMini",
8287
"SwitchbotPlugMini",
8388
"SwitchbotRelaySwitch",

switchbot/devices/device.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class SwitchbotBaseDevice:
127127

128128
_turn_on_command: str | None = None
129129
_turn_off_command: str | None = None
130+
_press_command: str | None = None
130131

131132
def __init__(
132133
self,
@@ -718,6 +719,13 @@ async def turn_off(self) -> bool:
718719
result = await self._send_command(self._turn_off_command)
719720
return self._check_command_result(result, 0, {1})
720721

722+
@update_after_operation
723+
async def press(self) -> bool:
724+
"""Press the device."""
725+
self._check_function_support(self._press_command)
726+
result = await self._send_command(self._press_command)
727+
return self._check_command_result(result, 0, {1})
728+
721729

722730
class SwitchbotDevice(SwitchbotBaseDevice):
723731
"""

switchbot/devices/relay_switch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class SwitchbotRelaySwitch(SwitchbotSequenceDevice, SwitchbotEncryptedDevice):
6161

6262
_turn_on_command = f"{COMMAND_CONTROL}010100"
6363
_turn_off_command = f"{COMMAND_CONTROL}010000"
64+
_press_command = f"{COMMAND_CONTROL}110329" # for garage door opener toggle
6465

6566
def __init__(
6667
self,

tests/test_relay_switch.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,3 +451,14 @@ def test_merge_data(old_data, new_data, expected_result):
451451
"""Test merging of data dictionaries."""
452452
result = merge_data(old_data, new_data)
453453
assert result == expected_result
454+
455+
456+
@pytest.mark.asyncio
457+
async def test_press():
458+
"""Test the press command for garage door opener."""
459+
device = create_device_for_command_testing(
460+
b">\x00\x00\x00", SwitchbotModel.GARAGE_DOOR_OPENER
461+
)
462+
463+
await device.press()
464+
device._send_command.assert_awaited_once_with(device._press_command)

0 commit comments

Comments
 (0)