Skip to content

Commit 94882d3

Browse files
authored
Split constants per device (#303)
1 parent d8bf41d commit 94882d3

File tree

5 files changed

+22
-16
lines changed

5 files changed

+22
-16
lines changed

switchbot/adv_parsers/lock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import logging
66

7-
from ..const import LockStatus
7+
from ..const.lock import LockStatus
88

99
_LOGGER = logging.getLogger(__name__)
1010

switchbot/const.py renamed to switchbot/const/__init__.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
"""Library to handle connection with Switchbot."""
1+
"""Switchbot Device Consts Library."""
22

33
from __future__ import annotations
44

5-
from enum import Enum
5+
from ..enum import StrEnum
66

7-
from .enum import StrEnum
7+
# Preserve old LockStatus export for backwards compatibility
8+
from .lock import LockStatus as LockStatus
89

910
DEFAULT_RETRY_COUNT = 3
1011
DEFAULT_RETRY_TIMEOUT = 1
@@ -61,13 +62,3 @@ class SwitchbotModel(StrEnum):
6162
RELAY_SWITCH_1PM = "Relay Switch 1PM"
6263
RELAY_SWITCH_1 = "Relay Switch 1"
6364
REMOTE = "WoRemote"
64-
65-
66-
class LockStatus(Enum):
67-
LOCKED = 0
68-
UNLOCKED = 1
69-
LOCKING = 2
70-
UNLOCKING = 3
71-
LOCKING_STOP = 4 # LOCKING_BLOCKED
72-
UNLOCKING_STOP = 5 # UNLOCKING_BLOCKED
73-
NOT_FULLY_LOCKED = 6 # LATCH_LOCKED - Only EU lock type

switchbot/const/lock.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from __future__ import annotations
2+
3+
from enum import Enum
4+
5+
6+
class LockStatus(Enum):
7+
LOCKED = 0
8+
UNLOCKED = 1
9+
LOCKING = 2
10+
UNLOCKING = 3
11+
LOCKING_STOP = 4 # LOCKING_BLOCKED
12+
UNLOCKING_STOP = 5 # UNLOCKING_BLOCKED
13+
NOT_FULLY_LOCKED = 6 # LATCH_LOCKED - Only EU lock type

switchbot/devices/lock.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
from bleak.backends.device import BLEDevice
1010

11-
from ..const import LockStatus, SwitchbotModel
11+
from ..const import SwitchbotModel
12+
from ..const.lock import LockStatus
1213
from .device import SwitchbotEncryptedDevice
1314

1415
COMMAND_HEADER = "57"

tests/test_adv_parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
from bleak.backends.device import BLEDevice
66
from bleak.backends.scanner import AdvertisementData
77

8-
from switchbot import LockStatus, SwitchbotModel
8+
from switchbot import SwitchbotModel
99
from switchbot.adv_parser import parse_advertisement_data
10+
from switchbot.const.lock import LockStatus
1011
from switchbot.models import SwitchBotAdvertisement
1112

1213
ADVERTISEMENT_DATA_DEFAULTS = {

0 commit comments

Comments
 (0)