|
@@ -1,20 +1,18 @@
|
|
-import pytest
|
|
|
|
-
|
|
|
|
from typing import Any
|
|
from typing import Any
|
|
|
|
+from unittest.mock import Mock
|
|
|
|
|
|
|
|
+import pytest
|
|
from bleak.backends.device import BLEDevice
|
|
from bleak.backends.device import BLEDevice
|
|
|
|
|
|
from switchbot import SwitchBotAdvertisement, SwitchbotModel
|
|
from switchbot import SwitchBotAdvertisement, SwitchbotModel
|
|
from switchbot.devices import curtain
|
|
from switchbot.devices import curtain
|
|
|
|
|
|
-from test_adv_parser import generate_ble_device
|
|
|
|
-
|
|
|
|
-from unittest.mock import Mock
|
|
|
|
|
|
+from .test_adv_parser import generate_ble_device
|
|
|
|
|
|
|
|
|
|
def set_advertisement_data(ble_device: BLEDevice, in_motion: bool, position: int):
|
|
def set_advertisement_data(ble_device: BLEDevice, in_motion: bool, position: int):
|
|
"""Set advertisement data with defaults."""
|
|
"""Set advertisement data with defaults."""
|
|
-
|
|
|
|
|
|
+
|
|
return SwitchBotAdvertisement(
|
|
return SwitchBotAdvertisement(
|
|
address="aa:bb:cc:dd:ee:ff",
|
|
address="aa:bb:cc:dd:ee:ff",
|
|
data={
|
|
data={
|
|
@@ -37,71 +35,102 @@ def set_advertisement_data(ble_device: BLEDevice, in_motion: bool, position: int
|
|
active=True,
|
|
active=True,
|
|
)
|
|
)
|
|
|
|
|
|
-@pytest.mark.parametrize("reverse_mode", [(True),(False)])
|
|
|
|
|
|
+
|
|
|
|
+@pytest.mark.parametrize("reverse_mode", [(True), (False)])
|
|
def test_device_passive_not_in_motion(reverse_mode):
|
|
def test_device_passive_not_in_motion(reverse_mode):
|
|
"""Test passive not in motion advertisement."""
|
|
"""Test passive not in motion advertisement."""
|
|
ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")
|
|
ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")
|
|
curtain_device = curtain.SwitchbotCurtain(ble_device, reverse_mode=reverse_mode)
|
|
curtain_device = curtain.SwitchbotCurtain(ble_device, reverse_mode=reverse_mode)
|
|
- curtain_device.update_from_advertisement(set_advertisement_data(ble_device, False, 0))
|
|
|
|
|
|
+ curtain_device.update_from_advertisement(
|
|
|
|
+ set_advertisement_data(ble_device, False, 0)
|
|
|
|
+ )
|
|
|
|
|
|
assert curtain_device.is_opening() is False
|
|
assert curtain_device.is_opening() is False
|
|
assert curtain_device.is_closing() is False
|
|
assert curtain_device.is_closing() is False
|
|
|
|
|
|
-@pytest.mark.parametrize("reverse_mode", [(True),(False)])
|
|
|
|
|
|
+
|
|
|
|
+@pytest.mark.parametrize("reverse_mode", [(True), (False)])
|
|
def test_device_passive_opening(reverse_mode):
|
|
def test_device_passive_opening(reverse_mode):
|
|
"""Test passive opening advertisement."""
|
|
"""Test passive opening advertisement."""
|
|
ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")
|
|
ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")
|
|
curtain_device = curtain.SwitchbotCurtain(ble_device, reverse_mode=reverse_mode)
|
|
curtain_device = curtain.SwitchbotCurtain(ble_device, reverse_mode=reverse_mode)
|
|
- curtain_device.update_from_advertisement(set_advertisement_data(ble_device, True, 0))
|
|
|
|
- curtain_device.update_from_advertisement(set_advertisement_data(ble_device, True, 10))
|
|
|
|
|
|
+ curtain_device.update_from_advertisement(
|
|
|
|
+ set_advertisement_data(ble_device, True, 0)
|
|
|
|
+ )
|
|
|
|
+ curtain_device.update_from_advertisement(
|
|
|
|
+ set_advertisement_data(ble_device, True, 10)
|
|
|
|
+ )
|
|
|
|
|
|
assert curtain_device.is_opening() is True
|
|
assert curtain_device.is_opening() is True
|
|
assert curtain_device.is_closing() is False
|
|
assert curtain_device.is_closing() is False
|
|
|
|
|
|
-@pytest.mark.parametrize("reverse_mode", [(True),(False)])
|
|
|
|
|
|
+
|
|
|
|
+@pytest.mark.parametrize("reverse_mode", [(True), (False)])
|
|
def test_device_passive_closing(reverse_mode):
|
|
def test_device_passive_closing(reverse_mode):
|
|
"""Test passive closing advertisement."""
|
|
"""Test passive closing advertisement."""
|
|
ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")
|
|
ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")
|
|
curtain_device = curtain.SwitchbotCurtain(ble_device, reverse_mode=reverse_mode)
|
|
curtain_device = curtain.SwitchbotCurtain(ble_device, reverse_mode=reverse_mode)
|
|
- curtain_device.update_from_advertisement(set_advertisement_data(ble_device, True, 100))
|
|
|
|
- curtain_device.update_from_advertisement(set_advertisement_data(ble_device, True, 90))
|
|
|
|
|
|
+ curtain_device.update_from_advertisement(
|
|
|
|
+ set_advertisement_data(ble_device, True, 100)
|
|
|
|
+ )
|
|
|
|
+ curtain_device.update_from_advertisement(
|
|
|
|
+ set_advertisement_data(ble_device, True, 90)
|
|
|
|
+ )
|
|
|
|
|
|
assert curtain_device.is_opening() is False
|
|
assert curtain_device.is_opening() is False
|
|
assert curtain_device.is_closing() is True
|
|
assert curtain_device.is_closing() is True
|
|
|
|
|
|
-@pytest.mark.parametrize("reverse_mode", [(True),(False)])
|
|
|
|
|
|
+
|
|
|
|
+@pytest.mark.parametrize("reverse_mode", [(True), (False)])
|
|
def test_device_passive_opening_then_stop(reverse_mode):
|
|
def test_device_passive_opening_then_stop(reverse_mode):
|
|
"""Test passive stopped after opening advertisement."""
|
|
"""Test passive stopped after opening advertisement."""
|
|
ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")
|
|
ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")
|
|
curtain_device = curtain.SwitchbotCurtain(ble_device, reverse_mode=reverse_mode)
|
|
curtain_device = curtain.SwitchbotCurtain(ble_device, reverse_mode=reverse_mode)
|
|
- curtain_device.update_from_advertisement(set_advertisement_data(ble_device, True, 0))
|
|
|
|
- curtain_device.update_from_advertisement(set_advertisement_data(ble_device, True, 10))
|
|
|
|
- curtain_device.update_from_advertisement(set_advertisement_data(ble_device, False, 10))
|
|
|
|
|
|
+ curtain_device.update_from_advertisement(
|
|
|
|
+ set_advertisement_data(ble_device, True, 0)
|
|
|
|
+ )
|
|
|
|
+ curtain_device.update_from_advertisement(
|
|
|
|
+ set_advertisement_data(ble_device, True, 10)
|
|
|
|
+ )
|
|
|
|
+ curtain_device.update_from_advertisement(
|
|
|
|
+ set_advertisement_data(ble_device, False, 10)
|
|
|
|
+ )
|
|
|
|
|
|
assert curtain_device.is_opening() is False
|
|
assert curtain_device.is_opening() is False
|
|
assert curtain_device.is_closing() is False
|
|
assert curtain_device.is_closing() is False
|
|
|
|
|
|
-@pytest.mark.parametrize("reverse_mode", [(True),(False)])
|
|
|
|
|
|
+
|
|
|
|
+@pytest.mark.parametrize("reverse_mode", [(True), (False)])
|
|
def test_device_passive_closing_then_stop(reverse_mode):
|
|
def test_device_passive_closing_then_stop(reverse_mode):
|
|
"""Test passive stopped after closing advertisement."""
|
|
"""Test passive stopped after closing advertisement."""
|
|
ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")
|
|
ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")
|
|
curtain_device = curtain.SwitchbotCurtain(ble_device, reverse_mode=reverse_mode)
|
|
curtain_device = curtain.SwitchbotCurtain(ble_device, reverse_mode=reverse_mode)
|
|
- curtain_device.update_from_advertisement(set_advertisement_data(ble_device, True, 100))
|
|
|
|
- curtain_device.update_from_advertisement(set_advertisement_data(ble_device, True, 90))
|
|
|
|
- curtain_device.update_from_advertisement(set_advertisement_data(ble_device, False, 90))
|
|
|
|
|
|
+ curtain_device.update_from_advertisement(
|
|
|
|
+ set_advertisement_data(ble_device, True, 100)
|
|
|
|
+ )
|
|
|
|
+ curtain_device.update_from_advertisement(
|
|
|
|
+ set_advertisement_data(ble_device, True, 90)
|
|
|
|
+ )
|
|
|
|
+ curtain_device.update_from_advertisement(
|
|
|
|
+ set_advertisement_data(ble_device, False, 90)
|
|
|
|
+ )
|
|
|
|
|
|
assert curtain_device.is_opening() is False
|
|
assert curtain_device.is_opening() is False
|
|
assert curtain_device.is_closing() is False
|
|
assert curtain_device.is_closing() is False
|
|
|
|
|
|
|
|
+
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.asyncio
|
|
-@pytest.mark.parametrize("reverse_mode", [(True),(False)])
|
|
|
|
|
|
+@pytest.mark.parametrize("reverse_mode", [(True), (False)])
|
|
async def test_device_active_not_in_motion(reverse_mode):
|
|
async def test_device_active_not_in_motion(reverse_mode):
|
|
"""Test active not in motion."""
|
|
"""Test active not in motion."""
|
|
ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")
|
|
ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")
|
|
curtain_device = curtain.SwitchbotCurtain(ble_device, reverse_mode=reverse_mode)
|
|
curtain_device = curtain.SwitchbotCurtain(ble_device, reverse_mode=reverse_mode)
|
|
- curtain_device.update_from_advertisement(set_advertisement_data(ble_device, False, 0))
|
|
|
|
|
|
+ curtain_device.update_from_advertisement(
|
|
|
|
+ set_advertisement_data(ble_device, False, 0)
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ basic_info = bytes([0, 0, 0, 0, 0, 0, 100, 0])
|
|
|
|
|
|
- basic_info = bytes([0,0,0,0,0,0,100,0])
|
|
|
|
async def custom_implementation():
|
|
async def custom_implementation():
|
|
return basic_info
|
|
return basic_info
|
|
|
|
|
|
@@ -112,15 +141,19 @@ async def test_device_active_not_in_motion(reverse_mode):
|
|
assert curtain_device.is_opening() is False
|
|
assert curtain_device.is_opening() is False
|
|
assert curtain_device.is_closing() is False
|
|
assert curtain_device.is_closing() is False
|
|
|
|
|
|
|
|
+
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.asyncio
|
|
-@pytest.mark.parametrize("reverse_mode", [(True),(False)])
|
|
|
|
|
|
+@pytest.mark.parametrize("reverse_mode", [(True), (False)])
|
|
async def test_device_active_opening(reverse_mode):
|
|
async def test_device_active_opening(reverse_mode):
|
|
"""Test active opening."""
|
|
"""Test active opening."""
|
|
ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")
|
|
ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")
|
|
curtain_device = curtain.SwitchbotCurtain(ble_device, reverse_mode=reverse_mode)
|
|
curtain_device = curtain.SwitchbotCurtain(ble_device, reverse_mode=reverse_mode)
|
|
- curtain_device.update_from_advertisement(set_advertisement_data(ble_device, True, 0))
|
|
|
|
|
|
+ curtain_device.update_from_advertisement(
|
|
|
|
+ set_advertisement_data(ble_device, True, 0)
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ basic_info = bytes([0, 0, 0, 0, 0, 67, 10, 0])
|
|
|
|
|
|
- basic_info = bytes([0,0,0,0,0,67,10,0])
|
|
|
|
async def custom_implementation():
|
|
async def custom_implementation():
|
|
return basic_info
|
|
return basic_info
|
|
|
|
|
|
@@ -131,15 +164,19 @@ async def test_device_active_opening(reverse_mode):
|
|
assert curtain_device.is_opening() is True
|
|
assert curtain_device.is_opening() is True
|
|
assert curtain_device.is_closing() is False
|
|
assert curtain_device.is_closing() is False
|
|
|
|
|
|
|
|
+
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.asyncio
|
|
-@pytest.mark.parametrize("reverse_mode", [(True),(False)])
|
|
|
|
|
|
+@pytest.mark.parametrize("reverse_mode", [(True), (False)])
|
|
async def test_device_active_closing(reverse_mode):
|
|
async def test_device_active_closing(reverse_mode):
|
|
"""Test active closing."""
|
|
"""Test active closing."""
|
|
ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")
|
|
ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")
|
|
curtain_device = curtain.SwitchbotCurtain(ble_device, reverse_mode=reverse_mode)
|
|
curtain_device = curtain.SwitchbotCurtain(ble_device, reverse_mode=reverse_mode)
|
|
- curtain_device.update_from_advertisement(set_advertisement_data(ble_device, True, 100))
|
|
|
|
|
|
+ curtain_device.update_from_advertisement(
|
|
|
|
+ set_advertisement_data(ble_device, True, 100)
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ basic_info = bytes([0, 0, 0, 0, 0, 67, 90, 0])
|
|
|
|
|
|
- basic_info = bytes([0,0,0,0,0,67,90,0])
|
|
|
|
async def custom_implementation():
|
|
async def custom_implementation():
|
|
return basic_info
|
|
return basic_info
|
|
|
|
|
|
@@ -150,15 +187,19 @@ async def test_device_active_closing(reverse_mode):
|
|
assert curtain_device.is_opening() is False
|
|
assert curtain_device.is_opening() is False
|
|
assert curtain_device.is_closing() is True
|
|
assert curtain_device.is_closing() is True
|
|
|
|
|
|
|
|
+
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.asyncio
|
|
-@pytest.mark.parametrize("reverse_mode", [(True),(False)])
|
|
|
|
|
|
+@pytest.mark.parametrize("reverse_mode", [(True), (False)])
|
|
async def test_device_active_opening_then_stop(reverse_mode):
|
|
async def test_device_active_opening_then_stop(reverse_mode):
|
|
"""Test active stopped after opening."""
|
|
"""Test active stopped after opening."""
|
|
ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")
|
|
ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")
|
|
curtain_device = curtain.SwitchbotCurtain(ble_device, reverse_mode=reverse_mode)
|
|
curtain_device = curtain.SwitchbotCurtain(ble_device, reverse_mode=reverse_mode)
|
|
- curtain_device.update_from_advertisement(set_advertisement_data(ble_device, True, 0))
|
|
|
|
|
|
+ curtain_device.update_from_advertisement(
|
|
|
|
+ set_advertisement_data(ble_device, True, 0)
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ basic_info = bytes([0, 0, 0, 0, 0, 67, 10, 0])
|
|
|
|
|
|
- basic_info = bytes([0,0,0,0,0,67,10,0])
|
|
|
|
async def custom_implementation():
|
|
async def custom_implementation():
|
|
return basic_info
|
|
return basic_info
|
|
|
|
|
|
@@ -166,22 +207,26 @@ async def test_device_active_opening_then_stop(reverse_mode):
|
|
|
|
|
|
await curtain_device.get_basic_info()
|
|
await curtain_device.get_basic_info()
|
|
|
|
|
|
- basic_info = bytes([0,0,0,0,0,0,10,0])
|
|
|
|
|
|
+ basic_info = bytes([0, 0, 0, 0, 0, 0, 10, 0])
|
|
|
|
|
|
await curtain_device.get_basic_info()
|
|
await curtain_device.get_basic_info()
|
|
|
|
|
|
assert curtain_device.is_opening() is False
|
|
assert curtain_device.is_opening() is False
|
|
assert curtain_device.is_closing() is False
|
|
assert curtain_device.is_closing() is False
|
|
|
|
|
|
|
|
+
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.asyncio
|
|
-@pytest.mark.parametrize("reverse_mode", [(True),(False)])
|
|
|
|
|
|
+@pytest.mark.parametrize("reverse_mode", [(True), (False)])
|
|
async def test_device_active_closing_then_stop(reverse_mode):
|
|
async def test_device_active_closing_then_stop(reverse_mode):
|
|
"""Test active stopped after closing."""
|
|
"""Test active stopped after closing."""
|
|
ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")
|
|
ble_device = generate_ble_device("aa:bb:cc:dd:ee:ff", "any")
|
|
curtain_device = curtain.SwitchbotCurtain(ble_device, reverse_mode=reverse_mode)
|
|
curtain_device = curtain.SwitchbotCurtain(ble_device, reverse_mode=reverse_mode)
|
|
- curtain_device.update_from_advertisement(set_advertisement_data(ble_device, True, 100))
|
|
|
|
|
|
+ curtain_device.update_from_advertisement(
|
|
|
|
+ set_advertisement_data(ble_device, True, 100)
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ basic_info = bytes([0, 0, 0, 0, 0, 67, 90, 0])
|
|
|
|
|
|
- basic_info = bytes([0,0,0,0,0,67,90,0])
|
|
|
|
async def custom_implementation():
|
|
async def custom_implementation():
|
|
return basic_info
|
|
return basic_info
|
|
|
|
|
|
@@ -189,9 +234,9 @@ async def test_device_active_closing_then_stop(reverse_mode):
|
|
|
|
|
|
await curtain_device.get_basic_info()
|
|
await curtain_device.get_basic_info()
|
|
|
|
|
|
- basic_info = bytes([0,0,0,0,0,0,90,0])
|
|
|
|
|
|
+ basic_info = bytes([0, 0, 0, 0, 0, 0, 90, 0])
|
|
|
|
|
|
await curtain_device.get_basic_info()
|
|
await curtain_device.get_basic_info()
|
|
|
|
|
|
assert curtain_device.is_opening() is False
|
|
assert curtain_device.is_opening() is False
|
|
- assert curtain_device.is_closing() is False
|
|
|
|
|
|
+ assert curtain_device.is_closing() is False
|