Skip to content

Commit

Permalink
Remove UART thread (#598)
Browse files Browse the repository at this point in the history
  • Loading branch information
puddly authored Dec 6, 2023
1 parent e4c624a commit 1ac01ed
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 454 deletions.
1 change: 0 additions & 1 deletion bellows/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
vol.Optional(CONF_EZSP_POLICIES, default={}): vol.Schema(
{vol.Optional(str): int}
),
vol.Optional(CONF_USE_THREAD, default=True): cv_boolean,
}
)

Expand Down
6 changes: 3 additions & 3 deletions bellows/ezsp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ async def startup_reset(self) -> None:
async def initialize(cls, zigpy_config: dict) -> EZSP:
"""Return initialized EZSP instance."""
ezsp = cls(zigpy_config[conf.CONF_DEVICE])
await ezsp.connect(use_thread=zigpy_config[conf.CONF_USE_THREAD])
await ezsp.connect()

try:
await ezsp.startup_reset()
Expand All @@ -134,9 +134,9 @@ async def initialize(cls, zigpy_config: dict) -> EZSP:

return ezsp

async def connect(self, *, use_thread: bool = True) -> None:
async def connect(self) -> None:
assert self._gw is None
self._gw = await bellows.uart.connect(self._config, self, use_thread=use_thread)
self._gw = await bellows.uart.connect(self._config, self)
self._protocol = v4.EZSPv4(self.handle_callback, self._gw)

async def reset(self):
Expand Down
122 changes: 0 additions & 122 deletions bellows/thread.py

This file was deleted.

22 changes: 1 addition & 21 deletions bellows/uart.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import zigpy.config
import zigpy.serial

from bellows.thread import EventLoopThread, ThreadsafeProxy
import bellows.types as t

LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -364,7 +363,7 @@ def _unstuff(self, s):
return out


async def _connect(config, application):
async def connect(config, application):
loop = asyncio.get_event_loop()

connection_future = loop.create_future()
Expand All @@ -387,23 +386,4 @@ async def _connect(config, application):

await connection_future

thread_safe_protocol = ThreadsafeProxy(protocol, loop)
return thread_safe_protocol, connection_done_future


async def connect(config, application, use_thread=True):
if use_thread:
application = ThreadsafeProxy(application, asyncio.get_event_loop())
thread = EventLoopThread()
await thread.start()
try:
protocol, connection_done = await thread.run_coroutine_threadsafe(
_connect(config, application)
)
except Exception:
thread.force_stop()
raise
connection_done.add_done_callback(lambda _: thread.force_stop())
else:
protocol, _ = await _connect(config, application)
return protocol
9 changes: 2 additions & 7 deletions bellows/zigbee/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@
import zigpy.zdo.types as zdo_t

import bellows
from bellows.config import (
CONF_EZSP_CONFIG,
CONF_EZSP_POLICIES,
CONF_USE_THREAD,
CONFIG_SCHEMA,
)
from bellows.config import CONF_EZSP_CONFIG, CONF_EZSP_POLICIES, CONFIG_SCHEMA
from bellows.exception import ControllerError, EzspError, StackAlreadyRunning
import bellows.ezsp
from bellows.ezsp.v8.types.named import EmberDeviceUpdate
Expand Down Expand Up @@ -138,7 +133,7 @@ async def _get_board_info(self) -> tuple[str, str, str] | tuple[None, None, None

async def connect(self) -> None:
ezsp = bellows.ezsp.EZSP(self.config[zigpy.config.CONF_DEVICE])
await ezsp.connect(use_thread=self.config[CONF_USE_THREAD])
await ezsp.connect()

try:
await ezsp.startup_reset()
Expand Down
Loading

0 comments on commit 1ac01ed

Please sign in to comment.