Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
greyeee committed Nov 25, 2024
1 parent 33226d3 commit 57b7050
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 5 deletions.
6 changes: 3 additions & 3 deletions switchbot/adv_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from .adv_parsers.motion import process_wopresence
from .adv_parsers.plug import process_woplugmini
from .adv_parsers.relay_switch import (
process_worelay_switch_1plus,
process_worelay_switch_1,
process_worelay_switch_1pm,
)
from .const import SwitchbotModel
Expand Down Expand Up @@ -191,9 +191,9 @@ class SwitchbotSupportedType(TypedDict):
"manufacturer_id": 2409,
},
";": {
"modelName": SwitchbotModel.RELAY_SWITCH_1_PLUS,
"modelName": SwitchbotModel.RELAY_SWITCH_1,
"modelFriendlyName": "Relay Switch 1",
"func": process_worelay_switch_1plus,
"func": process_worelay_switch_1,
"manufacturer_id": 2409,
},
}
Expand Down
2 changes: 1 addition & 1 deletion switchbot/adv_parsers/relay_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def process_worelay_switch_1pm(
}


def process_worelay_switch_1plus(
def process_worelay_switch_1(
data: bytes | None, mfr_data: bytes | None
) -> dict[str, bool | int]:
"""Process WoStrip services data."""
Expand Down
2 changes: 1 addition & 1 deletion switchbot/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class SwitchbotModel(StrEnum):
HUB2 = "WoHub2"
KEYPAD = "WoKeypad"
RELAY_SWITCH_1PM = "Relay Switch 1PM"
RELAY_SWITCH_1_PLUS = "Relay Switch 1"
RELAY_SWITCH_1 = "Relay Switch 1"


class LockStatus(Enum):
Expand Down
65 changes: 65 additions & 0 deletions tests/test_adv_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1672,3 +1672,68 @@ def test_parse_advertisement_data_keypad():
rssi=-67,
active=True,
)


def test_parse_advertisement_data_relay_switch_1pm():
"""Test parse_advertisement_data for the keypad."""
ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")
adv_data = generate_advertisement_data(
manufacturer_data={2409: b"$X|\x0866G\x81\x00\x00\x001\x00\x00\x00\x00"},
service_data={"0000fd3d-0000-1000-8000-00805f9b34fb": b"<\x00\x00\x00"},
rssi=-67,
)
result = parse_advertisement_data(
ble_device, adv_data, SwitchbotModel.RELAY_SWITCH_1PM
)
assert result == SwitchBotAdvertisement(
address="aa:bb:cc:dd:ee:ff",
data={
"data": {
"switchMode": True,
"sequence_number": 71,
"isOn": True,
"power": 4.9,
"voltage": 0,
"current": 0,
},
"isEncrypted": False,
"model": "<",
"modelFriendlyName": "Relay Switch 1PM",
"modelName": SwitchbotModel.RELAY_SWITCH_1PM,
"rawAdvData": b"<\x00\x00\x00",
},
device=ble_device,
rssi=-67,
active=True,
)


def test_parse_advertisement_data_relay_switch_1():
"""Test parse_advertisement_data for the keypad."""
ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")
adv_data = generate_advertisement_data(
manufacturer_data={2409: b"$X|\x0866G\x81\x00\x00\x001\x00\x00\x00\x00"},
service_data={"0000fd3d-0000-1000-8000-00805f9b34fb": b";\x00\x00\x00"},
rssi=-67,
)
result = parse_advertisement_data(
ble_device, adv_data, SwitchbotModel.RELAY_SWITCH_1
)
assert result == SwitchBotAdvertisement(
address="aa:bb:cc:dd:ee:ff",
data={
"data": {
"switchMode": True,
"sequence_number": 71,
"isOn": True,
},
"isEncrypted": False,
"model": ";",
"modelFriendlyName": "Relay Switch 1",
"modelName": SwitchbotModel.RELAY_SWITCH_1,
"rawAdvData": b";\x00\x00\x00",
},
device=ble_device,
rssi=-67,
active=True,
)

0 comments on commit 57b7050

Please sign in to comment.