Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ async def send_cloud(self, *args, **kwargs):
self.send_args = args

def call(self, coro):
asyncio.get_event_loop().run_until_complete(coro)
loop = asyncio.new_event_loop()
loop.run_until_complete(coro)
loop.close()
return self.send_args


Expand All @@ -39,7 +41,7 @@ def init(device: dict, config: dict = None) -> (XRegistry, List[XEntity]):
params = device.setdefault("params", {})
params.setdefault("staMac", "FF:FF:FF:FF:FF:FF")

asyncio.create_task = lambda _: None
asyncio.create_task = lambda coro: coro.close()
asyncio.get_running_loop = lambda: type("", (), {"_thread_id": threading.get_ident()})

entities = []
Expand Down
10 changes: 6 additions & 4 deletions tests/test_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
MAJOR_VERSION,
MINOR_VERSION,
UnitOfEnergy,
UnitOfTemperature,
UnitOfVolume,
)
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
from homeassistant.util.unit_system import IMPERIAL_SYSTEM

from custom_components.sonoff import remote
from custom_components.sonoff.binary_sensor import XBinarySensor, XRemoteSensor
Expand All @@ -33,7 +31,7 @@
SIGNAL_CONNECTED,
SIGNAL_UPDATE,
)
from custom_components.sonoff.cover import XCover, XCoverOP, XCoverDualR3, XZigbeeCover
from custom_components.sonoff.cover import XCover, XCoverDualR3, XCoverOP, XZigbeeCover
from custom_components.sonoff.fan import XFan, XToggleFan
from custom_components.sonoff.light import (
UIID22_MODES,
Expand Down Expand Up @@ -73,7 +71,11 @@ def get_entitites(device: Union[dict, list], config: dict = None) -> list:


def await_(coro):
return asyncio.get_event_loop().run_until_complete(coro)
loop = asyncio.new_event_loop()
try:
return loop.run_until_complete(coro)
finally:
loop.close()


def test_simple_switch():
Expand Down
4 changes: 3 additions & 1 deletion tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test_bulk():
registry_send = []

device = XDevice()
loop = asyncio.get_event_loop()
loop = asyncio.new_event_loop()
# noinspection PyTypeChecker
registry: XRegistry = XRegistry(None)
registry.send = save_to(registry_send)
Expand Down Expand Up @@ -40,6 +40,8 @@ def test_bulk():
"switches": [{"outlet": 1, "switch": "on"}, {"outlet": 2, "switch": "off"}]
}

loop.close()


def test_issue_1160():
payload = XRegistryLocal.decrypt_msg(
Expand Down
Loading