Update groveStreams.groovy
[smartapps.git] / third-party / camera-motion.groovy
1 /**
2  *  Camera Motion
3  *
4  *  Copyright 2015 Kristopher Kubicki
5  *
6  */
7 definition(
8     name: "Camera Motion",
9     namespace: "KristopherKubicki",
10     author: "kristopher@acm.org",
11     description: "Creates an endpoint for your camera ",
12     category: "Convenience",
13     iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
14     iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
15     iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png")
16
17
18 preferences {
19     page(name: "selectDevices", install: false, uninstall: true, nextPage: "viewURL") {
20         section("Allow endpoint to control this thing...") {
21                         input "motions", "capability.motionSensor", title: "Which simulated motion sensor?"
22                         label title: "Assign a name", required: false
23                         mode title: "Set for specific mode(s)", required: false
24         }
25     }
26     page(name: "viewURL", title: "viewURL", install: true)
27 }
28
29 def installed() {
30         log.debug "Installed with settings: ${settings}"
31 }
32
33 def updated() {
34         log.debug "Updated with settings: ${settings}"
35         unsubscribe()
36
37 }
38
39
40
41 mappings {
42
43     path("/active") {
44         action: [
45             GET: "activeMotion"
46         ]
47     }
48     path("/inactive") {
49         action: [
50             GET: "inactiveMotion"
51         ]
52     }
53 }
54
55 void activeMotion() {
56         log.debug "Updated2 with settings: ${settings}"
57     motions?.active()
58 }
59
60 void inactiveMotion() {
61         log.debug "Updated2 with settings: ${settings}"
62     motions?.inactive()
63 }
64
65
66 def generateURL() {
67         
68         createAccessToken()
69         
70         ["https://graph.api.smartthings.com/api/smartapps/installations/${app.id}/active", "?access_token=${state.accessToken}"]
71 }
72
73
74 def viewURL() {
75         dynamicPage(name: "viewURL", title: "HTTP Motion Endpoint", install:!resetOauth, nextPage: resetOauth ? "viewURL" : null) {
76                         section() {
77                 generateURL() 
78                                 paragraph "Activate: https://graph.api.smartthings.com/api/smartapps/installations/${app.id}/active?access_token=${state.accessToken}"
79                 paragraph "Deactivate: https://graph.api.smartthings.com/api/smartapps/installations/${app.id}/inactive?access_token=${state.accessToken}"
80
81                         }
82         }
83 }