Skip to content

Select server URL based on any Wi-Fi connection - #7372

Open
adamff-dev wants to merge 3 commits into
home-assistant:mainfrom
adamff-dev:feature/wifi-dependent-server-url
Open

Select server URL based on any Wi-Fi connection#7372
adamff-dev wants to merge 3 commits into
home-assistant:mainfrom
adamff-dev:feature/wifi-dependent-server-url

Conversation

@adamff-dev

@adamff-dev adamff-dev commented Aug 24, 2026

Copy link
Copy Markdown

Summary

This change adds support for selecting the Home Assistant server URL based on the current Wi-Fi connection.

Users can configure whether any Wi-Fi connection should be treated as an internal connection. The server settings and SSID configuration screens expose this option, and the connection state provider uses it when determining which server URL to use. The database schema was updated accordingly, with tests added for the connection state behavior.

Checklist

  • New or updated tests have been added to cover the changes following the testing guidelines.
  • The code follows the project's code style and best_practices.
  • The changes have been thoroughly tested, and edge cases have been considered.
  • Changes are backward compatible whenever feasible. Any breaking changes are documented in the changelog for users and/or in the code for developers depending on the relevance.
  • I have read the Open Home Foundation AI Policy.

Select exactly one option that describes AI usage in this contribution:

  • I have not used AI for this contribution.
  • AI assistance was used for this contribution.
  • AI fully generated the code for this contribution, but I've reviewed and understood it before submitting and will respond without AI during review.

Screenshots

Screenshots are not included.

Link to pull request in documentation repositories

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

Developer Documentation: home-assistant/developers.home-assistant#

Any other notes

The common module tests completed successfully. A Room database schema migration is included for the new connection setting.

Copilot AI lite review requested due to automatic review settings August 24, 2026 19:28

@home-assistant home-assistant Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @adamff-dev,

When attempting to inspect the commits of your pull request for CLA signature status among all authors we encountered commit(s) which were not linked to a GitHub account, thus not allowing us to determine their status(es).

The commits that are missing a linked GitHub account are the following:

Unfortunately, we are unable to accept this pull request until this situation is corrected.

Here are your options:

  1. If you had an email address set for the commit that simply wasn't linked to your GitHub account you can link that email now and it will retroactively apply to your commits. The simplest way to do this is to click the link to one of the above commits and look for a blue question mark in a blue circle in the top left. Hovering over that bubble will show you what email address you used. Clicking on that button will take you to your email address settings on GitHub. Just add the email address on that page and you're all set. GitHub has more information about this option in their help center.

  2. If you didn't use an email address at all, it was an invalid email, or it's one you can't link to your GitHub, you will need to change the authorship information of the commit and your global Git settings so this doesn't happen again going forward. GitHub provides some great instructions on how to change your authorship information in their help center.

    • If you only made a single commit you should be able to run
      git commit --amend --author="Author Name <email@address.com>"
      
      (substituting "Author Name" and "email@address.com" for your actual information) to set the authorship information.
    • If you made more than one commit and the commit with the missing authorship information is not the most recent one you have two options:
      1. You can re-create all commits missing authorship information. This is going to be the easiest solution for developers that aren't extremely confident in their Git and command line skills.
      2. You can use this script that GitHub provides to rewrite history. Please note: this should be used only if you are very confident in your abilities and understand its impacts.
    • Whichever method you choose, I will come by to re-check the pull request once you push the fixes to this branch.

We apologize for this inconvenience, especially since it usually bites new contributors to Home Assistant. We hope you understand the need for us to protect ourselves and the great community we all have built legally. The best thing to come out of this is that you only need to fix this once and it benefits the entire Home Assistant and GitHub community.

Thanks, I look forward to checking this PR again soon! ❤️

@home-assistant

Copy link
Copy Markdown

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant
home-assistant Bot marked this pull request as draft August 24, 2026 19:28
@adamff-dev
adamff-dev force-pushed the feature/wifi-dependent-server-url branch from f250ece to 6492238 Compare August 24, 2026 19:30
home-assistant[bot]

This comment was marked as duplicate.

home-assistant[bot]

This comment was marked as duplicate.

@adamff-dev
adamff-dev marked this pull request as ready for review August 24, 2026 19:31
@home-assistant
home-assistant Bot dismissed stale reviews from themself August 24, 2026 19:31

Stale

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds per-server support for treating any Wi‑Fi connection as internal, including persistence, connection-state logic, settings UI, migration, and tests.

Changes:

  • Adds the useAnyWifiForInternal setting.
  • Updates Wi‑Fi-based URL selection and security-state handling.
  • Adds Room schema migration and provider tests.

Outstanding review comments:

  • SsidView.ktModerate, 4 votes: provide switch semantics and add interaction coverage.
  • ServerConnectionStateProviderImpl.ktNit, 2 votes: update isInternal documentation.
  • ServerConnectionStateProviderImpl.ktModerate, 3 votes: avoid requiring location when any-Wi‑Fi detection is configured.
  • ServerConnectionInfo.ktNit, 3 votes: add coverage for any-Wi‑Fi-only configuration.
  • strings.xmlNit, 3 votes: add the user-visible setting to the changelog.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
