Concurrency & Networking
Concurrency
Prefer Swift Concurrency (async/await, Task, actors, structured concurrency) for all new asynchronous code.
- Do not introduce new PromiseKit code. PromiseKit is a legacy dependency that the codebase is gradually moving away from. Parts of
HomeAssistantAPI(HAAPI.swift) still use it, so don't assume a full migration — but new work should useasync/awaitinstead ofPromise/Guarantee. - When touching existing PromiseKit code, migrate it to
async/awaitwhere practical rather than extending the PromiseKit usage. - Use
Combineonly where an existing reactive pattern already requires it; otherwise preferasync/awaitandAsyncStream/AsyncSequence. - Annotate SwiftUI-facing view models with
@MainActor.
Networking
Use HAKit (the Home Assistant Swift SDK) for server communication:
- REST API calls via
HAConnection - WebSocket subscriptions for real-time updates
- Connection info managed through
Current.servers - Prefer
async/awaitfor new request flows (see Concurrency above); avoid adding new PromiseKit-based calls.