Skip to content

Commit 5d4f3c7

Browse files
authored
Fallback to internal URL until location enforcement is communicated c… (home-assistant#3276)
…learly <!-- Thank you for submitting a Pull Request and helping to improve Home Assistant. Please complete the following sections to help the processing and review of your changes. Please do not delete anything from this template. --> ## Summary <!-- Provide a brief summary of the changes you have made and most importantly what they aim to achieve --> ## Screenshots <!-- If this is a user-facing change not in the frontend, please include screenshots in light and dark mode. --> ## Link to pull request in Documentation repository <!-- Pull requests that add, change or remove functionality must have a corresponding pull request in the Companion App Documentation repository (https://github.com/home-assistant/companion.home-assistant). Please add the number of this pull request after the "#" --> Documentation: home-assistant/companion.home-assistant# ## Any other notes <!-- If there is any other information of note, like if this Pull Request is part of a bigger change, please include it here. -->
1 parent 63ae3a0 commit 5d4f3c7

File tree

4 files changed

+56
-36
lines changed

4 files changed

+56
-36
lines changed

Sources/App/Settings/Connection/ConnectionSettingsViewController.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ class ConnectionSettingsViewController: HAFormViewController, RowControllerType
156156
row.displayValueFor = { [server] _ in
157157
if server.info.connection.internalSSIDs?.isEmpty ?? true,
158158
server.info.connection.internalHardwareAddresses?.isEmpty ?? true,
159-
!server.info.connection.alwaysFallbackToInternalURL {
159+
!server.info.connection.alwaysFallbackToInternalURL,
160+
!ConnectionInfo.shouldFallbackToInternalURL {
160161
return "‼️ \(L10n.Settings.ConnectionSection.InternalBaseUrl.RequiresSetup.title)"
161162
} else {
162163
return server.info.connection.address(for: .internal)?.absoluteString ?? ""

Sources/App/Settings/Connection/ConnectionURLViewController.swift

+32-28
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ final class ConnectionURLViewController: HAFormViewController, TypedRowControlle
232232
$0.tag = RowTag.internalURLWarning.rawValue
233233
if server.info.connection.internalSSIDs?.isEmpty ?? true,
234234
server.info.connection.internalHardwareAddresses?.isEmpty ?? true,
235-
!server.info.connection.alwaysFallbackToInternalURL {
235+
!server.info.connection.alwaysFallbackToInternalURL,
236+
!ConnectionInfo.shouldFallbackToInternalURL {
236237
#if targetEnvironment(macCatalyst)
237238
$0.title = "‼️" + L10n.Settings.ConnectionSection.InternalBaseUrl.SsidBssidRequired.title
238239
#else
@@ -296,38 +297,41 @@ final class ConnectionURLViewController: HAFormViewController, TypedRowControlle
296297
}
297298
}
298299

299-
form +++ Section(footer: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.footer)
300-
<<< SwitchRow(RowTag.alwaysFallbackToInternalURL.rawValue) {
301-
$0.title = L10n.Settings.ConnectionSection.AlwaysFallbackInternal.title
302-
$0.value = server.info.connection.alwaysFallbackToInternalURL
300+
if !ConnectionInfo.shouldFallbackToInternalURL {
301+
form +++ Section(footer: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.footer)
302+
<<< SwitchRow(RowTag.alwaysFallbackToInternalURL.rawValue) {
303+
$0.title = L10n.Settings.ConnectionSection.AlwaysFallbackInternal.title
304+
$0.value = server.info.connection.alwaysFallbackToInternalURL
303305

304-
$0.cellUpdate { cell, _ in
305-
cell.switchControl.onTintColor = .red
306-
}
306+
$0.cellUpdate { cell, _ in
307+
cell.switchControl.onTintColor = .red
308+
}
307309

308-
$0.onChange { [weak self] row in
309-
if row.value ?? false {
310-
let alert = UIAlertController(
311-
title: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.Confirmation.title,
312-
message: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.Confirmation.message,
313-
preferredStyle: .alert
314-
)
315-
alert.addAction(UIAlertAction(title: L10n.cancelLabel, style: .cancel, handler: { _ in
316-
self?.server.info.connection.alwaysFallbackToInternalURL = false
317-
row.value = false
318-
row.cellUpdate { _, row in
310+
$0.onChange { [weak self] row in
311+
if row.value ?? false {
312+
let alert = UIAlertController(
313+
title: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.Confirmation.title,
314+
message: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.Confirmation.message,
315+
preferredStyle: .alert
316+
)
317+
alert.addAction(UIAlertAction(title: L10n.cancelLabel, style: .cancel, handler: { _ in
318+
self?.server.info.connection.alwaysFallbackToInternalURL = false
319319
row.value = false
320-
}
321-
row.reload()
322-
}))
323-
alert.addAction(UIAlertAction(
324-
title: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.Confirmation.confirmButton,
325-
style: .destructive
326-
))
327-
self?.present(alert, animated: true)
320+
row.cellUpdate { _, row in
321+
row.value = false
322+
}
323+
row.reload()
324+
}))
325+
alert.addAction(UIAlertAction(
326+
title: L10n.Settings.ConnectionSection.AlwaysFallbackInternal.Confirmation
327+
.confirmButton,
328+
style: .destructive
329+
))
330+
self?.present(alert, animated: true)
331+
}
328332
}
329333
}
330-
}
334+
}
331335
}
332336

333337
private func locationPermissionSection() -> Section {

Sources/Shared/API/ConnectionInfo.swift

+18-7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import Communicator
66
#endif
77

88
public struct ConnectionInfo: Codable, Equatable {
9+
// TODO: Remove when location permission enforcement is in place
10+
/// Developer toggle used while enforcement of location permision is not ready
11+
/// Used as feature toggle
12+
public static var shouldFallbackToInternalURL = true
13+
914
private var externalURL: URL?
1015
private var internalURL: URL?
1116
private var remoteUIURL: URL?
@@ -200,13 +205,19 @@ public struct ConnectionInfo: Codable, Equatable {
200205
activeURLType = .internal
201206
url = internalURL
202207
} else {
203-
activeURLType = .none
204-
url = nil
205-
/*
206-
No URL that can be used in this context is available
207-
This can happen when only internal URL is set and
208-
user tries to access the App remotely
209-
*/
208+
// TODO: Remove when location permission enforcement is in place
209+
if ConnectionInfo.shouldFallbackToInternalURL {
210+
activeURLType = .internal
211+
url = internalURL
212+
} else {
213+
activeURLType = .none
214+
url = nil
215+
/*
216+
No URL that can be used in this context is available
217+
This can happen when only internal URL is set and
218+
user tries to access the App remotely
219+
*/
220+
}
210221
}
211222

212223
return url?.sanitized()

Tests/Shared/ConnectionInfo.test.swift

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import Version
33
import XCTest
44

55
class ConnectionInfoTests: XCTestCase {
6+
override func setUp() async throws {
7+
ConnectionInfo.shouldFallbackToInternalURL = false
8+
}
9+
610
func testInternalOnlyURL() {
711
let url = URL(string: "http://example.com:8123")
812
var info = ConnectionInfo(

0 commit comments

Comments
 (0)