Skip to content

Commit

Permalink
Minor Bug Fix + Code Tidy-up
Browse files Browse the repository at this point in the history
Minor Bug Fix + Code Tidy-up
  • Loading branch information
Jon authored and Jon committed Dec 3, 2017
1 parent 4780af5 commit 781574d
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 266 deletions.
2 changes: 1 addition & 1 deletion Alexa-Hue Bridge.indigoPlugin/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>PluginVersion</key>
<string>3.0.19</string>
<string>3.0.20</string>
<key>ServerApiVersion</key>
<string>2.0</string>
<key>IwsApiVersion</key>
Expand Down
65 changes: 4 additions & 61 deletions Alexa-Hue Bridge.indigoPlugin/Contents/Server Plugin/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ def __init__(self, plugin, ahbDevId):

try:
self.ahbDevId = ahbDevId
# self._host = PLUGIN.globals['alexaHueBridge'][self.ahbDevId]['host']
# self._port = PLUGIN.globals['alexaHueBridge'][self.ahbDevId]['port']
# self.uuid = PLUGIN.globals['alexaHueBridge'][self.ahbDevId]['uuid']
# self._timeout = PLUGIN.globals['alexaHueBridge'][self.ahbDevId]['discoveryExpiration']

PLUGIN.broadcasterLogger.debug("Broadcaster.__init__ for '{}' is running".format(PLUGIN.globals['alexaHueBridge'][self.ahbDevId]['hubName']))

Expand Down Expand Up @@ -116,29 +112,6 @@ def stop(self):
PLUGIN.broadcasterLogger.debug("Broadcaster thread stopped")
self.interrupted = True

# @property
# def host(self):
# return self._host

# @host.setter
# def host(self, host):
# self._host = host

# @property
# def port(self):
# return self._port

# @port.setter
# def port(self, port):
# self._port = port

# @property
# def timeout(self):
# return self._timeout

# @timeout.setter
# def timeout(self, timeout):
# self._timeout = timeout

class Responder(threading.Thread):
def __init__(self, plugin, ahbDevId):
Expand All @@ -149,17 +122,13 @@ def __init__(self, plugin, ahbDevId):

try:
self.ahbDevId = ahbDevId
# self._host = PLUGIN.globals['alexaHueBridge'][self.ahbDevId]['host']
# self._port = PLUGIN.globals['alexaHueBridge'][self.ahbDevId]['port']
# self.uuid = PLUGIN.globals['alexaHueBridge'][self.ahbDevId]['uuid']
# self._timeout = PLUGIN.globals['alexaHueBridge'][self.ahbDevId]['discoveryExpiration']

PLUGIN.responderLogger.debug("Responder.__init__ for '{}' is running".format(PLUGIN.globals['alexaHueBridge'][self.ahbDevId]['hubName']))

self.interrupted = False

response_data = {"server_ip": PLUGIN.globals['alexaHueBridge'][self.ahbDevId]['host'],
"server_port": PLUGIN.globals['alexaHueBridge'][self.ahbDevId]['port'],
response_data = {"server_ip": PLUGIN.globals['alexaHueBridge'][self.ahbDevId]['host'],
"server_port": PLUGIN.globals['alexaHueBridge'][self.ahbDevId]['port'],
"uuid": PLUGIN.globals['alexaHueBridge'][self.ahbDevId]['uuid']}
self.response_packet = response_packet % response_data
except StandardError, e:
Expand Down Expand Up @@ -195,7 +164,7 @@ def run(self):
return
else:
if M_SEARCH_REQ_MATCH in data:
PLUGIN.responderLogger.debug("Responder.run: received: %s" % str(data))
PLUGIN.responderLogger.debug("Responder.run: received: {}".format(str(data)))
self.respond(addr)
except socket.error as e:
# This is the exception thrown when someone else has bound to the UPNP port, so write some errors and
Expand Down Expand Up @@ -228,30 +197,4 @@ def respond(self, addr):
output_socket.sendto(self.response_packet, addr)
PLUGIN.responderLogger.debug("Responder.respond: closing output_socket")
output_socket.close()
PLUGIN.responderLogger.debug("Responder.respond: UDP Response sent to %s" % str(addr))


# @property
# def host(self):
# return self._host

# @host.setter
# def host(self, host):
# self._host = host

# @property
# def port(self):
# return self._port

# @port.setter
# def port(self, port):
# self._port = port

# @property
# def timeout(self):
# return self._timeout

# @timeout.setter
# def timeout(self, timeout):
# self._timeout = timeout

PLUGIN.responderLogger.debug("Responder.respond: UDP Response sent to {}".format(str(addr)))
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
import indigo
except ImportError, e:
pass

import Queue
import sys
import threading
import traceback

PLUGIN = None


class ThreadDiscoveryLogging(threading.Thread):

def __init__(self, plugin):
Expand All @@ -33,21 +35,21 @@ def run(self):
while True:

try:
discoveryId, discoveryName, discoveryList = PLUGIN.globals['queues']['discoveryLogging'].get(True, 5)
discoveryId, client_address, discoveryName, discoveryList = PLUGIN.globals['queues']['discoveryLogging'].get(True, 5)
if len(discoveryList) > 0:
discoveryList.sort()
PLUGIN.serverLogger.info(u"Alexa-Hue Bridge '%s' responding to Alexa discovery [request id: %s] ..." % (discoveryName, discoveryId))
PLUGIN.serverLogger.info(u"Alexa-Hue Bridge '{}' responding to Alexa discovery from {} [request id: {}] ...".format(discoveryName, client_address, discoveryId))
deviceCount = 0
for deviceName in discoveryList:
deviceCount += 1
PLUGIN.serverLogger.info(u"+ Publishing device '%s' to Alexa" % deviceName)
PLUGIN.serverLogger.info(u"+ Publishing device '{}' to Alexa".format(deviceName))
if deviceCount == 0:
deviceString = 'No device' # This probably won't occur ?
elif deviceCount == 1:
deviceString = 'One device'
else:
deviceString = '%s devices' % str(deviceCount)
PLUGIN.serverLogger.info(u"... %s discovered by Alexa on Alexa-Hue Bridge '%s'." % (deviceString, discoveryName))
deviceString = '{} devices'.format(str(deviceCount))
PLUGIN.serverLogger.info(u"... {} discovered by Alexa on Alexa-Hue Bridge '{}'.".format(deviceString, discoveryName))

del PLUGIN.globals['discoveryLists'][discoveryId]

Expand All @@ -57,9 +59,9 @@ def run(self):
PLUGIN.serverLogger.error(u"StandardError detected in Discovery Logging")
errorLines = traceback.format_exc().splitlines()
for errorLine in errorLines:
PLUGIN.serverLogger.error(u"%s" % errorLine)
PLUGIN.serverLogger.error(u"{}".format(errorLine))

except StandardError, e:
PLUGIN.serverLogger.error(u"StandardError detected in Discovery Logging thread. Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e))
PLUGIN.serverLogger.error(u"StandardError detected in Discovery Logging thread. Line '{}' has error='{}'".format(sys.exc_traceback.tb_lineno, e))

PLUGIN.serverLogger.debug(u"Discovery Logging thread ended.")
PLUGIN.serverLogger.debug(u"Discovery Logging thread ended.")
Loading

0 comments on commit 781574d

Please sign in to comment.