forked from SmartThingsCommunity/SmartThingsPublic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request SmartThingsCommunity#2839 from SmartThingsCommunit…
…y/staging Rolling up staging to production
- Loading branch information
Showing
13 changed files
with
253 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
devicetypes/smartthings/virtual-dimmer-switch.src/virtual-dimmer-switch.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/** | ||
* Copyright 2017 SmartThings | ||
* | ||
* Provides a virtual dimmer switch | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License | ||
* for the specific language governing permissions and limitations under the License. | ||
* | ||
*/ | ||
metadata { | ||
definition (name: "Virtual Dimmer Switch", namespace: "smartthings", author: "SmartThings", runLocally: true, minHubCoreVersion: '000.021.00001', executeCommandsLocally: true) { | ||
capability "Actuator" | ||
capability "Sensor" | ||
capability "Switch" | ||
capability "Switch Level" | ||
} | ||
|
||
preferences {} | ||
|
||
tiles(scale: 2) { | ||
multiAttributeTile(name:"switch", type: "lighting", width: 6, height: 4, canChangeIcon: true){ | ||
tileAttribute ("device.switch", key: "PRIMARY_CONTROL") { | ||
attributeState "on", label:'${name}', action:"switch.off", icon:"st.Home.home30", backgroundColor:"#00A0DC", nextState:"turningOff" | ||
attributeState "off", label:'${name}', action:"switch.on", icon:"st.Home.home30", backgroundColor:"#FFFFFF", nextState:"turningOn", defaultState: true | ||
attributeState "turningOn", label:'Turning On', action:"switch.off", icon:"st.Home.home30", backgroundColor:"#00A0DC", nextState:"turningOn" | ||
attributeState "turningOff", label:'Turning Off', action:"switch.on", icon:"st.Home.home30", backgroundColor:"#FFFFFF", nextState:"turningOff" | ||
} | ||
tileAttribute ("device.level", key: "SLIDER_CONTROL") { | ||
attributeState "level", action: "setLevel" | ||
} | ||
tileAttribute ("brightnessLabel", key: "SECONDARY_CONTROL") { | ||
attributeState "Brightness", label: '${name}', defaultState: true | ||
} | ||
} | ||
|
||
standardTile("explicitOn", "device.switch", width: 2, height: 2, decoration: "flat") { | ||
state "default", label: "On", action: "switch.on", icon: "st.Home.home30", backgroundColor: "#ffffff" | ||
} | ||
standardTile("explicitOff", "device.switch", width: 2, height: 2, decoration: "flat") { | ||
state "default", label: "Off", action: "switch.off", icon: "st.Home.home30", backgroundColor: "#ffffff" | ||
} | ||
controlTile("levelSlider", "device.level", "slider", width: 2, height: 2, inactiveLabel: false, range: "(1..100)") { | ||
state "physicalLevel", action: "switch level.setLevel" | ||
} | ||
|
||
main(["switch"]) | ||
details(["switch", "explicitOn", "explicitOff", "levelSlider"]) | ||
|
||
} | ||
} | ||
|
||
def parse(String description) { | ||
} | ||
|
||
def on() { | ||
log.trace "Executing 'on'" | ||
turnOn() | ||
} | ||
|
||
def off() { | ||
log.trace "Executing 'off'" | ||
turnOff() | ||
} | ||
|
||
def setLevel(value) { | ||
log.trace "Executing setLevel $value" | ||
Map levelEventMap = buildSetLevelEvent(value) | ||
if (levelEventMap.value == 0) { | ||
turnOff() | ||
// notice that we don't set the level to 0' | ||
} else { | ||
implicitOn() | ||
sendEvent(levelEventMap) | ||
} | ||
} | ||
|
||
private Map buildSetLevelEvent(value) { | ||
def intValue = value as Integer | ||
def newLevel = Math.max(Math.min(intValue, 100), 0) | ||
Map eventMap = [name: "level", value: newLevel, unit: "%", isStateChange: true] | ||
return eventMap | ||
} | ||
def setLevel(value, duration) { | ||
log.trace "Executing setLevel $value (ignoring duration)" | ||
setLevel(value) | ||
} | ||
|
||
private implicitOn() { | ||
if (device.currentValue("switch") != "on") { | ||
turnOn() | ||
} | ||
} | ||
|
||
private turnOn() { | ||
sendEvent(name: "switch", value: "on", isStateChange: true) | ||
} | ||
|
||
private turnOff() { | ||
sendEvent(name: "switch", value: "off", isStateChange: true) | ||
} | ||
|
||
def installed() { | ||
setLevel(100) | ||
} |
61 changes: 61 additions & 0 deletions
61
devicetypes/smartthings/virtual-switch.src/virtual-switch.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* Copyright 2017 SmartThings | ||
* | ||
* Provides a virtual switch. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License | ||
* for the specific language governing permissions and limitations under the License. | ||
* | ||
*/ | ||
metadata { | ||
definition (name: "Virtual Switch", namespace: "smartthings", author: "SmartThings", runLocally: true, minHubCoreVersion: '000.021.00001', executeCommandsLocally: true) { | ||
capability "Actuator" | ||
capability "Sensor" | ||
capability "Switch" | ||
} | ||
|
||
preferences {} | ||
|
||
tiles(scale: 2) { | ||
multiAttributeTile(name:"switch", type: "lighting", width: 6, height: 4, canChangeIcon: true){ | ||
tileAttribute ("device.switch", key: "PRIMARY_CONTROL") { | ||
attributeState "on", label:'${name}', action:"switch.off", icon:"st.Home.home30", backgroundColor:"#00A0DC", nextState:"turningOff" | ||
attributeState "off", label:'${name}', action:"switch.on", icon:"st.Home.home30", backgroundColor:"#FFFFFF", nextState:"turningOn", defaultState: true | ||
attributeState "turningOn", label:'Turning On', action:"switch.off", icon:"st.Home.home30", backgroundColor:"#00A0DC", nextState:"turningOn" | ||
attributeState "turningOff", label:'Turning Off', action:"switch.on", icon:"st.Home.home30", backgroundColor:"#FFFFFF", nextState:"turningOff" | ||
} | ||
} | ||
|
||
standardTile("explicitOn", "device.switch", width: 2, height: 2, decoration: "flat") { | ||
state "default", label: "On", action: "switch.on", icon: "st.Home.home30", backgroundColor: "#ffffff" | ||
} | ||
standardTile("explicitOff", "device.switch", width: 2, height: 2, decoration: "flat") { | ||
state "default", label: "Off", action: "switch.off", icon: "st.Home.home30", backgroundColor: "#ffffff" | ||
} | ||
|
||
main(["switch"]) | ||
details(["switch", "explicitOn", "explicitOff"]) | ||
|
||
} | ||
} | ||
|
||
def parse(String description) { | ||
} | ||
|
||
def on() { | ||
sendEvent(name: "switch", value: "on", isStateChange: true) | ||
} | ||
|
||
def off() { | ||
sendEvent(name: "switch", value: "off", isStateChange: true) | ||
} | ||
|
||
def installed() { | ||
on() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
smartapps/smartthings/virtual-device-manager.src/virtual-device-manager.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* Virtual Device Manager | ||
* | ||
* Copyright 2015 Bob Florian/SmartThings | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at: | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License | ||
* for the specific language governing permissions and limitations under the License. | ||
* | ||
*/ | ||
|
||
definition( | ||
name: "Virtual Device Manager", | ||
namespace: "smartthings", | ||
author: "SmartThings", | ||
description: "Creates virtual devices", | ||
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png", | ||
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/[email protected]", | ||
iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/[email protected]", | ||
singleInstance: true, | ||
pausable: false | ||
) | ||
|
||
|
||
preferences { | ||
page name: "mainPage", install: true, uninstall: true | ||
} | ||
|
||
def mainPage() { | ||
dynamicPage(name: "mainPage") { | ||
section { | ||
input "virtualDeviceType", "enum", title: "Which type of virtual device do you want to create?", multiple: false, required: true, options: ["Virtual Switch", "Virtual Dimmer Switch"] | ||
input "theHub", "hub", title: "Select the hub (required for local execution) (Optional)", multiple: false, required: false | ||
} | ||
} | ||
} | ||
|
||
def installed() { | ||
log.debug "Installed with settings: ${settings}" | ||
state.nextDni = 1 | ||
} | ||
|
||
def updated() { | ||
log.debug "Updated with settings: ${settings}" | ||
initialize() | ||
} | ||
|
||
def initialize() { | ||
def latestDni = state.nextDni | ||
if (virtualDeviceType) { | ||
def d = addChildDevice("smartthings", virtualDeviceType, "virtual-$latestDni", theHub?.id, [completedSetup: true, label: "$virtualDeviceType $latestDni"]) | ||
latestDni++ | ||
state.nextDni = latestDni | ||
} else { | ||
log.error "Failed creating Virtual Device because the device type was missing" | ||
} | ||
} |