iOS/Sources/Shared/Environment/MatterWrapper.swift
Bruno Pantaleão Gonçalves 1d2adcc418
Exclude Mac Catalyst from MatterSupport import check (#4097)
Updated the isAvailable property to exclude macCatalyst from the
MatterSupport import check, ensuring Matter features are only enabled on
supported platforms.

<!-- 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. -->
2025-12-16 18:59:18 +01:00

83 lines
2.4 KiB
Swift

#if canImport(MatterSupport)
import MatterSupport
#endif
import PromiseKit
public class MatterWrapper {
public var isAvailable: Bool = {
#if canImport(MatterSupport) && !targetEnvironment(macCatalyst)
if #available(iOS 16.1, *) {
return true
} else {
return false
}
#else
return false
#endif
}()
public var threadCredentialsSharingEnabled: Bool {
// For now mac is not returning thread credentials for some reason
#if canImport(ThreadNetwork) && !targetEnvironment(macCatalyst)
if #available(iOS 16.4, *) {
return true
} else {
return false
}
#else
return false
#endif
}
public var threadCredentialsStoreInKeychainEnabled: Bool {
#if canImport(ThreadNetwork) && !targetEnvironment(macCatalyst)
if #available(iOS 16.4, *) {
return true
} else {
return false
}
#else
return false
#endif
}
#if os(iOS)
public var threadClientService: ThreadClientProtocol = ThreadClientService()
public var lastCommissionServerIdentifier: Identifier<Server>? {
get { Current.settingsStore.prefs.string(forKey: "lastCommissionServerID").flatMap { .init(rawValue: $0) } }
set { Current.settingsStore.prefs.set(newValue?.rawValue, forKey: "lastCommissionServerID") }
}
public lazy var commission: (_ server: Server) -> Promise<Void> = { [self] server in
#if canImport(MatterSupport)
guard #available(iOS 16.4, *) else {
return .value(())
}
lastCommissionServerIdentifier = server.identifier
let request = MatterAddDeviceRequest(
topology: .init(ecosystemName: "Home Assistant", homes: []),
shouldScanNetworks: true
)
return Promise<Void> { seal in
Task {
do {
try await request.perform()
Current.Log.info("Matter pairing finished (native flow manually closed or pairing succeeded)")
seal.fulfill(())
} catch {
Current.Log.error("Matter pairing failed: \(error)")
seal.reject(error)
}
}
}
#else
return .value(())
#endif
}
#endif
}