Skip to content

Commit

Permalink
Bug Fix
Browse files Browse the repository at this point in the history
Bug fix
  • Loading branch information
Jon authored and Jon committed Nov 20, 2017
1 parent 04b59a3 commit 9654dfb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 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.17</string>
<string>3.0.18</string>
<key>ServerApiVersion</key>
<string>2.0</string>
<key>IwsApiVersion</key>
Expand Down
34 changes: 19 additions & 15 deletions Alexa-Hue Bridge.indigoPlugin/Contents/Server Plugin/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import indigo
except ImportError, e:
pass

import errno
import socket
import sys
import time
Expand Down Expand Up @@ -71,7 +73,7 @@ def __init__(self, plugin, ahbDevId):
# self.uuid = PLUGIN.globals['alexaHueBridge'][self.ahbDevId]['uuid']
# self._timeout = PLUGIN.globals['alexaHueBridge'][self.ahbDevId]['discoveryExpiration']

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

self.interrupted = False

Expand All @@ -82,7 +84,7 @@ def __init__(self, plugin, ahbDevId):
"uuid": PLUGIN.globals['alexaHueBridge'][self.ahbDevId]['uuid']}
self.broadcast_packet = broadcast_packet % broadcast_data
except StandardError, e:
PLUGIN.broadcasterLogger.error(u"StandardError detected in Broadcaster.Init for '%s'. Line '%s' has error='%s'" % (indigo.devices[ahbDevId].name, sys.exc_traceback.tb_lineno, e))
PLUGIN.broadcasterLogger.error(u"StandardError detected in Broadcaster.Init for '{}'. Line '{}' has error='{}'".format(indigo.devices[ahbDevId].name, sys.exc_traceback.tb_lineno, e))

def run(self):
try:
Expand All @@ -91,7 +93,7 @@ def run(self):
sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 20)
start_time = time.time()
end_time = start_time + (PLUGIN.globals['alexaHueBridge'][self.ahbDevId]['discoveryExpiration'] * 60)
PLUGIN.broadcasterLogger.debug("Broadcaster.run: sending first broadcast:\n%s" % self.broadcast_packet)
PLUGIN.broadcasterLogger.debug("Broadcaster.run: sending first broadcast:\n{}".format(self.broadcast_packet))
while True:
sock.sendto(self.broadcast_packet, (BCAST_IP, UPNP_PORT))
for x in range(BROADCAST_INTERVAL):
Expand All @@ -105,11 +107,9 @@ def run(self):
PLUGIN.setDeviceDiscoveryState(False, self.ahbDevId)
sock.close()
return
PLUGIN.setDeviceDiscoveryState(False, self.ahbDevId)
PLUGIN.broadcasterLogger.debug("Broadcaster.run for '%s' is ending" % PLUGIN.globals['alexaHueBridge'][self.ahbDevId]['hubName'])

except StandardError, e:
PLUGIN.broadcasterLogger.error(u"StandardError detected in Broadcaster.Run for '%s'. Line '%s' has error='%s'" % (indigo.devices[self.ahbDevId].name, sys.exc_traceback.tb_lineno, e))
PLUGIN.broadcasterLogger.error(u"StandardError detected in Broadcaster.Run for '{}'. Line '{}' has error='{}'".format(indigo.devices[self.ahbDevId].name, sys.exc_traceback.tb_lineno, e))

def stop(self):
PLUGIN.setDeviceDiscoveryState(False, self.ahbDevId)
Expand Down Expand Up @@ -154,7 +154,7 @@ def __init__(self, plugin, ahbDevId):
# self.uuid = PLUGIN.globals['alexaHueBridge'][self.ahbDevId]['uuid']
# self._timeout = PLUGIN.globals['alexaHueBridge'][self.ahbDevId]['discoveryExpiration']

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

self.interrupted = False

Expand All @@ -163,7 +163,7 @@ def __init__(self, plugin, ahbDevId):
"uuid": PLUGIN.globals['alexaHueBridge'][self.ahbDevId]['uuid']}
self.response_packet = response_packet % response_data
except StandardError, e:
PLUGIN.responderLogger.error(u"StandardError detected in Responder.Init for '%s'. Line '%s' has error='%s'" % (indigo.devices[ahbDevId].name, sys.exc_traceback.tb_lineno, e))
PLUGIN.responderLogger.error(u"StandardError detected in Responder.Init for '{}'. Line '{}' has error='{}'".format(indigo.devices[ahbDevId].name, sys.exc_traceback.tb_lineno, e))

