mirror of
https://github.com/home-assistant/iOS.git
synced 2026-06-18 11:15:36 -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 --> Introduce makeHAEntityIntentItemCollection to centralize building IntentItemCollection<HAAppEntityAppIntentEntity> with a default icon and areaName mapping. Replace duplicated mapping logic in multiple ControlOpen* entity option providers (Camera, Cover, InputBoolean, Light, Lock, Sensor, Switch) to call the new helper, reducing duplication and adding consistent areaName support. The helper is added to HAAppEntityAppIntentEntity.swift and used by the various ControlOpen*ValueProvider files. ## 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. -->
91 lines
2.9 KiB
Swift
91 lines
2.9 KiB
Swift
import AppIntents
|
|
import Foundation
|
|
import SFSafeSymbols
|
|
import Shared
|
|
import WidgetKit
|
|
|
|
@available(iOS 18, *)
|
|
struct ControlOpenSensorItem {
|
|
let entity: HAAppEntityAppIntentEntity
|
|
let icon: SFSymbolEntity
|
|
let displayText: String?
|
|
}
|
|
|
|
@available(iOS 18, *)
|
|
struct ControlOpenSensorValueProvider: AppIntentControlValueProvider {
|
|
func currentValue(configuration: ControlOpenSensorConfiguration) async throws -> ControlOpenSensorItem {
|
|
item(configuration: configuration)
|
|
}
|
|
|
|
func placeholder(for configuration: ControlOpenSensorConfiguration) -> ControlOpenSensorItem {
|
|
item(configuration: configuration)
|
|
}
|
|
|
|
func previewValue(configuration: ControlOpenSensorConfiguration) -> ControlOpenSensorItem {
|
|
item(configuration: configuration)
|
|
}
|
|
|
|
private func item(configuration: ControlOpenSensorConfiguration) -> ControlOpenSensorItem {
|
|
.init(
|
|
entity: configuration.entity ?? .init(
|
|
id: "",
|
|
entityId: "",
|
|
serverId: "",
|
|
serverName: "",
|
|
displayString: L10n.Widgets.Controls.OpenSensor.pendingConfiguration,
|
|
iconName: ""
|
|
),
|
|
icon: configuration.icon ?? placeholder().icon,
|
|
displayText: configuration.displayText
|
|
)
|
|
}
|
|
|
|
private func placeholder() -> ControlOpenSensorItem {
|
|
.init(
|
|
entity: .init(
|
|
id: "",
|
|
entityId: "",
|
|
serverId: "",
|
|
serverName: "",
|
|
displayString: L10n.Widgets.Controls.OpenSensor.pendingConfiguration,
|
|
iconName: ""
|
|
),
|
|
icon: .init(id: SFSymbol.eye.rawValue), displayText: nil
|
|
)
|
|
}
|
|
}
|
|
|
|
@available(iOS 18.0, *)
|
|
struct ControlOpenSensorConfiguration: ControlConfigurationIntent {
|
|
static var title: LocalizedStringResource = .init(
|
|
"widgets.controls.open_sensor.configuration.title",
|
|
defaultValue: "Open Sensor"
|
|
)
|
|
|
|
@Parameter(
|
|
title: .init("widgets.controls.open_sensor.configuration.parameter.entity", defaultValue: "Sensor"),
|
|
optionsProvider: SensorEntityOptionsProvider()
|
|
)
|
|
var entity: HAAppEntityAppIntentEntity?
|
|
|
|
@Parameter(
|
|
title: .init("app_intents.scenes.icon.title", defaultValue: "Icon")
|
|
)
|
|
var icon: SFSymbolEntity?
|
|
@Parameter(
|
|
title: .init("app_intents.display_text.title", defaultValue: "Display Text")
|
|
)
|
|
var displayText: String?
|
|
}
|
|
|
|
@available(iOS 18.0, *)
|
|
struct SensorEntityOptionsProvider: DynamicOptionsProvider {
|
|
func results() async throws -> IntentItemCollection<HAAppEntityAppIntentEntity> {
|
|
let entities = ControlEntityProvider(domains: [.sensor, .binarySensor]).getEntities()
|
|
return makeHAEntityIntentItemCollection(
|
|
entities: entities,
|
|
defaultIconName: SFSymbol.eye.rawValue
|
|
)
|
|
}
|
|
}
|