Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 29, 2025

Summary

The current syncNetworkInformation pattern introduces race conditions: callers may read stale cached SSID/BSSID values before the async fetch completes. This refactors critical paths to fetch network info in real-time via async APIs.

Changes:

  • ConnectivityWrapper: Added NetworkInfo struct and currentNetworkInfo: () async -> NetworkInfo that wraps NEHotspotNetwork.fetchCurrent in async/await
  • ConnectionInfo: Added async overloads for activeURL(), webhookURL(), isOnInternalNetwork(), activeAPIURL() that fetch real-time network state
  • ConnectionInfo+WebView: Added async versions of webviewURL() and webviewURLComponents()
  • Updated callers: WebViewController, HomeNetworkInputView, ImprovDiscoverView, ConnectionSecurityLevelBlockViewModel now use async APIs for connection-critical operations
  • Backward compatible: Synchronous APIs preserved for non-critical paths
// Before: race condition prone
Current.connectivity.syncNetworkInformation {
    let url = server.info.connection.activeURL()
}

// After: real-time fetch
let url = await server.info.connection.activeURL()

Screenshots

N/A - No UI changes

Link to pull request in Documentation repository

Documentation: home-assistant/companion.home-assistant#

Any other notes

The existing synchronous APIs remain for backward compatibility. The async APIs should be preferred for any operation where correct network state is essential (connection decisions, URL resolution, etc.).

Original prompt

Task: Refactor the way app checks for SSID/BSSID/Current network information to always be realtime when accessing, for example, .activeURL().

Where to start: ConnectivityWrapper, currentWiFiSSID and currentWiFiBSSID should not be syncronous values, it will impact primarily server's ConnectionInfo, which is used in several parts of the codebase when code requires the URL to be used for an operation.

What is currently implemented: In ConnectivityWrapper we have "syncNetworkInformation" that replaces the SSID and BSSID when called, keeping them syncronous but opening opportunities for race conditions and executions without latest information.

This is a big change, make sure tests are updated and new tests are created if needed.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits December 29, 2025 12:21
…iveURL to ConnectionInfo

Co-authored-by: bgoncal <5808343+bgoncal@users.noreply.github.com>
Co-authored-by: bgoncal <5808343+bgoncal@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor app to access realtime network information Refactor network SSID/BSSID checks to be real-time async Dec 29, 2025
Copilot AI requested a review from bgoncal December 29, 2025 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants