diff --git a/switchbot/adv_parser.py b/switchbot/adv_parser.py index fa7e9a8..435c7d4 100644 --- a/switchbot/adv_parser.py +++ b/switchbot/adv_parser.py @@ -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 @@ -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, }, } diff --git a/switchbot/adv_parsers/relay_switch.py b/switchbot/adv_parsers/relay_switch.py index fb631f6..4b3a0f4 100644 --- a/switchbot/adv_parsers/relay_switch.py +++ b/switchbot/adv_parsers/relay_switch.py @@ -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.""" diff --git a/switchbot/const.py b/switchbot/const.py index b01f844..a2581d6 100644 --- a/switchbot/const.py +++ b/switchbot/const.py @@ -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): diff --git a/tests/test_adv_parser.py b/tests/test_adv_parser.py index b922e6e..1ca3997 100644 --- a/tests/test_adv_parser.py +++ b/tests/test_adv_parser.py @@ -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, + )