Update Light_Rule.groovy
[smartapps.git] / official / device-tile-controller.groovy
1 /**
2  *  Device Tile Controller
3  *
4  *  Copyright 2016 SmartThings
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7  *  in compliance with the License. You may obtain a copy of the License at:
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
12  *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
13  *  for the specific language governing permissions and limitations under the License.
14  *
15  */
16 definition(
17     name: "Device Tile Controller",
18     namespace: "smartthings/tile-ux",
19     author: "SmartThings",
20     description: "A controller SmartApp to install virtual devices into your location in order to simulate various native Device Tiles.",
21     category: "SmartThings Internal",
22     iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
23     iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
24     iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
25     singleInstance: true)
26
27
28 preferences {
29     // landing page
30     page(name: "defaultPage")
31 }
32
33 def defaultPage() {
34     dynamicPage(name: "defaultPage", install: true, uninstall: true) {
35         section {
36             paragraph "Select on Unselect the devices that you want to install"
37         }
38         section(title: "Multi Attribute Tile Types") {
39             input(type: "bool", name: "genericDeviceTile", title: "generic", description: "A device that showcases the various use of generic multi-attribute-tiles.", defaultValue: "false")
40             input(type: "bool", name: "lightingDeviceTile", title: "lighting", description: "A device that showcases the various use of lighting multi-attribute-tiles.", defaultValue: "false")
41             input(type: "bool", name: "thermostatDeviceTile", title: "thermostat", description: "A device that showcases the various use of thermostat multi-attribute-tiles.", defaultValue: "true")
42             input(type: "bool", name: "mediaPlayerDeviceTile", title: "media player", description: "A device that showcases the various use of mediaPlayer multi-attribute-tiles.", defaultValue: "false")
43             input(type: "bool", name: "videoPlayerDeviceTile", title: "video player", description: "A device that showcases the various use of videoPlayer multi-attribute-tiles.", defaultValue: "false")
44         }
45         section(title: "Device Tile Types") {
46             input(type: "bool", name: "standardDeviceTile", title: "standard device tiles", description: "A device that showcases the various use of standard device tiles.", defaultValue: "false")
47             input(type: "bool", name: "valueDeviceTile", title: "value device tiles", description: "A device that showcases the various use of value device tiles.", defaultValue: "false")
48             input(type: "bool", name: "presenceDeviceTile", title: "presence device tiles", description: "A device that showcases the various use of color control device tile.", defaultValue: "false")
49         }
50         section(title: "Other Tile Types") {
51             input(type: "bool", name: "carouselDeviceTile", title: "image carousel", description: "A device that showcases the various use of carousel device tile.", defaultValue: "false")
52             input(type: "bool", name: "sliderDeviceTile", title: "slider", description: "A device that showcases the various use of slider device tile.", defaultValue: "false")
53             input(type: "bool", name: "colorWheelDeviceTile", title: "color wheel", description: "A device that showcases the various use of color wheel device tile.", defaultValue: "false")
54         }
55     }
56 }
57
58 def installed() {
59     log.debug "Installed with settings: ${settings}"
60 }
61
62 def uninstalled() {
63     getChildDevices().each {
64         deleteChildDevice(it.deviceNetworkId)
65     }
66 }
67
68 def updated() {
69     log.debug "Updated with settings: ${settings}"
70     unsubscribe()
71     initializeDevices()
72 }
73
74 def initializeDevices() {
75     settings.each { key, value ->
76         log.debug "$key : $value"
77         def existingDevice = getChildDevices().find { it.name == key }
78         log.debug "$existingDevice"
79         if (existingDevice && !value) {
80             deleteChildDevice(existingDevice.deviceNetworkId)
81         } else if (!existingDevice && value) {
82             String dni = UUID.randomUUID()
83             log.debug "$dni"
84             addChildDevice(app.namespace, key, dni, null, [
85                 label: labelMap()[key] ?: key,
86                 completedSetup: true
87             ])
88         }
89     }
90 }
91
92 // Map the name of the Device to a proper Label
93 def labelMap() {
94     [
95         genericDeviceTile: "Tile Multiattribute Generic",
96         lightingDeviceTile: "Tile Multiattribute Lighting",
97         thermostatDeviceTile: "Tile Multiattribute Thermostat",
98         mediaPlayerDeviceTile: "Tile Multiattribute Media Player",
99         videoPlayerDeviceTile: "Tile Multiattribute Video Player",
100         standardDeviceTile: "Tile Device Standard",
101         valueDeviceTile: "Tile Device Value",
102         presenceDeviceTile: "Tile Device Presence",
103         carouselDeviceTile: "Tile Device Carousel",
104         sliderDeviceTile: "Tile Device Slider",
105         colorWheelDeviceTile: "Tile Device Color Wheel"
106     ]
107 }