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

Added Request Handler for GetBinaryState to keep wemo device Alive #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
19 changes: 19 additions & 0 deletions fauxmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ def __init__(self, name, listener, poller, ip_address, port, action_handler = No
self.action_handler = action_handler
else:
self.action_handler = self
self.device_state = 0
dbg("FauxMo device '%s' ready on %s:%s" % (self.name, self.ip_address, self.port))

def get_name(self):
Expand All @@ -237,10 +238,12 @@ def handle_request(self, data, sender, socket):
if data.find('<BinaryState>1</BinaryState>') != -1:
# on
dbg("Responding to ON for %s" % self.name)
self.device_state = 1
success = self.action_handler.on()
elif data.find('<BinaryState>0</BinaryState>') != -1:
# off
dbg("Responding to OFF for %s" % self.name)
self.device_state = 0
success = self.action_handler.off()
else:
dbg("Unknown Binary State request:")
Expand All @@ -261,6 +264,22 @@ def handle_request(self, data, sender, socket):
"\r\n"
"%s" % (len(soap), date_str, soap))
socket.send(message)
elif data.find('SOAPACTION: "urn:Belkin:service:basicevent:1#GetBinaryState"') != -1:
dbg("Responding to GetBinaryState for %s" % self.name)

soap = """<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetBinaryStateResponse xmlns:u="urn:Belkin:service:basicevent:1"><BinaryState>%d</BinaryState></u:GetBinaryStateResponse></s:Body> </s:Envelope>""" % self.device_state
date_str = email.utils.formatdate(timeval=None, localtime=False, usegmt=True)
message = ("HTTP/1.1 200 OK\r\n"
"CONTENT-LENGTH: %d\r\n"
"CONTENT-TYPE: text/xml charset=\"utf-8\"\r\n"
"DATE: %s\r\n"
"EXT:\r\n"
"SERVER: Unspecified, UPnP/1.0, Unspecified\r\n"
"X-User-Agent: redsonic\r\n"
"CONNECTION: close\r\n"
"\r\n"
"%s" % (len(soap), date_str, soap))
socket.send(message)
else:
dbg(data)

Expand Down