mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-13 05:11:51 +00:00
Compare commits
1 Commits
MSA-1867-1
...
MSA-1864-1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e7e892f41 |
@@ -34,13 +34,13 @@ metadata {
|
||||
tiles(scale: 2) {
|
||||
multiAttributeTile(name:"FGFS", type:"lighting", width:6, height:4) {//with generic type secondary control text is not displayed in Android app
|
||||
tileAttribute("device.water", key:"PRIMARY_CONTROL") {
|
||||
attributeState("dry", icon:"st.alarm.water.dry", backgroundColor:"#ffffff")
|
||||
attributeState("wet", icon:"st.alarm.water.wet", backgroundColor:"#00a0dc")
|
||||
attributeState("dry", icon:"st.alarm.water.dry", backgroundColor:"#00a0dc")
|
||||
attributeState("wet", icon:"st.alarm.water.wet", backgroundColor:"#e86d13")
|
||||
}
|
||||
|
||||
tileAttribute("device.tamper", key:"SECONDARY_CONTROL") {
|
||||
attributeState("active", label:'tamper active', backgroundColor:"#cccccc")
|
||||
attributeState("inactive", label:'tamper inactive', backgroundColor:"#00A0DC")
|
||||
attributeState("active", label:'tamper active', backgroundColor:"#00a0dc")
|
||||
attributeState("inactive", label:'tamper inactive', backgroundColor:"#cccccc")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ metadata {
|
||||
command "clearObstruction"
|
||||
|
||||
fingerprint endpoint: "1", profileId: "0104", inClusters: "0000,0001,0003,0004,0005,0006,0008,0020,0402,0403,0B05,FC01,FC02", outClusters: "0019"
|
||||
fingerprint endpoint: "1", profileId: "0104", inClusters: "0000,0001,0003,0004,0005,0006,0008,0020,0402,0403,0B05,FC01,FC02", outClusters: "0019", manufacturer: "Keen Home Inc", model: "SV01-410-DV-1.0", deviceJoinName: "Keen Home Smart Vent"
|
||||
}
|
||||
|
||||
// simulator metadata
|
||||
|
||||
@@ -32,7 +32,7 @@ metadata {
|
||||
command "switchMode"
|
||||
command "switchFanMode"
|
||||
|
||||
attribute "displayThermostatSetpoint", "string" // Added to be able to show "Auto"/"Off" keeping attribute thermostatSetpoint a number
|
||||
attribute "thermostatSetpoint", "number"
|
||||
attribute "thermostatStatus", "string"
|
||||
attribute "maxHeatingSetpoint", "number"
|
||||
attribute "minHeatingSetpoint", "number"
|
||||
@@ -70,7 +70,7 @@ metadata {
|
||||
state "heat", action:"switchMode", nextState: "updating", icon: "st.thermostat.heat"
|
||||
state "cool", action:"switchMode", nextState: "updating", icon: "st.thermostat.cool"
|
||||
state "auto", action:"switchMode", nextState: "updating", icon: "st.thermostat.auto"
|
||||
state "emergency heat", label:"auxHeatOnly", action:"switchMode", icon: "st.thermostat.emergency-heat" // emergency heat = auxHeatOnly
|
||||
state "auxHeatOnly", action:"switchMode", icon: "st.thermostat.emergency-heat"
|
||||
state "updating", label:"Working", icon: "st.secondary.secondary"
|
||||
}
|
||||
standardTile("fanMode", "device.thermostatFanMode", inactiveLabel: false, decoration: "flat") {
|
||||
@@ -81,8 +81,8 @@ metadata {
|
||||
standardTile("upButtonControl", "device.thermostatSetpoint", inactiveLabel: false, decoration: "flat") {
|
||||
state "setpoint", action:"raiseSetpoint", icon:"st.thermostat.thermostat-up"
|
||||
}
|
||||
valueTile("displayThermostatSetpoint", "device.displayThermostatSetpoint", width: 1, height: 1, decoration: "flat") {
|
||||
state "displayThermostatSetpoint", label:'${currentValue}'
|
||||
valueTile("thermostatSetpoint", "device.thermostatSetpoint", width: 1, height: 1, decoration: "flat") {
|
||||
state "thermostatSetpoint", label:'${currentValue}'
|
||||
}
|
||||
valueTile("currentStatus", "device.thermostatStatus", height: 1, width: 2, decoration: "flat") {
|
||||
state "thermostatStatus", label:'${currentValue}', backgroundColor:"#ffffff"
|
||||
@@ -113,7 +113,7 @@ metadata {
|
||||
state "humidity", label:'${currentValue}%'
|
||||
}
|
||||
main "temperature"
|
||||
details(["temperature", "upButtonControl", "displayThermostatSetpoint", "currentStatus", "downButtonControl", "mode", "fanMode","humidity", "resumeProgram", "refresh"])
|
||||
details(["temperature", "upButtonControl", "thermostatSetpoint", "currentStatus", "downButtonControl", "mode", "fanMode","humidity", "resumeProgram", "refresh"])
|
||||
}
|
||||
|
||||
preferences {
|
||||
@@ -452,10 +452,10 @@ def emergencyHeat() {
|
||||
}
|
||||
|
||||
def auxHeatOnly() {
|
||||
log.debug "auxHeatOnly = emergency heat"
|
||||
log.debug "auxHeatOnly"
|
||||
def deviceId = device.deviceNetworkId.split(/\./).last()
|
||||
if (parent.setMode ("auxHeatOnly", deviceId))
|
||||
generateModeEvent("emergency heat") // emergency heat = auxHeatOnly
|
||||
generateModeEvent("auxHeatOnly")
|
||||
else {
|
||||
log.debug "Error setting new mode."
|
||||
def currentMode = device.currentState("thermostatMode")?.value
|
||||
@@ -574,23 +574,17 @@ def generateSetpointEvent() {
|
||||
sendEvent("name":"heatingSetpoint", "value":heatingSetpoint, "unit":location.temperatureScale)
|
||||
sendEvent("name":"coolingSetpoint", "value":coolingSetpoint, "unit":location.temperatureScale)
|
||||
|
||||
def averageSetpoint = roundC((heatingSetpoint + coolingSetpoint) / 2)
|
||||
if (mode == "heat") {
|
||||
sendEvent("name":"thermostatSetpoint", "value":heatingSetpoint, "unit":location.temperatureScale)
|
||||
sendEvent("name":"displayThermostatSetpoint", "value":heatingSetpoint, "unit":location.temperatureScale, displayed: false)
|
||||
}
|
||||
else if (mode == "cool") {
|
||||
sendEvent("name":"thermostatSetpoint", "value":coolingSetpoint, "unit":location.temperatureScale)
|
||||
sendEvent("name":"displayThermostatSetpoint", "value":coolingSetpoint, "unit":location.temperatureScale, displayed: false)
|
||||
} else if (mode == "auto") {
|
||||
sendEvent("name":"thermostatSetpoint", "value":averageSetpoint, "unit":location.temperatureScale)
|
||||
sendEvent("name":"displayThermostatSetpoint", "value":"Auto", displayed: false)
|
||||
sendEvent("name":"thermostatSetpoint", "value":"Auto")
|
||||
} else if (mode == "off") {
|
||||
sendEvent("name":"thermostatSetpoint", "value":averageSetpoint, "unit":location.temperatureScale)
|
||||
sendEvent("name":"displayThermostatSetpoint", "value":"Off", displayed: false)
|
||||
} else if (mode == "emergency heat") { // emergency heat = auxHeatOnly
|
||||
sendEvent("name":"thermostatSetpoint", "value":"Off")
|
||||
} else if (mode == "auxHeatOnly") {
|
||||
sendEvent("name":"thermostatSetpoint", "value":heatingSetpoint, "unit":location.temperatureScale)
|
||||
sendEvent("name":"displayThermostatSetpoint", "value":heatingSetpoint, "unit":location.temperatureScale, displayed: false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -627,14 +621,13 @@ void raiseSetpoint() {
|
||||
targetvalue = thermostatSetpoint ? thermostatSetpoint : 0
|
||||
targetvalue = location.temperatureScale == "F"? targetvalue + 1 : targetvalue + 0.5
|
||||
|
||||
if ((mode == "heat" || mode == "emergency heat") && targetvalue > maxHeatingSetpoint) { // emergency heat = auxHeatOnly
|
||||
if ((mode == "heat" || mode == "auxHeatOnly") && targetvalue > maxHeatingSetpoint) {
|
||||
targetvalue = maxHeatingSetpoint
|
||||
} else if (mode == "cool" && targetvalue > maxCoolingSetpoint) {
|
||||
targetvalue = maxCoolingSetpoint
|
||||
}
|
||||
|
||||
sendEvent("name":"thermostatSetpoint", "value":targetvalue, "unit":location.temperatureScale, displayed: false)
|
||||
sendEvent("name":"displayThermostatSetpoint", "value":targetvalue, "unit":location.temperatureScale, displayed: false)
|
||||
log.info "In mode $mode raiseSetpoint() to $targetvalue"
|
||||
|
||||
runIn(3, "alterSetpoint", [data: [value:targetvalue], overwrite: true]) //when user click button this runIn will be overwrite
|
||||
@@ -673,14 +666,13 @@ void lowerSetpoint() {
|
||||
targetvalue = thermostatSetpoint ? thermostatSetpoint : 0
|
||||
targetvalue = location.temperatureScale == "F"? targetvalue - 1 : targetvalue - 0.5
|
||||
|
||||
if ((mode == "heat" || mode == "emergency heat") && targetvalue < minHeatingSetpoint) { // emergency heat = auxHeatOnly
|
||||
if ((mode == "heat" || mode == "auxHeatOnly") && targetvalue < minHeatingSetpoint) {
|
||||
targetvalue = minHeatingSetpoint
|
||||
} else if (mode == "cool" && targetvalue < minCoolingSetpoint) {
|
||||
targetvalue = minCoolingSetpoint
|
||||
}
|
||||
|
||||
sendEvent("name":"thermostatSetpoint", "value":targetvalue, "unit":location.temperatureScale, displayed: false)
|
||||
sendEvent("name":"displayThermostatSetpoint", "value":targetvalue, "unit":location.temperatureScale, displayed: false)
|
||||
log.info "In mode $mode lowerSetpoint() to $targetvalue"
|
||||
|
||||
runIn(3, "alterSetpoint", [data: [value:targetvalue], overwrite: true]) //when user click button this runIn will be overwrite
|
||||
@@ -714,7 +706,7 @@ void alterSetpoint(temp) {
|
||||
}
|
||||
|
||||
//step1: check thermostatMode, enforce limits before sending request to cloud
|
||||
if (mode == "heat" || mode == "emergency heat"){ // emergency heat = auxHeatOnly
|
||||
if (mode == "heat" || mode == "auxHeatOnly"){
|
||||
if (temp.value > coolingSetpoint){
|
||||
targetHeatingSetpoint = temp.value
|
||||
targetCoolingSetpoint = temp.value
|
||||
@@ -743,18 +735,15 @@ void alterSetpoint(temp) {
|
||||
|
||||
if (parent.setHold(heatingValue, coolingValue, deviceId, sendHoldType)) {
|
||||
sendEvent("name": "thermostatSetpoint", "value": temp.value, displayed: false)
|
||||
sendEvent("name": "displayThermostatSetpoint", "value": temp.value, displayed: false)
|
||||
sendEvent("name": "heatingSetpoint", "value": targetHeatingSetpoint, "unit": location.temperatureScale)
|
||||
sendEvent("name": "coolingSetpoint", "value": targetCoolingSetpoint, "unit": location.temperatureScale)
|
||||
log.debug "alterSetpoint in mode $mode succeed change setpoint to= ${temp.value}"
|
||||
} else {
|
||||
log.error "Error alterSetpoint()"
|
||||
if (mode == "heat" || mode == "emergency heat"){ // emergency heat = auxHeatOnly
|
||||
if (mode == "heat" || mode == "auxHeatOnly"){
|
||||
sendEvent("name": "thermostatSetpoint", "value": heatingSetpoint.toString(), displayed: false)
|
||||
sendEvent("name": "displayThermostatSetpoint", "value": heatingSetpoint.toString(), displayed: false)
|
||||
} else if (mode == "cool") {
|
||||
sendEvent("name": "thermostatSetpoint", "value": coolingSetpoint.toString(), displayed: false)
|
||||
sendEvent("name": "displayThermostatSetpoint", "value": heatingSetpoint.toString(), displayed: false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -770,7 +759,6 @@ def generateStatusEvent() {
|
||||
def coolingSetpoint = device.currentValue("coolingSetpoint")
|
||||
def temperature = device.currentValue("temperature")
|
||||
def statusText
|
||||
def operatingState = "idle"
|
||||
|
||||
log.debug "Generate Status Event for Mode = ${mode}"
|
||||
log.debug "Temperature = ${temperature}"
|
||||
@@ -779,29 +767,20 @@ def generateStatusEvent() {
|
||||
log.debug "HVAC Mode = ${mode}"
|
||||
|
||||
if (mode == "heat") {
|
||||
if (temperature >= heatingSetpoint) {
|
||||
if (temperature >= heatingSetpoint)
|
||||
statusText = "Right Now: Idle"
|
||||
} else {
|
||||
else
|
||||
statusText = "Heating to ${heatingSetpoint} ${location.temperatureScale}"
|
||||
operatingState = "heating"
|
||||
}
|
||||
} else if (mode == "cool") {
|
||||
if (temperature <= coolingSetpoint) {
|
||||
if (temperature <= coolingSetpoint)
|
||||
statusText = "Right Now: Idle"
|
||||
} else {
|
||||
else
|
||||
statusText = "Cooling to ${coolingSetpoint} ${location.temperatureScale}"
|
||||
operatingState = "cooling"
|
||||
}
|
||||
} else if (mode == "auto") {
|
||||
statusText = "Right Now: Auto"
|
||||
if (temperature < heatingSetpoint) {
|
||||
operatingState = "heating"
|
||||
} else if (temperature > coolingSetpoint) {
|
||||
operatingState = "cooling"
|
||||
}
|
||||
} else if (mode == "off") {
|
||||
statusText = "Right Now: Off"
|
||||
} else if (mode == "emergency heat") { // emergency heat = auxHeatOnly
|
||||
} else if (mode == "auxHeatOnly") {
|
||||
statusText = "Emergency Heat"
|
||||
} else {
|
||||
statusText = "?"
|
||||
@@ -809,7 +788,6 @@ def generateStatusEvent() {
|
||||
|
||||
log.debug "Generate Status Event = ${statusText}"
|
||||
sendEvent("name":"thermostatStatus", "value":statusText, "description":statusText, displayed: true)
|
||||
sendEvent("name":"thermostatOperatingState", "value":operatingState, "description":operatingState, displayed: false)
|
||||
}
|
||||
|
||||
def generateActivityFeedsEvent(notificationMessage) {
|
||||
|
||||
@@ -135,7 +135,10 @@ def refresh() {
|
||||
return zigbee.readAttribute(0xFC45, 0x0000, ["mfgCode": 0x104E]) + // New firmware
|
||||
zigbee.readAttribute(0xFC45, 0x0000, ["mfgCode": 0xC2DF]) + // Original firmware
|
||||
zigbee.readAttribute(zigbee.TEMPERATURE_MEASUREMENT_CLUSTER, 0x0000) +
|
||||
zigbee.readAttribute(zigbee.POWER_CONFIGURATION_CLUSTER, 0x0020)
|
||||
zigbee.readAttribute(zigbee.POWER_CONFIGURATION_CLUSTER, 0x0020) +
|
||||
zigbee.configureReporting(0xFC45, 0x0000, DataType.INT16, 30, 3600, 100) +
|
||||
zigbee.batteryConfig() +
|
||||
zigbee.temperatureConfig(30, 300)
|
||||
}
|
||||
|
||||
def configure() {
|
||||
@@ -147,10 +150,5 @@ def configure() {
|
||||
|
||||
// temperature minReportTime 30 seconds, maxReportTime 5 min. Reporting interval if no activity
|
||||
// battery minReport 30 seconds, maxReportTime 6 hrs by default
|
||||
return refresh() +
|
||||
zigbee.configureReporting(0xFC45, 0x0000, DataType.UINT16, 30, 3600, 100, ["mfgCode": 0x104E]) + // New firmware
|
||||
zigbee.configureReporting(0xFC45, 0x0000, DataType.UINT16, 30, 3600, 100, ["mfgCode": 0xC2DF]) + // Original firmware
|
||||
zigbee.batteryConfig() +
|
||||
zigbee.temperatureConfig(30, 300)
|
||||
|
||||
return refresh()
|
||||
}
|
||||
|
||||
@@ -40,7 +40,6 @@ metadata {
|
||||
fingerprint profileId: "0104", inClusters: "0000,0003,0004,0005,0006,0008,0300,0B04,FC0F", outClusters: "0019", manufacturer: "OSRAM", model: "LIGHTIFY BR RGBW", deviceJoinName: "SYLVANIA Smart BR30 RGBW"
|
||||
fingerprint profileId: "0104", inClusters: "0000,0003,0004,0005,0006,0008,0300,0B04,FC0F", outClusters: "0019", manufacturer: "OSRAM", model: "LIGHTIFY RT RGBW", deviceJoinName: "SYLVANIA Smart RT5/6 RGBW"
|
||||
fingerprint profileId: "0104", inClusters: "0000,0003,0004,0005,0006,0008,0300,0B04,FC0F", outClusters: "0019", manufacturer: "OSRAM", model: "LIGHTIFY FLEX OUTDOOR RGBW", deviceJoinName: "SYLVANIA Smart Outdoor RGBW Flex"
|
||||
fingerprint profileId: "0104", inClusters: "0000, 0003, 0004, 0005, 0006, 0008, 0300", outClusters: "0000, 0003, 0006", manufacturer: "LINGAN", model: "LIGHTIFY A01 RGBW", deviceJoinName: "LINGAN LIGHTIFY LED Smart Connected Light"
|
||||
}
|
||||
|
||||
// UI tile definitions
|
||||
|
||||
@@ -25,13 +25,11 @@ metadata {
|
||||
capability "Switch Level"
|
||||
capability "Sensor"
|
||||
capability "Actuator"
|
||||
capability "Health Check"
|
||||
capability "Light"
|
||||
|
||||
command "reset"
|
||||
|
||||
fingerprint inClusters: "0x26,0x32"
|
||||
fingerprint mfr:"0086", prod:"0003", model:"001B", deviceJoinName: "Aeon Labs Micro Smart Dimmer 2E"
|
||||
}
|
||||
|
||||
simulator {
|
||||
@@ -101,9 +99,6 @@ def parse(String description) {
|
||||
}
|
||||
|
||||
def updated() {
|
||||
// Device-Watch simply pings if no device events received for 32min(checkInterval)
|
||||
sendEvent(name: "checkInterval", value: 2 * 15 * 60 + 2 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID])
|
||||
|
||||
response(refresh())
|
||||
}
|
||||
|
||||
@@ -168,14 +163,6 @@ def poll() {
|
||||
], 1000)
|
||||
}
|
||||
|
||||
/**
|
||||
* PING is used by Device-Watch in attempt to reach the Device
|
||||
* */
|
||||
def ping() {
|
||||
log.debug "ping() called"
|
||||
refresh()
|
||||
}
|
||||
|
||||
def refresh() {
|
||||
delayBetween([
|
||||
zwave.switchMultilevelV1.switchMultilevelGet().format(),
|
||||
|
||||
@@ -0,0 +1,445 @@
|
||||
/**
|
||||
* MediaRenderer Service Manager v 2.0.1
|
||||
*
|
||||
* Author: SmartThings - Ulises Mujica
|
||||
*/
|
||||
|
||||
definition(
|
||||
name: "MediaRenderer (Connect)",
|
||||
namespace: "mujica",
|
||||
author: "SmartThings - Ulises Mujica",
|
||||
description: "Allows you to control your Media Renderer from the SmartThings app. Perform basic functions like play, pause, stop, change track, and check artist and song name from the Things screen.",
|
||||
category: "SmartThings Labs",
|
||||
singleInstance: true,
|
||||
iconUrl: "https://graph.api.smartthings.com/api/devices/icons/st.secondary.smartapps-tile?displaySize=2x",
|
||||
iconX2Url: "https://graph.api.smartthings.com/api/devices/icons/st.secondary.smartapps-tile?displaySize=2x"
|
||||
)
|
||||
|
||||
preferences {
|
||||
page(name: "MainPage", title: "Search and config your Media Renderers", install:true, uninstall: true){
|
||||
section("") {
|
||||
href(name: "discover",title: "Discovery process",required: false,page: "mediaRendererDiscovery",description: "tap to start searching")
|
||||
}
|
||||
section("Options", hideable: true, hidden: true) {
|
||||
input("refreshMRInterval", "number", title:"Enter refresh players interval (min)",defaultValue:"15", required:false)
|
||||
}
|
||||
}
|
||||
page(name: "mediaRendererDiscovery", title:"Discovery Started!")
|
||||
}
|
||||
|
||||
def mediaRendererDiscovery()
|
||||
{
|
||||
log.trace "mediaRendererDiscovery() state.subscribe ${state.subscribe}"
|
||||
if(canInstallLabs())
|
||||
{
|
||||
|
||||
|
||||
int mediaRendererRefreshCount = !state.mediaRendererRefreshCount ? 0 : state.mediaRendererRefreshCount as int
|
||||
state.mediaRendererRefreshCount = mediaRendererRefreshCount + 1
|
||||
def refreshInterval = 5
|
||||
|
||||
def options = mediaRenderersDiscovered() ?: []
|
||||
|
||||
def numFound = options.size() ?: 0
|
||||
|
||||
if(!state.subscribe) {
|
||||
subscribe(location, null, locationHandler, [filterEvents:false])
|
||||
state.subscribe = true
|
||||
}
|
||||
|
||||
//mediaRenderer discovery request every 5 //25 seconds
|
||||
if((mediaRendererRefreshCount % 8) == 0) {
|
||||
discoverMediaRenderers()
|
||||
}
|
||||
|
||||
//setup.xml request every 3 seconds except on discoveries
|
||||
if(((mediaRendererRefreshCount % 1) == 0) && ((mediaRendererRefreshCount % 8) != 0)) {
|
||||
verifyMediaRendererPlayer()
|
||||
}
|
||||
|
||||
return dynamicPage(name:"mediaRendererDiscovery", title:"Discovery Started!", nextPage:"", refreshInterval:refreshInterval) {
|
||||
section("Please wait while we discover your MediaRenderer. Discovery can take five minutes or more, so sit back and relax! Select your device below once discovered.") {
|
||||
input "selectedMediaRenderer", "enum", required:false, title:"Select Media Renderer (${numFound} found)", multiple:true, options:options
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
def upgradeNeeded = """To use SmartThings Labs, your Hub should be completely up to date.
|
||||
To update your Hub, access Location Settings in the Main Menu (tap the gear next to your location name), select your Hub, and choose "Update Hub"."""
|
||||
|
||||
return dynamicPage(name:"mediaRendererDiscovery", title:"Upgrade needed!", nextPage:"", install:false, uninstall: true) {
|
||||
section("Upgrade") {
|
||||
paragraph "$upgradeNeeded"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private discoverMediaRenderers()
|
||||
{
|
||||
sendHubCommand(new physicalgraph.device.HubAction("lan discovery urn:schemas-upnp-org:device:MediaRenderer:1", physicalgraph.device.Protocol.LAN))
|
||||
}
|
||||
|
||||
|
||||
private verifyMediaRendererPlayer() {
|
||||
def devices = getMediaRendererPlayer().findAll { it?.value?.verified != true }
|
||||
|
||||
devices.each {
|
||||
verifyMediaRenderer((it?.value?.ip + ":" + it?.value?.port), it?.value?.ssdpPath)
|
||||
}
|
||||
}
|
||||
|
||||
private verifyMediaRenderer(String deviceNetworkId, String ssdpPath) {
|
||||
String ip = getHostAddress(deviceNetworkId)
|
||||
if(!ssdpPath){
|
||||
ssdpPath = "/"
|
||||
}
|
||||
log.trace "verifyMediaRenderer($deviceNetworkId, $ssdpPath, $ip)"
|
||||
sendHubCommand(new physicalgraph.device.HubAction("""GET $ssdpPath HTTP/1.1\r\nHOST: $ip\r\n\r\n""", physicalgraph.device.Protocol.LAN, "${deviceNetworkId}"))
|
||||
}
|
||||
|
||||
Map mediaRenderersDiscovered() {
|
||||
def vmediaRenderers = getVerifiedMediaRendererPlayer()
|
||||
def map = [:]
|
||||
vmediaRenderers.each {
|
||||
def value = "${it.value.name}"
|
||||
def key = it.value.ip + ":" + it.value.port
|
||||
map["${key}"] = value
|
||||
}
|
||||
map
|
||||
}
|
||||
|
||||
def getMediaRendererPlayer()
|
||||
{
|
||||
state.mediaRenderers = state.mediaRenderers ?: [:]
|
||||
}
|
||||
|
||||
def getVerifiedMediaRendererPlayer()
|
||||
{
|
||||
getMediaRendererPlayer().findAll{ it?.value?.verified == true }
|
||||
}
|
||||
|
||||
def installed() {
|
||||
log.trace "installed()"
|
||||
//initialize()
|
||||
}
|
||||
|
||||
def updated() {
|
||||
log.trace "updated()"
|
||||
|
||||
|
||||
if (selectedMediaRenderer) {
|
||||
addMediaRenderer()
|
||||
}
|
||||
|
||||
unsubscribe()
|
||||
state.subscribe = false
|
||||
unschedule()
|
||||
scheduleTimer()
|
||||
scheduleActions()
|
||||
|
||||
refreshAll()
|
||||
syncDevices()
|
||||
}
|
||||
|
||||
def uninstalled() {
|
||||
def devices = getChildDevices()
|
||||
devices.each {
|
||||
deleteChildDevice(it.deviceNetworkId)
|
||||
}
|
||||
}
|
||||
|
||||
def initialize() {
|
||||
// remove location subscription aftwards
|
||||
log.trace "initialize()"
|
||||
//scheduledRefreshHandler()
|
||||
}
|
||||
|
||||
|
||||
def scheduledRefreshHandler(){
|
||||
|
||||
}
|
||||
|
||||
def scheduledTimerHandler() {
|
||||
timerAll()
|
||||
}
|
||||
|
||||
def scheduledActionsHandler() {
|
||||
syncDevices()
|
||||
//runIn(60, scheduledRefreshHandler)
|
||||
}
|
||||
|
||||
private scheduleTimer() {
|
||||
def cron = "0 0/3 * * * ?"
|
||||
schedule(cron, scheduledTimerHandler)
|
||||
}
|
||||
|
||||
private scheduleActions() {
|
||||
def minutes = Math.max(settings.refreshMRInterval.toInteger(),1)
|
||||
def cron = "0 0/${minutes} * * * ?"
|
||||
schedule(cron, scheduledActionsHandler)
|
||||
}
|
||||
|
||||
private syncDevices() {
|
||||
log.debug "syncDevices()"
|
||||
if(!state.subscribe) {
|
||||
subscribe(location, null, locationHandler, [filterEvents:false])
|
||||
log.trace "subscribe($location, null, locationHandler, [filterEvents:false])"
|
||||
state.subscribe = true
|
||||
}
|
||||
|
||||
discoverMediaRenderers()
|
||||
}
|
||||
|
||||
private timerAll(){
|
||||
childDevices*.poll()
|
||||
}
|
||||
|
||||
private refreshAll(){
|
||||
childDevices*.refresh()
|
||||
}
|
||||
|
||||
def addMediaRenderer() {
|
||||
def players = getVerifiedMediaRendererPlayer()
|
||||
def runSubscribe = false
|
||||
selectedMediaRenderer.each { dni ->
|
||||
def d = getChildDevice(dni)
|
||||
if(!d) {
|
||||
def newPlayer = players.find { (it.value.ip + ":" + it.value.port) == dni }
|
||||
if (newPlayer){
|
||||
d = addChildDevice("mujica", "DLNA Player", dni, newPlayer?.value.hub, [label:"${newPlayer?.value.name} Speaker","data":["model":newPlayer?.value.model,"avtcurl":newPlayer?.value.avtcurl,"avteurl":newPlayer?.value.avteurl,"rccurl":newPlayer?.value.rccurl,"rceurl":newPlayer?.value.rceurl,"udn":newPlayer?.value.udn,"dni":dni]])
|
||||
}
|
||||
runSubscribe = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def locationHandler(evt) {
|
||||
def description = evt.description
|
||||
def hub = evt?.hubId
|
||||
def parsedEvent = parseEventMessage(description)
|
||||
def msg = parseLanMessage(description)
|
||||
|
||||
if (msg?.headers?.sid)
|
||||
{
|
||||
childDevices*.each { childDevice ->
|
||||
if(childDevice.getDataValue('subscriptionId') == ((msg?.headers?.sid ?:"") - "uuid:")|| childDevice.getDataValue('subscriptionId1') == ((msg?.headers?.sid ?:"") - "uuid:")){
|
||||
childDevice.parse(description)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
parsedEvent << ["hub":hub]
|
||||
|
||||
if (parsedEvent?.ssdpTerm?.contains("urn:schemas-upnp-org:device:MediaRenderer:1"))
|
||||
{ //SSDP DISCOVERY EVENTS
|
||||
log.debug "MediaRenderer device found" + parsedEvent
|
||||
def mediaRenderers = getMediaRendererPlayer()
|
||||
|
||||
|
||||
if (!(mediaRenderers."${parsedEvent.ssdpUSN.toString()}"))
|
||||
{ //mediaRenderer does not exist
|
||||
mediaRenderers << ["${parsedEvent.ssdpUSN.toString()}":parsedEvent]
|
||||
}
|
||||
else
|
||||
{ // update the values
|
||||
|
||||
def d = mediaRenderers."${parsedEvent.ssdpUSN.toString()}"
|
||||
boolean deviceChangedValues = false
|
||||
if(d.ip != parsedEvent.ip || d.port != parsedEvent.port) {
|
||||
d.ip = parsedEvent.ip
|
||||
d.port = parsedEvent.port
|
||||
deviceChangedValues = true
|
||||
}
|
||||
if (deviceChangedValues) {
|
||||
def children = getChildDevices()
|
||||
children.each {
|
||||
if (parsedEvent.ssdpUSN.toString().contains(it.getDataValue("udn"))) {
|
||||
it.setDeviceNetworkId((parsedEvent.ip + ":" + parsedEvent.port)) //could error if device with same dni already exists
|
||||
it.updateDataValue("dni", (parsedEvent.ip + ":" + parsedEvent.port))
|
||||
it.refresh()
|
||||
log.trace "Updated Device IP"
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (parsedEvent.headers && parsedEvent.body)
|
||||
{ // MEDIARENDER RESPONSES
|
||||
def headerString = new String(parsedEvent?.headers?.decodeBase64())
|
||||
def bodyString = new String(parsedEvent.body.decodeBase64())
|
||||
|
||||
def type = (headerString =~ /Content-Type:.*/) ? (headerString =~ /Content-Type:.*/)[0] : null
|
||||
def body
|
||||
def device
|
||||
if (bodyString?.contains("xml"))
|
||||
{ // description.xml response (application/xml)
|
||||
body = new XmlSlurper().parseText(bodyString)
|
||||
log.trace "MEDIARENDER RESPONSES ${body?.device?.modelName?.text()}"
|
||||
// Avoid add sonos devices
|
||||
device = body?.device
|
||||
body?.device?.deviceList?.device?.each{
|
||||
if (it?.deviceType?.text().contains("urn:schemas-upnp-org:device:MediaRenderer:1")) {
|
||||
device = it
|
||||
}
|
||||
}
|
||||
if ( device?.deviceType?.text().contains("urn:schemas-upnp-org:device:MediaRenderer:1"))
|
||||
{
|
||||
def avtcurl = ""
|
||||
def avteurl = ""
|
||||
def rccurl = ""
|
||||
def rceurl = ""
|
||||
|
||||
|
||||
device?.serviceList?.service?.each{
|
||||
if (it?.serviceType?.text().contains("AVTransport")) {
|
||||
avtcurl = it?.controlURL?.text().startsWith("/")? it?.controlURL.text() : "/" + it?.controlURL.text()
|
||||
avteurl = it?.eventSubURL?.text().startsWith("/")? it?.eventSubURL.text() : "/" + it?.eventSubURL.text()
|
||||
}
|
||||
else if (it?.serviceType?.text().contains("RenderingControl")) {
|
||||
rccurl = it?.controlURL?.text().startsWith("/")? it?.controlURL?.text() : "/" + it?.controlURL?.text()
|
||||
rceurl = it?.eventSubURL?.text().startsWith("/")? it?.eventSubURL?.text() : "/" + it?.eventSubURL?.text()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def mediaRenderers = getMediaRendererPlayer()
|
||||
def player = mediaRenderers.find {it?.key?.contains(device?.UDN?.text())}
|
||||
if (player)
|
||||
{
|
||||
player.value << [name:device?.friendlyName?.text(),model:device?.modelName?.text(), serialNumber:device?.UDN?.text(), verified: true,avtcurl:avtcurl,avteurl:avteurl,rccurl:rccurl,rceurl:rceurl,udn:device?.UDN?.text()]
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else if(type?.contains("json"))
|
||||
{ //(application/json)
|
||||
body = new groovy.json.JsonSlurper().parseText(bodyString)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private def parseEventMessage(Map event) {
|
||||
//handles mediaRenderer attribute events
|
||||
return event
|
||||
}
|
||||
|
||||
private def parseEventMessage(String description) {
|
||||
def event = [:]
|
||||
def parts = description.split(',')
|
||||
parts.each { part ->
|
||||
part = part.trim()
|
||||
if (part.startsWith('devicetype:')) {
|
||||
def valueString = part.split(":")[1].trim()
|
||||
event.devicetype = valueString
|
||||
}
|
||||
else if (part.startsWith('mac:')) {
|
||||
def valueString = part.split(":")[1].trim()
|
||||
if (valueString) {
|
||||
event.mac = valueString
|
||||
}
|
||||
}
|
||||
else if (part.startsWith('networkAddress:')) {
|
||||
def valueString = part.split(":")[1].trim()
|
||||
if (valueString) {
|
||||
event.ip = valueString
|
||||
}
|
||||
}
|
||||
else if (part.startsWith('deviceAddress:')) {
|
||||
def valueString = part.split(":")[1].trim()
|
||||
if (valueString) {
|
||||
event.port = valueString
|
||||
}
|
||||
}
|
||||
else if (part.startsWith('ssdpPath:')) {
|
||||
def valueString = part.split(":")[1].trim()
|
||||
if (valueString) {
|
||||
event.ssdpPath = valueString
|
||||
}
|
||||
}
|
||||
else if (part.startsWith('ssdpUSN:')) {
|
||||
part -= "ssdpUSN:"
|
||||
def valueString = part.trim()
|
||||
if (valueString) {
|
||||
event.ssdpUSN = valueString
|
||||
}
|
||||
}
|
||||
else if (part.startsWith('ssdpTerm:')) {
|
||||
part -= "ssdpTerm:"
|
||||
def valueString = part.trim()
|
||||
if (valueString) {
|
||||
event.ssdpTerm = valueString
|
||||
}
|
||||
}
|
||||
else if (part.startsWith('headers')) {
|
||||
part -= "headers:"
|
||||
def valueString = part.trim()
|
||||
if (valueString) {
|
||||
event.headers = valueString
|
||||
}
|
||||
}
|
||||
else if (part.startsWith('body')) {
|
||||
part -= "body:"
|
||||
def valueString = part.trim()
|
||||
if (valueString) {
|
||||
event.body = valueString
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (event.devicetype == "04" && event.ssdpPath =~ /[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}/ && !event.ssdpUSN && !event.ssdpTerm){
|
||||
def matcher = event.ssdpPath =~ /[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}/
|
||||
def ssdpUSN = matcher[0]
|
||||
event.ssdpUSN = "uuid:$ssdpUSN::urn:schemas-upnp-org:device:MediaRenderer:1"
|
||||
event.ssdpTerm = "urn:schemas-upnp-org:device:MediaRenderer:1"
|
||||
}
|
||||
event
|
||||
}
|
||||
|
||||
|
||||
/////////CHILD DEVICE METHODS
|
||||
def parse(childDevice, description) {
|
||||
def parsedEvent = parseEventMessage(description)
|
||||
|
||||
if (parsedEvent.headers && parsedEvent.body) {
|
||||
def headerString = new String(parsedEvent.headers.decodeBase64())
|
||||
def bodyString = new String(parsedEvent.body.decodeBase64())
|
||||
|
||||
def body = new groovy.json.JsonSlurper().parseText(bodyString)
|
||||
} else {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
private Integer convertHexToInt(hex) {
|
||||
Integer.parseInt(hex,16)
|
||||
}
|
||||
|
||||
private String convertHexToIP(hex) {
|
||||
[convertHexToInt(hex[0..1]),convertHexToInt(hex[2..3]),convertHexToInt(hex[4..5]),convertHexToInt(hex[6..7])].join(".")
|
||||
}
|
||||
|
||||
private getHostAddress(d) {
|
||||
def parts = d.split(":")
|
||||
def ip = convertHexToIP(parts[0])
|
||||
def port = convertHexToInt(parts[1])
|
||||
return ip + ":" + port
|
||||
}
|
||||
|
||||
private Boolean canInstallLabs()
|
||||
{
|
||||
return hasAllHubsOver("000.011.00603")
|
||||
}
|
||||
|
||||
private Boolean hasAllHubsOver(String desiredFirmware)
|
||||
{
|
||||
return realHubFirmwareVersions.every { fw -> fw >= desiredFirmware }
|
||||
}
|
||||
|
||||
private List getRealHubFirmwareVersions()
|
||||
{
|
||||
return location.hubs*.firmwareVersionString.findAll { it }
|
||||
}
|
||||
Reference in New Issue
Block a user