def run(self):
try:
Expand Down Expand Up @@ -197,27 +197,31 @@ def run(self):
if M_SEARCH_REQ_MATCH in data:
PLUGIN.responderLogger.debug("Responder.run: received: %s" % str(data))
self.respond(addr)
except socket.error, (value, message):
except socket.error as e:
# This is the exception thrown when someone else has bound to the UPNP port, so write some errors and
# stop the thread (which really isn't needed, but it logs a nice stop debug message).
if value == 48:
PLUGIN.responderLogger.error(u"Responder startup failed because another app or plugin is using the UPNP port.")
PLUGIN.responderLogger.error(u"Open a terminal window and type 'sudo lsof -i :%i' to see a list of processes that have bound to that port and quit those applications." % UPNP_PORT)
if e.errno == errno.EADDRINUSE:
PLUGIN.responderLogger.error(u"'{}' Responder startup failed because another app or plugin is using the UPNP port.".format(indigo.devices[self.ahbDevId].name))
PLUGIN.responderLogger.error(u"Open a terminal window and type 'sudo lsof -i :{}}' to see a list of processes that have bound to that port and quit those applications.".format(UPNP_PORT))
self.stop()
elif e.errno == errno.EADDRNOTAVAIL:
PLUGIN.responderLogger.error(u"'{}' Responder startup failed because host address is not available.".format(indigo.devices[self.ahbDevId].name))
PLUGIN.responderLogger.error(u"Double check that the host is specified correctly in the Plugin Config. Correct if invalid and then reload the plugin.")
self.stop()
else:
PLUGIN.responderLogger.error("Responder.run: socket error: %s - %s" % (str(value), message))
PLUGIN.responderLogger.error("'{}' Responder.run: socket error: {}".format(indigo.devices[self.ahbDevId].name, e))

PLUGIN.setDeviceDiscoveryState(False, self.ahbDevId)
except StandardError, e:
PLUGIN.responderLogger.error(u"StandardError detected in Responder.Run for '%s'. Line '%s' has error='%s'" % (indigo.devices[self.ahbDevId].name, sys.exc_traceback.tb_lineno, e))
PLUGIN.responderLogger.error(u"StandardError detected in Responder.Run for '{}'. Line '{}' has error='{}'".format(indigo.devices[self.ahbDevId].name, sys.exc_traceback.tb_lineno, e))

def stop(self):
PLUGIN.setDeviceDiscoveryState(False, self.ahbDevId)
PLUGIN.responderLogger.debug("Responder thread stopped")
self.interrupted = True

def respond(self, addr):
PLUGIN.responderLogger.debug("Responder.respond called from address %s\n%s" % (str(addr), self.response_packet))
PLUGIN.responderLogger.debug("Responder.respond called from address {}\n{}".format(str(addr), self.response_packet))
PLUGIN.responderLogger.debug("Responder.respond: creating output_socket")
output_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
PLUGIN.responderLogger.debug("Responder.respond: calling output_socket.sendto")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def deviceStartComm(self, ahbDev):
if int(ahbDev.address) != int(port):
port_changed = True
except:
self.generalLogger.error("Alexa-Hue Bridge '{}' at address {} either has an invalid address or invalif port {} - specify in Device Config".format(ahbDev.address, port))
self.generalLogger.error("Alexa-Hue Bridge '{}' at address {} either has an invalid address or invalid port {} - specify in Device Config".format(ahbDev.name, ahbDev.address, port))
return

self.globals['alexaHueBridge'][ahbDev.id]['port'] = port
Expand Down Expand Up @@ -515,15 +515,11 @@ def deviceStartComm(self, ahbDev):

self.setDeviceDiscoveryState(True, ahbDev.id)




self.generalLogger.info(u"Alexa-Hue Bridge '{}' started: Host: {} Port: {}".format(self.globals['alexaHueBridge'][ahbDev.id]['hubName'], self.globals['alexaHueBridge'][ahbDev.id]['host'], self.globals['alexaHueBridge'][ahbDev.id]['port']))

except StandardError, e:
self.generalLogger.error(u"StandardError detected in deviceStartComm for '%s'. Line '%s' has error='%s'" % (indigo.devices[ahbDev.id].name, sys.exc_traceback.tb_lineno, e))


def deviceStopComm(self, ahbDev):
self.methodTracer.threaddebug(u"CLASS: Plugin")

Expand All @@ -543,7 +539,6 @@ def deviceStopComm(self, ahbDev):
except StandardError, e:
self.generalLogger.error(u"StandardError detected in deviceStopComm for '%s'. Line '%s' has error='%s'" % (stoppedName, sys.exc_traceback.tb_lineno, e))


def didDeviceCommPropertyChange(self, origDev, newDev):
self.methodTracer.threaddebug(u"CLASS: Plugin")
self.generalLogger.debug(u'DID-DEVICE-COMM-PROPERTY-CHANGE: Old [%s] vs New [%s]' % (origDev.name, newDev.name))
Expand All @@ -561,7 +556,6 @@ def didDeviceCommPropertyChange(self, origDev, newDev):
return True
return False


def getDeviceConfigUiValues(self, pluginProps, typeId, ahbDevId):
self.methodTracer.threaddebug(u"CLASS: Plugin")

Expand Down Expand Up @@ -609,7 +603,6 @@ def getDeviceConfigUiValues(self, pluginProps, typeId, ahbDevId):
pluginProps["sourceDimActionMenu"] = "0" # NO ACTION
pluginProps["sourceDimActionVariableMenu"] = "0" # NO VARIABLE


return super(Plugin, self).getDeviceConfigUiValues(pluginProps, typeId, ahbDevId)

########################################
Expand Down

0 comments on commit 9654dfb

Please sign in to comment.