common/src/test/kotlin/io/homeassistant/companion/android/common/data/servers/ServerConnectionStateProviderImplTest.kt Tests any-Wi‑Fi detection behavior.
common/src/main/res/values/strings.xml Adds the setting label.
common/src/main/kotlin/io/homeassistant/companion/android/database/server/ServerConnectionInfo.kt Stores and evaluates the new setting.
common/src/main/kotlin/io/homeassistant/companion/android/database/AppDatabase.kt Advances the Room database version.
common/src/main/kotlin/io/homeassistant/companion/android/common/data/servers/ServerConnectionStateProviderImpl.kt Applies Wi‑Fi-based internal detection.
common/schemas/io.homeassistant.companion.android.database.AppDatabase/54.json Records the updated Room schema.
app/src/main/kotlin/io/homeassistant/companion/android/settings/ssid/views/SsidView.kt Displays the any-Wi‑Fi toggle.
app/src/main/kotlin/io/homeassistant/companion/android/settings/ssid/SsidViewModel.kt Loads and persists the setting.
app/src/main/kotlin/io/homeassistant/companion/android/settings/ssid/SsidFragment.kt Connects UI callbacks to the ViewModel.
app/src/main/kotlin/io/homeassistant/companion/android/settings/server/ServerSettingsView.kt Extends the home-network settings contract.
app/src/main/kotlin/io/homeassistant/companion/android/settings/server/ServerSettingsPresenterImpl.kt Supplies the new configuration to the settings view.
app/src/main/kotlin/io/homeassistant/companion/android/settings/server/ServerSettingsFragment.kt Displays the configured option.
Suppressed comments (2)

app/src/main/kotlin/io/homeassistant/companion/android/settings/ssid/SsidViewModel.kt:126

  • Please add a ViewModel test for this new persistence path. The provider tests cover the in-memory detection branch, but no test verifies that setInternalWithAnyWifi writes useAnyWifiForInternal to the server (or that initialization reads it), so the toggle could appear to change without affecting URL selection.
    fun setInternalWithAnyWifi(enabled: Boolean) {
        viewModelScope.launch {
            serverManager.getServer(serverId)?.let {
                serverManager.updateServer(
                    it.copy(

common/src/main/kotlin/io/homeassistant/companion/android/common/data/servers/ServerConnectionStateProviderImpl.kt:67

  • This branch short-circuits SSID detection, but enabling it leaves any previously configured internalSsids in the database. CheckLocationDisabledUseCase.isSsidUsed() still treats that stale list as active, so users who switch from an SSID to any-Wi-Fi detection can continue receiving a location-disabled notification even though this detection path does not need location. Please either clear the list when enabling this mode or make the location check ignore SSIDs while useAnyWifiForInternal is true.
        return if (connection.useAnyWifiForInternal) {
            wifiHelper.isUsingWifi()
        } else if (connection.internalSsids.isNotEmpty()) {

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +227 to +229
checked = anyWifi,
onClicked = onSetAnyWifi,
)
Comment on lines +65 to +66
return if (connection.useAnyWifiForInternal) {
wifiHelper.isUsingWifi()
Comment on lines +65 to +66
return if (connection.useAnyWifiForInternal) {
wifiHelper.isUsingWifi()
Comment on lines +111 to +112
val hasHomeNetworkSetup: Boolean = useAnyWifiForInternal ||
internalSsids.isNotEmpty() ||
<string name="pref_connection_title">Connection information</string>
<string name="pref_connection_url">Home Assistant URL</string>
<string name="pref_connection_homenetwork">Home network</string>
<string name="pref_connection_use_any_wifi_for_internal">Detect any Wi-Fi connection</string>
@jpelgrom jpelgrom changed the title Select server URL based on Wi-Fi connection Select server URL based on any Wi-Fi connection Aug 24, 2026
home-assistant[bot]

This comment was marked as duplicate.

@home-assistant
home-assistant Bot marked this pull request as draft August 24, 2026 19:42
@jpelgrom

Copy link
Copy Markdown
Member

I do not believe we should add this option as it promotes insecure behavior. What issue are you trying to solve?

home-assistant[bot]

This comment was marked as duplicate.

home-assistant[bot]

This comment was marked as outdated.

@adamff-dev
adamff-dev marked this pull request as ready for review August 24, 2026 19:54
@home-assistant
home-assistant Bot dismissed stale reviews from themself August 24, 2026 19:54

Stale

@adamff-dev
adamff-dev force-pushed the feature/wifi-dependent-server-url branch from 793a65e to 43c0366 Compare August 24, 2026 19:56

@home-assistant home-assistant Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @adamff-dev

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant
home-assistant Bot marked this pull request as draft August 24, 2026 19:56
@adamff-dev
adamff-dev marked this pull request as ready for review August 24, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants