Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
WIP: NOT READY FOR MERGE YET
This replaces the primary mechanism by which HASS runs.
The existing architecture exposes 3 core.py API objects, EventBus, StateMachine, and ServiceRegistry. These are called from a variety of threads and are all blocking calls that attempt to acquire per-object locks to fully execute.
This change retains the existing thread-safe blocking API for use by all components, as well as the blocking nature of component setup. However, it starts up an asyncio event loop on start, which is where the actual work is done. The thread-safe API calls schedule the async API variant version into the event loop, then blocks waiting until it has run to completion.
EventBus registrations that are marked as coroutines run on the event loop and may directly run async versions of the appropriate API's. To retain similar call characteristics as before, EventBus's async_fire schedules coroutines to run later on the event loop while sending non-coroutines to the thread-pool as before. This does mean that coroutine listeners are guaranteed to run after all listeners were located, while non-coroutines may start executing immediately in the other thread.
This WIP uses Python 3.4.4 functionality as a proving ground for the approach, using earlier 3.4 should be fine with a backported function or two for asyncio features needed (such as run_coroutine_threadsafe).