Skip to content

Commit

Permalink
Working single/double/triple clicks
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyingDiver committed Apr 2, 2018
1 parent c77d269 commit 5b579b7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 44 deletions.
17 changes: 0 additions & 17 deletions Lutron RadioRA 2.indigoPlugin/Contents/Server Plugin/Devices.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
<?xml version="1.0"?>
<Devices>
<!--
<Device type="custom" id="ra2MainRepeater">
<Name>RadioRA 2 Main Repeater</Name>
<ConfigUI>
<Field id="device" type="textField" defaultValue="1">
<Label>Integration ID:</Label>
</Field>
</ConfigUI>
<States>
<State id="serialNumber">
<ValueType>String</ValueType>
<TriggerLabel>Serial Number</TriggerLabel>
<ControlPageLabel>Serial Number</ControlPageLabel>
</State>
</States>
</Device>
-->
<Device type="custom" id="ra2TimeClockEvent">
<Name>RadioRA 2 Time Clock Event</Name>
<ConfigUI>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
<Field type="menu" id="clicks" defaultValue="single">
<Label>Presses:</Label>
<List>
<Option value="single">Single</Option>
<Option value="double">Double</Option>
<Option value="1">Single</Option>
<Option value="2">Double</Option>
<Option value="3">Triple</Option>
</List>
</Field>
<Field id="room" type="menu">
Expand Down
69 changes: 44 additions & 25 deletions Lutron RadioRA 2.indigoPlugin/Contents/Server Plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
PROP_BUTTONTYPE = "ButtonType"
PROP_OUTPUTTYPE = "OutputType"

DOUBLE_CLICK_DELAY = 1.0
CLICK_DELAY = 1.0

########################################
class Plugin(indigo.PluginBase):
Expand Down Expand Up @@ -148,6 +148,7 @@ def __init__(self, pluginId, pluginDisplayName, pluginVersion, pluginPrefs):
self.roomButtonTree = {}
self.lastKeyTime = time.time()
self.lastKeyAddress = ""
self.key_taps = 0

self.threadLock = threading.Lock() # for background data fetch

Expand Down Expand Up @@ -230,17 +231,26 @@ def deviceUpdated(self, oldDevice, newDevice):
def triggerStartProcessing(self, trigger):

if trigger.pluginTypeId == "keypadButtonPress":
try:
clicks = trigger.pluginProps["clicks"]
except:
clicks = trigger.pluginProps["clicks"] = "1"

try:
deviceID = trigger.pluginProps["deviceID"]
componentID = trigger.pluginProps["componentID"]
except:
try:
buttonID = trigger.pluginProps.get("buttonID", None)
buttonID = trigger.pluginProps["buttonID"]
buttonAddress = indigo.devices[int(buttonID)].address
parts = buttonAddress.split(".")
deviceID = trigger.pluginProps["deviceID"] = parts[0]
componentID = trigger.pluginProps["componentID"] = parts[1]
except:
self.logger.error("keypadButtonPress Trigger %s (%s) missing deviceID/componentID/buttonID: %s" % (trigger.name, trigger.id, str(trigger.pluginProps)))
return

self.logger.debug("Adding Button Trigger %s (%d)" % (trigger.name, trigger.id))
self.logger.debug("Adding Button Trigger '{}', deviceID = {}, componentID = {}, clicks = {}".format(trigger.name, deviceID, componentID, clicks))
self.buttonTriggers[trigger.id] = trigger


Expand All @@ -251,7 +261,7 @@ def triggerStartProcessing(self, trigger):
self.logger.error(u"Timeclock Event Trigger %s (%s) does not contain event: %s" % (trigger.name, trigger.id, str(trigger.pluginProps)))
return

self.logger.debug("Adding Event Trigger %s (%d)" % (trigger.name, trigger.id))
self.logger.debug("Adding Event Trigger {}, event = {}".format(trigger.name, event))
self.eventTriggers[trigger.id] = trigger

elif trigger.pluginTypeId == "groupEvent":
Expand All @@ -261,11 +271,11 @@ def triggerStartProcessing(self, trigger):
self.logger.error(u"Group Trigger %s (%s) does not contain group: %s" % (trigger.name, trigger.id, str(trigger.pluginProps)))
return

self.logger.debug("Adding Group Trigger %s (%d)" % (trigger.name, trigger.id))
self.logger.debug("Adding Group Trigger {}, group = {}".format(trigger.name, group))
self.groupTriggers[trigger.id] = trigger

else:
self.logger.error(u"triggerStartProcessing: Trigger %s (%s) is unknown type: %s" % (trigger.name, trigger.id, trigger.pluginTypeId))
self.logger.error(u"triggerStartProcessing: Trigger '{}' is unknown type: {}" % (trigger.name, trigger.pluginTypeId))


