mirror of
https://github.com/home-assistant/iOS.git
synced 2026-06-19 07:24:05 -05:00
Adds new fastlane lanes: - `fastlane lint` which checks the linters - `fastlane autocorrect` which applies the linters which can autocorrect (Rubocop, SwiftFormat) Adds a build step to the Codegen abstract target which runs SwiftFormat in lint mode, pointing out what it's going to change when run. Applies SwiftFormat to nearly all code -- exempts a few externally-sourced files and generated code.
47 lines
1.4 KiB
Swift
47 lines
1.4 KiB
Swift
import Foundation
|
|
import PromiseKit
|
|
import UserNotifications
|
|
|
|
extension WebhookResponseIdentifier {
|
|
static var serviceCall: Self { .init(rawValue: "serviceCall") }
|
|
}
|
|
|
|
struct WebhookResponseServiceCall: WebhookResponseHandler {
|
|
let api: HomeAssistantAPI
|
|
init(api: HomeAssistantAPI) {
|
|
self.api = api
|
|
}
|
|
|
|
static func shouldReplace(request current: WebhookRequest, with proposed: WebhookRequest) -> Bool {
|
|
// every service call is distinct
|
|
false
|
|
}
|
|
|
|
func handle(
|
|
request: Promise<WebhookRequest>,
|
|
result: Promise<Any>
|
|
) -> Guarantee<WebhookResponseHandlerResult> {
|
|
firstly {
|
|
when(fulfilled: request, result)
|
|
}.get { request, _ in
|
|
let requestDictionary = try request.asDictionary()
|
|
|
|
let domain = requestDictionary["domain"] as? String ?? "(unknown)"
|
|
let service = requestDictionary["service"] as? String ?? "(unknown)"
|
|
let payload = requestDictionary["service_data"] as? [String: Any] ?? [:]
|
|
|
|
let event = ClientEvent(
|
|
text: "Called service: \(domain).\(service)",
|
|
type: .serviceCall,
|
|
payload: payload
|
|
)
|
|
|
|
Current.clientEventStore.addEvent(event)
|
|
}.then { _ in
|
|
Guarantee.value(WebhookResponseHandlerResult.default)
|
|
}.recover { _ in
|
|
Guarantee.value(WebhookResponseHandlerResult.default)
|
|
}
|
|
}
|
|
}
|