iOS/Sources/Shared/Intents/FocusStatusIntentHandler.swift
Michal Šrůtek 3146e08aac
Available checks cleanup for iOS 15 and watchOS 8 (#2622)
<!-- 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 -->

As the [minimum watchOS is
8](https://github.com/home-assistant/iOS/pull/2609) and [minimum iOS
15](https://github.com/home-assistant/iOS/pull/2469), this PR removes
redundant `#available` checks.

Co-authored-by: Bruno Pantaleão Gonçalves <bruno.ing879@gmail.com>
2024-03-04 15:36:55 +01:00

30 lines
1.0 KiB
Swift

import Foundation
import Intents
import PromiseKit
class FocusStatusIntentHandler: NSObject, INShareFocusStatusIntentHandling {
func handle(intent: INShareFocusStatusIntent, completion: @escaping (INShareFocusStatusIntentResponse) -> Void) {
let currentState = intent.focusStatus
Current.focusStatus.update(fromReceived: currentState)
Current.Log.info("starting, status from intent is \(String(describing: currentState)) from \(intent)")
let limitedTo: [SensorProvider.Type]?
if Current.isCatalyst {
limitedTo = [FocusSensor.self]
} else {
limitedTo = nil
}
when(fulfilled: Current.apis.map {
$0.UpdateSensors(trigger: .Siri, limitedTo: limitedTo)
}).done {
Current.Log.info("finished successfully")
completion(.init(code: .success, userActivity: nil))
}.catch { error in
Current.Log.error("failed: \(error)")
completion(.init(code: .failure, userActivity: nil))
}
}
}