def triggerStopProcessing(self, trigger):
Expand Down Expand Up @@ -305,61 +315,70 @@ def groupTriggerCheck(self, groupID, status):
group = trigger.pluginProps["group"]
occupancy = trigger.pluginProps["occupancyPopUp"]
if (group != groupID) or (occupancy != status):
self.logger.threaddebug(u"groupTriggerCheck: Skipping Trigger %s (%s), wrong group or stats: %s, %s" % (trigger.name, trigger.id, group, occupancy))
self.logger.threaddebug(u"groupTriggerCheck: Skipping Trigger %s (%s), wrong group or status: %s, %s" % (trigger.name, trigger.id, group, occupancy))
continue

self.logger.info(u"groupTriggerCheck: Executing Trigger %s (%s), group %s, status %s" % (trigger.name, trigger.id, groupID, status))
indigo.trigger.execute(trigger)

def buttonTriggerCheck(self, devID, compID):

self.logger.debug(u"buttonTriggerCheck: devID: %s, compID: %s" % (devID, compID))
triggerAddress = "{}.{}".format(devID, compID)
self.logger.debug(u"buttonTriggerCheck: devID: {}, compID: {}, address: {}".format(devID, compID, triggerAddress))

# check for linked devices

triggerAddress = "{}.{}".format(devID, compID)
for linkID, linkItem in self.linkedDeviceList.iteritems():
controlledDevice = indigo.devices[int(linkItem["controlledDevice"])]
buttonAddress = linkItem["buttonAddress"]
if buttonAddress == triggerAddress:
self.logger.debug(u"Linked Device Match, buttonAddress: {}, controlledDevice: {}".format(buttonAddress, controlledDevice.id))
indigo.device.toggle(controlledDevice.id)


# and check for multiple taps

if (triggerAddress == self.lastKeyAddress) and (time.time() < (self.lastKeyTime + CLICK_DELAY)):
self.key_taps += 1
else:
self.key_taps = 1

self.lastKeyAddress = triggerAddress
self.lastKeyTime = time.time()

# Look for triggers that match this button

for triggerId, trigger in self.buttonTriggers.iteritems():

try:
clicks = trigger.pluginProps["clicks"]
except:
clicks = "1"

try:
deviceID = trigger.pluginProps["deviceID"]
componentID = trigger.pluginProps["componentID"]
self.logger.threaddebug(u"buttonTriggerCheck: Using deviceID = {}, componentID = {}".format(deviceID, componentID))
except:
try:
buttonID = trigger.pluginProps["buttonID"]
buttonAddress = indigo.devices[int(buttonID)].address
parts = buttonAddress.split(".")
deviceID = parts[0]
componentID = parts[1]
self.logger.threaddebug(u"buttonTriggerCheck: deviceID = {}, componentID = {}".format(deviceID, componentID))
except:
self.logger.threaddebug(u"buttonTriggerCheck: Error matching keypress trigger.pluginProps = {}".format(trigger.pluginProps))
continue
self.logger.error(u"keypadButtonPress Trigger '{}' missing deviceID/componentID/buttonID: {}".format(trigger.name, trigger.pluginProps))
return

if (deviceID != devID) or (componentID != compID):
self.logger.threaddebug(u"buttonTriggerCheck: Skipping Trigger %s (%s), wrong keypad button: %s, %s" % (trigger.name, trigger.id, deviceID, componentID))
self.logger.threaddebug(u"buttonTriggerCheck: Skipping Trigger '{}', wrong keypad button: {}, {}".format(trigger.name, deviceID, componentID))
continue

if self.key_taps != int(clicks):
self.logger.threaddebug(u"buttonTriggerCheck: Skipping Trigger {}, wrong click count: {}".format(trigger.name, clicks))
continue

self.logger.debug(u"buttonTriggerCheck: Executing Trigger %s (%s), keypad button: %s.%s" % (trigger.name, trigger.id, deviceID, componentID))
self.logger.debug(u"buttonTriggerCheck: Executing Trigger '{}', keypad button: {}.{}".format(trigger.name, deviceID, componentID))
indigo.trigger.execute(trigger)


# and check for double tap

if (triggerAddress == self.lastKeyAddress) and (time.time() < (self.lastKeyTime + DOUBLE_CLICK_DELAY)):
self.logger.info(u"Double tap on button: {}".format(triggerAddress))

self.lastKeyAddress = triggerAddress
self.lastKeyTime = time.time()

####################

Expand Down Expand Up @@ -1504,7 +1523,7 @@ def addLinkedDevice(self, valuesDict, typeId=None, devId=None):
buttonLEDDeviceId = "0"
linkID = "{}-{}".format(buttonDeviceId, controlledDeviceId)
linkItem = {"name" : linkName, "buttonDevice" : buttonDeviceId, "buttonLEDDevice" : buttonLEDDeviceId, "controlledDevice" : controlledDeviceId, "buttonAddress" : buttonAddress}
self.logger.info(u"Adding linkItem {}: {}".format(linkID, linkItem))
self.logger.debug(u"Adding linkItem {}: {}".format(linkID, linkItem))
self.linkedDeviceList[linkID] = linkItem
self.logLinkedDevices()

Expand Down

0 comments on commit 5b579b7

Please sign in to comment.