mirror of
https://github.com/home-assistant/iOS.git
synced 2026-06-25 16:21:00 -05:00
<!-- 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 --> Some users experience their "WidgetCustom" interaction to not happen, meanwhile the entity states in the widget update normally. This PR adds more logs to help evaluate what's happening. ## 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. -->
32 lines
1.2 KiB
Swift
32 lines
1.2 KiB
Swift
import Foundation
|
|
import HAKit
|
|
import Shared
|
|
|
|
@available(iOS 16.4, *)
|
|
enum CustomWidgetIntentHelper {
|
|
/// Returns the active `HAConnection` for `serverId`, or nil if it can't be
|
|
/// resolved. When `activeURL` is nil, dispatches a local notification so a
|
|
/// tap doesn't silently do nothing.
|
|
static func resolveConnection(
|
|
serverId: String,
|
|
intentName: String
|
|
) -> HAConnection? {
|
|
guard let server = Current.servers.all.first(where: { $0.identifier.rawValue == serverId }) else {
|
|
Current.Log.error("\(intentName): server not found, serverId: \(serverId)")
|
|
return nil
|
|
}
|
|
guard let connection = Current.api(for: server)?.connection else {
|
|
Current.Log
|
|
.error("\(intentName): no API for server (activeURL is nil), serverId: \(serverId)")
|
|
Current.notificationDispatcher.send(.init(
|
|
id: .serverUnreachable,
|
|
title: L10n.Widgets.Custom.ServerUnreachable.title,
|
|
body: L10n.Widgets.Custom.ServerUnreachable.body
|
|
))
|
|
return nil
|
|
}
|
|
Current.Log.verbose("\(intentName): resolved connection, serverId: \(serverId)")
|
|
return connection
|
|
}
|
|
}
|