Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue with device port updates not being caught #1

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
34c2b0f
Update wemo-dimmer-light-switch.groovy
meatheadmike Aug 7, 2018
c9b8a8d
Update wemo-dimmer-light-switch.groovy
meatheadmike Aug 7, 2018
20c0be6
Update wemo-dimmer-light-switch.groovy
meatheadmike Aug 7, 2018
3b020b4
Update wemo-dimmer-light-switch.groovy
meatheadmike Aug 7, 2018
f67df64
Update wemo-dimmer-light-switch.groovy
meatheadmike Aug 8, 2018
069615a
Update wemo-dimmer-light-switch.groovy
meatheadmike Aug 8, 2018
f565c82
Update wemo-dimmer-light-switch.groovy
meatheadmike Aug 8, 2018
45b478b
Update wemo-dimmer-light-switch.groovy
meatheadmike Aug 8, 2018
d9dd130
Update wemo-dimmer-light-switch.groovy
meatheadmike Aug 8, 2018
61840b8
Update wemo-dimmer-light-switch.groovy
meatheadmike Aug 8, 2018
eaafae8
Update wemo-dimmer-light-switch.groovy
meatheadmike Aug 8, 2018
dcd742c
Update wemo-dimmer-light-switch.groovy
meatheadmike Aug 13, 2018
5a7052e
Update wemo-dimmer-light-switch.groovy
meatheadmike Aug 13, 2018
8e9611b
Update wemo-dimmer-light-switch.groovy
meatheadmike Aug 13, 2018
f9af0dc
Update wemo-dimmer-light-switch.groovy
meatheadmike Aug 13, 2018
bb95e64
Update wemo-dimmer-light-switch.groovy
meatheadmike Aug 13, 2018
3c03489
Update wemo-dimmer-light-switch.groovy
meatheadmike Aug 13, 2018
e3e679a
Update wemo-dimmer-light-switch.groovy
meatheadmike Aug 13, 2018
037cf9c
Update wemo-dimmer-light-switch.groovy
meatheadmike Aug 15, 2018
129852b
Update wemo-dimmer-light-switch.groovy
meatheadmike Aug 15, 2018
f429219
bug fix for device detection
Aug 24, 2018
ed13538
Merge pull request #1 from meatheadmike/test
meatheadmike Aug 24, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def refresh() {
}

