iOS/Sources/App/Frontend/WebView/ConnectionSecurityLevelBlock/ConnectionSecurityLevelBlockViewModel.swift
Bruno Pantaleão Gonçalves e17f81f64b
Organize webview folder (#4324)
<!-- 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. -->
2026-02-08 15:18:43 +01:00

63 lines
1.9 KiB
Swift

import Foundation
import SFSafeSymbols
import Shared
final class ConnectionSecurityLevelBlockViewModel: ObservableObject {
enum Requirement {
case homeNetworkMissing
case notOnHomeNetwork
case locationPermission
var title: String {
switch self {
case .homeNetworkMissing:
return L10n.ConnectionSecurityLevelBlock.Requirement.HomeNetworkMissing.title
case .notOnHomeNetwork:
return L10n.ConnectionSecurityLevelBlock.Requirement.NotOnHomeNetwork.title
case .locationPermission:
return L10n.ConnectionSecurityLevelBlock.Requirement.LocationPermissionMissing.title
}
}
var systemSymbol: SFSymbol {
switch self {
case .homeNetworkMissing:
return .wifi
case .notOnHomeNetwork:
return .wifiSlash
case .locationPermission:
return .location
}
}
}
@Published var requirements: [Requirement] = []
private let server: Server
init(server: Server) {
self.server = server
}
func loadRequirements() {
requirements = []
// Check if home network is defined
if server.info.connection.internalSSIDs?.isEmpty ?? true,
server.info.connection.internalHardwareAddresses?.isEmpty ?? true {
requirements.append(.homeNetworkMissing)
} else {
// Check if user is on home network
if !server.info.connection.isOnInternalNetwork {
requirements.append(.notOnHomeNetwork)
}
}
// Check location permission
let currentPermission = Current.locationManager.currentPermissionState
if currentPermission != .authorizedAlways, currentPermission != .authorizedWhenInUse {
requirements.append(.locationPermission)
}
}
}