iOS/Sources/App/WebView/ExternalMessageBus/WebViewExternalBusMessage.swift
Bruno Pantaleão Gonçalves 6b2f83e97e
Add "Add to" frontend compatibility for CarPlay, Widgets and Apple Watch (#4273)
<!-- 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 -->
This PR allows adding supported domain entities to CarPlay, Widgets and
Apple watch directly from the entity more info dialog

## 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. -->

---------

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
2026-01-29 17:00:17 +01:00

65 lines
2.8 KiB
Swift

import Foundation
import Shared
/// External Bus message types used by the web view integration.
/// - See: Home Assistant External Bus docs: https://developers.home-assistant.io/docs/frontend/external-bus
/// - See: Frontend implementation:
/// https://github.com/home-assistant/frontend/blob/dev/src/external_app/external_messaging.ts
enum WebViewExternalBusMessage: String, CaseIterable {
case configGet = "config/get"
case configScreenShow = "config_screen/show"
case haptic
case connectionStatus = "connection-status"
case tagRead = "tag/read"
case tagWrite = "tag/write"
case themeUpdate = "theme-update"
case matterCommission = "matter/commission"
case threadImportCredentials = "thread/import_credentials"
case threadStoreCredentialInAppleKeychain = "thread/store_in_platform_keychain"
case barCodeScanner = "bar_code/scan"
case barCodeScannerClose = "bar_code/close"
case barCodeScannerNotify = "bar_code/notify"
case assistShow = "assist/show"
case scanForImprov = "improv/scan"
case improvConfigureDevice = "improv/configure_device"
case focusElement = "focus_element"
case toastShow = "toast/show"
case toastHide = "toast/hide"
case entityAddToGetActions = "entity/add_to/get_actions"
case entityAddTo = "entity/add_to"
@MainActor static var configResult: [String: Any] {
[
"hasSettingsScreen": !Current.isCatalyst,
"canWriteTag": Current.tags.isNFCAvailable,
"canCommissionMatter": Current.matter.isAvailable,
"canImportThreadCredentials": Current.matter.threadCredentialsSharingEnabled,
"hasBarCodeScanner": true,
"canTransferThreadCredentialsToKeychain": Current.matter
.threadCredentialsStoreInKeychainEnabled,
"hasAssist": true,
"canSetupImprov": true,
"downloadFileSupported": true,
"hasEntityAddTo": true,
"appVersion": "\(AppConstants.version) (\(AppConstants.build))",
"toastComponentVersion": { // Frontend can use this to know if the version has what it needs
if #available(iOS 18, *), !Current.isCatalyst, Current.settingsStore.toastsHandledByApp {
return ToastManager.toastComponentVersion
} else {
return -1
}
}(),
]
}
}
enum WebViewExternalBusOutgoingMessage: String, CaseIterable {
case showSidebar = "sidebar/show"
case showAutomationEditor = "automation/editor/show"
case barCodeScanResult = "bar_code/scan_result"
case barCodeScanAborted = "bar_code/aborted"
case improvDiscoveredDevice = "improv/discovered_device"
case improvDiscoveredDeviceSetupDone = "improv/device_setup_done"
case navigate = "navigate"
}