def subscribe(hostAddress) {
debug("Executing 'subscribe()'")
debug("Executing subscribe(${hostAddress})")
def address = getCallBackAddress()
new physicalgraph.device.HubAction("""SUBSCRIBE /upnp/event/basicevent1 HTTP/1.1
HOST: ${hostAddress}
Expand All @@ -267,6 +267,7 @@ User-Agent: CyberGarage-HTTP/1.0
}

def subscribe() {
debug("calling getHostAddress()")
subscribe(getHostAddress())
}

Expand All @@ -286,7 +287,7 @@ def subscribe(ip, port) {
}

def resubscribe() {
debug("Executing 'resubscribe()'")
debug("Executing resubscribe()")
def sid = getDeviceDataByName("subscriptionId")

new physicalgraph.device.HubAction("""SUBSCRIBE /upnp/event/basicevent1 HTTP/1.1
Expand All @@ -307,4 +308,4 @@ SID: uuid:${sid}


""", physicalgraph.device.Protocol.LAN)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ def firstPage() {

debug("REFRESH COUNT :: ${refreshCount}")

if(!state.subscribe) {
debug("Subscribe to location")
// subscribe to answers from HUB
subscribe(location, null, locationHandler, [filterEvents:false])
state.subscribe = true
if (!state.subscribe) {
debug("Subscribe to location")
// subscribe to answers from HUB
subscribe(location, "ssdpTerm.urn:Belkin:service:basicevent:1", locationHandler, [filterEvents:false])
state.subscribe = true
}

//ssdp request every 25 seconds
Expand Down Expand Up @@ -127,7 +127,16 @@ def getWemoDimmerLightSwitches() {

def installed() {
debug("Installed with settings: ${settings}")
initialize()
unschedule()
unsubscribe()
if (selecteddimmerLightSwitches) {
adddimmerLightSwitches()
}
// run once subscribeToDevices
subscribeToDevices()

//setup cron jobs
runEvery5Minutes(subscribeToDevices)
}

def uninstalled() {
Expand All @@ -148,7 +157,15 @@ private removeChildDevices(devices) {

def updated() {
debug("Updated with settings: ${settings}")
initialize()
unschedule()
if (selecteddimmerLightSwitches) {
adddimmerLightSwitches()
}
// run once subscribeToDevices
subscribeToDevices()

//setup cron jobs
runEvery5Minutes(subscribeToDevices)
}

def resubscribe() {
Expand All @@ -168,6 +185,8 @@ def refreshDevices() {

def subscribeToDevices() {
debug("subscribeToDevices() called")
// Need to discover each subscribe call or updated ports wont be caught!
discoverAllWemoTypes()
def devices = getAllChildDevices()
devices.each { d ->
debug('Call subscribe on '+d.id)
Expand All @@ -176,15 +195,14 @@ def subscribeToDevices() {
}

def adddimmerLightSwitches() {
debug("adddimmerLightSwitches()")
def dimmerLightSwitches = getWemoDimmerLightSwitches()

selecteddimmerLightSwitches.each { dni ->
def selectedDimmerLightSwitch = dimmerLightSwitches.find { it.value.mac == dni } ?: dimmerLightSwitches.find { "${it.value.ip}:${it.value.port}" == dni }

def selectedDimmerLightSwitch = dimmerLightSwitches.find { it?.value?.mac == dni }
def d
if (selectedDimmerLightSwitch) {
d = getChildDevices()?.find {
it.dni == selectedDimmerLightSwitch.value.mac || it.device.getDataValue("mac") == selectedDimmerLightSwitch.value.mac
it?.dni == selectedDimmerLightSwitch?.value?.mac || it?.device?.getDataValue("mac") == selectedDimmerLightSwitch?.value?.mac
}
}

Expand All @@ -201,28 +219,11 @@ def adddimmerLightSwitches() {
debug("Mac: " + selectedDimmerLightSwitch.value.mac)
debug("Hub: " + (selectedDimmerLightSwitch?.value.hub))
debug("Data: " + data)
d = addChildDevice("kris2k2", "Wemo Dimmer Light Switch", selectedDimmerLightSwitch.value.mac, (selectedDimmerLightSwitch?.value.hub), data)
d = addChildDevice("kris2k2", "Wemo Dimmer Light Switch", selectedDimmerLightSwitch.value.mac, selectedDimmerLightSwitch?.value.hub, data)
}
}
}

def initialize() {
debug("Initialiaze")
// remove location subscription afterwards
unsubscribe()
state.subscribe = false

if (selecteddimmerLightSwitches) {
adddimmerLightSwitches()
}

// run once subscribeToDevices
subscribeToDevices()

//setup cron jobs
schedule("10 * * * * ?", "subscribeToDevices")
}

def locationHandler(evt) {
if(evt.name == "ping") {
return ""
Expand All @@ -246,23 +247,15 @@ def locationHandler(evt) {
} else { // just update the values
debug("Updating devices")
def d = dimmerLightSwitches."${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 (it.getDeviceDataByName("mac") == parsedEvent.mac) {
it.subscribe(parsedEvent.ip, parsedEvent.port)
}
def child = getChildDevice(parsedEvent.mac)
if (child) {
debug("Triggering subscribe on: ${parsedEvent.mac} ${parsedEvent.ip} ${parsedEvent.port}")
child.subscribe(parsedEvent.ip, parsedEvent.port)
}
}

}
} else if (parsedEvent.headers && parsedEvent.body) {
def headerString = new String(parsedEvent.headers.decodeBase64())
Expand Down Expand Up @@ -349,4 +342,4 @@ private Boolean hasAllHubsOver(String desiredFirmware) {

private List getRealHubFirmwareVersions() {
return location.hubs*.firmwareVersionString.findAll { it }
}
}