Skip to content

Commit 8870e27

Browse files
Add support for WoRemote (#294)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 9a1dd50 commit 8870e27

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

switchbot/adv_parser.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
process_worelay_switch_1,
3030
process_worelay_switch_1pm,
3131
)
32+
from .adv_parsers.remote import process_woremote
3233
from .const import SwitchbotModel
3334
from .models import SwitchBotAdvertisement
3435

@@ -203,6 +204,12 @@ class SwitchbotSupportedType(TypedDict):
203204
"func": process_worelay_switch_1,
204205
"manufacturer_id": 2409,
205206
},
207+
"b": {
208+
"modelName": SwitchbotModel.REMOTE,
209+
"modelFriendlyName": "Remote",
210+
"func": process_woremote,
211+
"manufacturer_id": 89,
212+
},
206213
}
207214

208215
_SWITCHBOT_MODEL_TO_CHAR = {

switchbot/adv_parsers/remote.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""Remote adv parser."""
2+
3+
from __future__ import annotations
4+
5+
import logging
6+
7+
_LOGGER = logging.getLogger(__name__)
8+
9+
10+
def process_woremote(
11+
data: bytes | None, mfr_data: bytes | None
12+
) -> dict[str, int | None]:
13+
"""Process WoRemote adv data."""
14+
15+
if data is None:
16+
return {
17+
"battery": None,
18+
}
19+
20+
_LOGGER.debug("data: %s", data.hex())
21+
22+
return {
23+
"battery": data[2] & 0b01111111,
24+
}

switchbot/const.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class SwitchbotModel(StrEnum):
5757
KEYPAD = "WoKeypad"
5858
RELAY_SWITCH_1PM = "Relay Switch 1PM"
5959
RELAY_SWITCH_1 = "Relay Switch 1"
60+
REMOTE = "WoRemote"
6061

6162

6263
class LockStatus(Enum):

tests/test_adv_parser.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,3 +1917,55 @@ def test_leak_real_data_from_ha():
19171917
rssi=-73,
19181918
active=True,
19191919
)
1920+
1921+
1922+
def test_remote_active() -> None:
1923+
ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")
1924+
adv_data = generate_advertisement_data(
1925+
manufacturer_data={89: b"\xaa\xbb\xcc\xdd\xee\xff"},
1926+
service_data={"00000d00-0000-1000-8000-00805f9b34fb": b"b V\x00"},
1927+
service_uuids=["cba20d00-224d-11e6-9fb8-0002a5d5c51b"],
1928+
rssi=-95,
1929+
)
1930+
result = parse_advertisement_data(ble_device, adv_data)
1931+
assert result == SwitchBotAdvertisement(
1932+
address="aa:bb:cc:dd:ee:ff",
1933+
data={
1934+
"data": {
1935+
"battery": 86,
1936+
},
1937+
"isEncrypted": False,
1938+
"model": "b",
1939+
"modelFriendlyName": "Remote",
1940+
"modelName": SwitchbotModel.REMOTE,
1941+
"rawAdvData": b"b V\x00",
1942+
},
1943+
device=ble_device,
1944+
rssi=-95,
1945+
active=True,
1946+
)
1947+
1948+
1949+
def test_remote_passive() -> None:
1950+
ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")
1951+
adv_data = generate_advertisement_data(
1952+
manufacturer_data={89: b"\xaa\xbb\xcc\xdd\xee\xff"},
1953+
rssi=-97,
1954+
)
1955+
result = parse_advertisement_data(ble_device, adv_data, SwitchbotModel.REMOTE)
1956+
assert result == SwitchBotAdvertisement(
1957+
address="aa:bb:cc:dd:ee:ff",
1958+
data={
1959+
"data": {
1960+
"battery": None,
1961+
},
1962+
"isEncrypted": False,
1963+
"model": "b",
1964+
"modelFriendlyName": "Remote",
1965+
"modelName": SwitchbotModel.REMOTE,
1966+
"rawAdvData": None,
1967+
},
1968+
device=ble_device,
1969+
rssi=-97,
1970+
active=False,
1971+
)

0 commit comments

Comments
 (0)