Skip to content

Commit

Permalink
Suggest listened to events as shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
robbiet480 committed Sep 19, 2018
1 parent 08aa6d5 commit f4fc40d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
18 changes: 16 additions & 2 deletions HomeAssistant/AppDelegate.swift
Expand Up @@ -68,13 +68,27 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}

_ = HomeAssistantAPI.authenticatedAPIPromise.then { api in
api.GetEvents()
}.then { eventsResp -> Promise<HomeAssistantAPI> in
for event in eventsResp {
if let eventName = event.Event {
if eventName == "*" {
continue
}
if let shortcut = INShortcut(intent: FireEventIntent(eventName: eventName)) {
shortcutsToSuggest.append(shortcut)
}
}
}

return HomeAssistantAPI.authenticatedAPIPromise
}.then { api in
api.GetServices()
}.done { serviceResp in
for domainContainer in serviceResp {
let domain = domainContainer.Domain
for service in domainContainer.Services {
if let shortcut = INShortcut(intent: CallServiceIntent(domain: domain,
service: service.key,
if let shortcut = INShortcut(intent: CallServiceIntent(domain: domain, service: service.key,
description: service.value.Description)) {
shortcutsToSuggest.append(shortcut)
}
Expand Down
14 changes: 7 additions & 7 deletions HomeAssistant/Resources/Intents.intentdefinition
Expand Up @@ -97,7 +97,7 @@
<key>INIntentParameterCombinationIsPrimary</key>
<true/>
<key>INIntentParameterCombinationSubtitle</key>
<string>Call service ${serviceDomain}.${service} with data ${payload}</string>
<string>Call service ${serviceDomain}.${service} with data: ${payload}</string>
<key>INIntentParameterCombinationSubtitleID</key>
<string>le6NdS</string>
<key>INIntentParameterCombinationSupportsBackgroundExecution</key>
Expand All @@ -112,7 +112,7 @@
<key>INIntentParameterCombinationIsPrimary</key>
<false/>
<key>INIntentParameterCombinationSubtitle</key>
<string>${serviceDescription}. Will send pasteboard contents as payload.</string>
<string>${serviceDescription}</string>
<key>INIntentParameterCombinationSubtitleID</key>
<string>SGxPSB</string>
<key>INIntentParameterCombinationSupportsBackgroundExecution</key>
Expand All @@ -127,7 +127,7 @@
<key>INIntentParameterCombinationIsPrimary</key>
<false/>
<key>INIntentParameterCombinationSubtitle</key>
<string>Call service ${serviceDomain}.${service}. Will send pasteboard contents as payload.</string>
<string>Call service ${serviceDomain}.${service}</string>
<key>INIntentParameterCombinationSubtitleID</key>
<string>MDmaRg</string>
<key>INIntentParameterCombinationSupportsBackgroundExecution</key>
Expand Down Expand Up @@ -479,13 +479,13 @@
<key>INIntentParameterCombinationIsPrimary</key>
<false/>
<key>INIntentParameterCombinationSubtitle</key>
<string>Fires ${eventName} to the Home Assistant event bus. Will send pasteboard contents as event data.</string>
<string>Fires an event named ${eventName} to the Home Assistant event bus. Will send pasteboard contents as event data.</string>
<key>INIntentParameterCombinationSubtitleID</key>
<string>nIl9ET</string>
<key>INIntentParameterCombinationSupportsBackgroundExecution</key>
<true/>
<key>INIntentParameterCombinationTitle</key>
<string>Fires ${eventName} with pasteboard data</string>
<string>Fire ${eventName} with pasteboard data</string>
<key>INIntentParameterCombinationTitleID</key>
<string>lnrohM</string>
</dict>
Expand All @@ -494,13 +494,13 @@
<key>INIntentParameterCombinationIsPrimary</key>
<true/>
<key>INIntentParameterCombinationSubtitle</key>
<string>Fires ${eventName} to the Home Assistant event bus with ${eventData}.</string>
<string>Fires an event named ${eventName} to the Home Assistant event bus with ${eventData}.</string>
<key>INIntentParameterCombinationSubtitleID</key>
<string>GoLNMt</string>
<key>INIntentParameterCombinationSupportsBackgroundExecution</key>
<true/>
<key>INIntentParameterCombinationTitle</key>
<string>Fire event ${eventName} with pre set data</string>
<string>Fire ${eventName} with data</string>
<key>INIntentParameterCombinationTitleID</key>
<string>yS9QV0</string>
</dict>
Expand Down
4 changes: 4 additions & 0 deletions Shared/API/HAAPI.swift
Expand Up @@ -246,6 +246,10 @@ public class HomeAssistantAPI {
return self.request(path: "services", callingFunctionName: "\(#function)")
}

public func GetEvents() -> Promise<[EventsResponse]> {
return self.request(path: "events", callingFunctionName: "\(#function)")
}

public func GetStates() -> Promise<[Entity]> {
return self.request(path: "states", callingFunctionName: "\(#function)")
}
Expand Down
10 changes: 5 additions & 5 deletions Shared/API/Responses/Events.swift
Expand Up @@ -9,15 +9,15 @@
import Foundation
import ObjectMapper

class EventsResponse: Mappable {
var Event: String?
var ListenerCount: Int?
public class EventsResponse: Mappable {
public var Event: String?
public var ListenerCount: Int?

required init?(map: Map) {
public required init?(map: Map) {

}

func mapping(map: Map) {
public func mapping(map: Map) {
Event <- map["event"]
ListenerCount <- map["listener_count"]
}
Expand Down

0 comments on commit f4fc40d

Please sign in to comment.