Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
class device_handler(debounce_handler):
"""Publishes the on/off state requested,
and the IP address of the Echo making the request.
"""
TRIGGERS = {"device": 52000}
def act(self, client_address, state, name):
print "State", state, "on ", name, "from client @", client_address
return True
if __name__ == "__main__":
# Startup the fauxmo server
fauxmo.DEBUG = True
p = fauxmo.poller()
u = fauxmo.upnp_broadcast_responder()
u.init_socket()
p.add(u)
# Register the device callback as a fauxmo handler
d = device_handler()
for trig, port in d.TRIGGERS.items():
fauxmo.fauxmo(trig, u, p, None, port, d)
# Loop and poll for incoming Echo requests
logging.debug("Entering fauxmo polling loop")
while True:
try:
# Allow time for a ctrl-c to stop the process
p.poll(100)
time.sleep(0.1)
except Exception, e:
def __init__(self, group=None, target=None, name=None, args=(), kwargs=None):
threading.Thread.__init__(self, group=group, target=target, name="Alexa")
self.shutdown_flag = threading.Event()
self.args = args
self.kwargs = kwargs
if kwargs["log"] != None:
self.log = kwargs["log"]
if kwargs["shutter"] != None:
self.shutter = kwargs["shutter"]
if kwargs["config"] != None:
self.config = kwargs["config"]
# Startup the fauxmo server
self.poller = fauxmo.poller(log = self.log)
self.upnp_responder = fauxmo.upnp_broadcast_responder(log = self.log)
self.upnp_responder.init_socket()
self.poller.add(self.upnp_responder)
# Register the device callback as a fauxmo handler
dbh = device_handler(log=self.log, shutter=self.shutter, config=self.config)
for shutter, shutterId in sorted(self.config.ShuttersByName.items(), key=lambda kv: kv[1]):
portId = 50000 + (abs(int(shutterId,16)) % 10000)
self.LogInfo ("Remote address in dec: " + str(int(shutterId,16)) + ", WeMo port will be n°" + str(portId))
fauxmo.fauxmo(shutter, self.upnp_responder, self.poller, None, portId, dbh, log=self.log)
return
GPIO.setmode(GPIO.BOARD) ## Use board pin numbering
GPIO.setup(int(10), GPIO.OUT) ## Setup GPIO Pin to OUTPUT
GPIO.output(int(10), state) ## State is true/false
else:
print("Device not found!")
return True
if __name__ == "__main__":
# Startup the fauxmo server
fauxmo.DEBUG = True
p = fauxmo.poller()
u = fauxmo.upnp_broadcast_responder()
u.init_socket()
p.add(u)
# Register the device callback as a fauxmo handler
d = device_handler()
for trig, port in d.TRIGGERS.items():
fauxmo.fauxmo(trig, u, p, None, port, d)
# Loop and poll for incoming Echo requests
logging.debug("Entering fauxmo polling loop")
while True:
try:
# Allow time for a ctrl-c to stop the process
p.poll(100)
time.sleep(0.1)
except Exception as e:
#TRIGGERS = {str(sys.argv[1]): int(sys.argv[2])}
TRIGGERS = {"office": 52000}
def act(self, client_address, state, name):
print("State", state, "from client @", client_address)
GPIO.setmode(GPIO.BOARD) ## Use board pin numbering
GPIO.setup(str(sys.argv[3]), GPIO.OUT) ## Setup GPIO Pin to OUTPUT
GPIO.output(str(sys.argv[3]), not state) ## State is true/false
GPIO.cleanup(str(sys.argv[3]))
return True
if __name__ == "__main__":
# Startup the fauxmo server
fauxmo.DEBUG = True
p = fauxmo.poller()
u = fauxmo.upnp_broadcast_responder()
u.init_socket()
p.add(u)
# Register the device callback as a fauxmo handler
d = device_handler()
for trig, port in d.TRIGGERS.items():
fauxmo.fauxmo(trig, u, p, None, port, d)
# Loop and poll for incoming Echo requests
logging.debug("Entering fauxmo polling loop")
while True:
try:
# Allow time for a ctrl-c to stop the process
p.poll(100)
time.sleep(0.1)
except Exception as e:
return r.status_code == 200
if __name__ == "__main__":
FAUXMOS = [
['office lights', dummy_handler("officelight")],
['kitchen lights', dummy_handler("kitchenlight")],
]
if len(sys.argv) > 1 and sys.argv[1] == '-d':
DEBUG = True
# Set up our singleton for polling the sockets for data ready
p = poller()
# Set up our singleton listener for UPnP broadcasts
u = upnp_broadcast_responder()
u.init_socket()
# Add the UPnP broadcast listener to the poller so we can respond
# when a broadcast is received.
p.add(u)
# Create our FauxMo virtual switch devices
for one_faux in FAUXMOS:
switch = fauxmo(one_faux[0], u, p, None, 0, action_handler = one_faux[1])
dbg("Entering main loop\n")
while True:
try:
# Allow time for a ctrl-c to stop the process
p.poll(100)
and the IP address of the Echo making the request.
"""
TRIGGERS = {str(sys.argv[1]): int(sys.argv[2])}
def act(self, client_address, state, name):
print "State", state, "from client @", client_address
GPIO.setmode(GPIO.BOARD) ## Use board pin numbering
GPIO.setup(int(sys.argv[3]), GPIO.OUT) ## Setup GPIO Pin to OUTPUT
GPIO.output(int(sys.argv[3]), not state) ## State is true/false
return True
if __name__ == "__main__":
# Startup the fauxmo server
fauxmo.DEBUG = True
p = fauxmo.poller()
u = fauxmo.upnp_broadcast_responder()
u.init_socket()
p.add(u)
# Register the device callback as a fauxmo handler
d = device_handler()
for trig, port in d.TRIGGERS.items():
fauxmo.fauxmo(trig, u, p, None, port, d)
# Loop and poll for incoming Echo requests
logging.debug("Entering fauxmo polling loop")
while True:
try:
# Allow time for a ctrl-c to stop the process
p.poll(100)
time.sleep(0.1)
except Exception, e:
class device_handler(debounce_handler):
"""Publishes the on/off state requested,
and the IP address of the Echo making the request.
"""
TRIGGERS = {"office": 52000}
def act(self, client_address, state, name):
print("State", state, "on ", name, "from client @", client_address)
return True
if __name__ == "__main__":
# Startup the fauxmo server
fauxmo.DEBUG = True
p = fauxmo.poller()
u = fauxmo.upnp_broadcast_responder()
u.init_socket()
p.add(u)
# Register the device callback as a fauxmo handler
d = device_handler()
for trig, port in d.TRIGGERS.items():
fauxmo.fauxmo(trig, u, p, None, port, d)
# Loop and poll for incoming Echo requests
logging.debug("Entering fauxmo polling loop")
while True:
try:
# Allow time for a ctrl-c to stop the process
p.poll(100)
time.sleep(0.1)
except Exception as e:
return r.status_code == 200
if __name__ == "__main__":
FAUXMOS = [
['office lights', dummy_handler("officelight")],
['kitchen lights', dummy_handler("kitchenlight")],
]
if len(sys.argv) > 1 and sys.argv[1] == '-d':
DEBUG = True
# Set up our singleton for polling the sockets for data ready
p = poller()
# Set up our singleton listener for UPnP broadcasts
u = upnp_broadcast_responder()
u.init_socket()
# Add the UPnP broadcast listener to the poller so we can respond
# when a broadcast is received.
p.add(u)
# Create our FauxMo virtual switch devices
for one_faux in FAUXMOS:
switch = fauxmo(one_faux[0], u, p, None, 0, action_handler = one_faux[1])
dbg("Entering main loop\n")
while True:
try:
# Allow time for a ctrl-c to stop the process
p.poll(100)