Skip to content

Commit

Permalink
Added battery level support
Browse files Browse the repository at this point in the history
For Picos, Shades, Sensors
Also fixed old bug in sensor devices
  • Loading branch information
Joe Keenan authored and Joe Keenan committed Oct 23, 2020
1 parent be74639 commit 5d1cf01
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Lutron RadioRA 2.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>7.3.3</string>
<string>7.4.0</string>
<key>ServerApiVersion</key>
<string>2.0</string>
<key>IwsApiVersion</key>
Expand Down
11 changes: 11 additions & 0 deletions Lutron RadioRA 2.indigoPlugin/Contents/Server Plugin/Actions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@
<Name>Stop Shade Raising/Lowering</Name>
<CallbackMethod>stopRaiseLower</CallbackMethod>
</Action>
<Action id="getBatteryLevels">
<Name>Poll Devices for Battery Status</Name>
<CallbackMethod>getBatteryLevels</CallbackMethod>
<ConfigUI>
<Field id="gateway" type="menu">
<Label>Gateway:</Label>
<List class="self" method="get_gateway_list" dynamicReload="true"/>
<CallbackMethod>menuChanged</CallbackMethod>
</Field>
</ConfigUI>
</Action>
<Action id="sendRawCommand">
<Name>Send Raw Command</Name>
<CallbackMethod>sendRawCommand</CallbackMethod>
Expand Down
70 changes: 66 additions & 4 deletions Lutron RadioRA 2.indigoPlugin/Contents/Server Plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
PROP_BUTTONTYPE = "ButtonType"
PROP_OUTPUTTYPE = "OutputType"
PROP_LASTSPEED = "LastSpeed"
PROP_SUPPORTS_BATTERY = "SupportsBatteryLevel"

# device state keys
ACTUALSPEED = "ActualSpeed"
Expand Down Expand Up @@ -1225,7 +1226,12 @@ def _cmdDeviceChange(self, cmd, gatewayID):
id = cmdArray[1]
button = cmdArray[2]
action = cmdArray[3]
if action == '2': # this is a motion sensor

if action == '22': # battery status report
self._doBatteryUpdate(gatewayID, cmdArray)
return

elif action == '2': # this is a motion sensor
if cmdArray[4] == '3':
status = '1'
elif cmdArray[4] == '4':
Expand All @@ -1239,7 +1245,6 @@ def _cmdDeviceChange(self, cmd, gatewayID):

keypadid = "{}:{}.{}".format(gatewayID, id, button)


if keypadid in self.phantomButtons:
self.logger.debug(u"Received a phantom button status message: " + cmd)
dev = self.phantomButtons[keypadid]
Expand Down Expand Up @@ -1295,16 +1300,49 @@ def _cmdDeviceChange(self, cmd, gatewayID):
dev.updateStateOnServer(ONOFF, True)
self.logger.info(u"Received: CCI {} {}".format(dev.name, "Closed"))

if id in self.sensors:
sensorid = "{}:{}".format(gatewayID, id)

if sensorid in self.sensors:
self.logger.debug(u"Received a sensor status message: " + cmd)
dev = self.sensors[id]
dev = self.sensors[sensorid]
if status == '0':
dev.updateStateOnServer(ONOFF, False)
self.logger.info(u"Received: Motion Sensor {} {}".format(dev.name, "vacancy detected"))
elif status == '1':
dev.updateStateOnServer(ONOFF, True)
self.logger.info(u"Received: Motion Sensor {} {}".format(dev.name, "motion detected"))

def _doBatteryUpdate(self, gatewayID, cmdArray):
id = cmdArray[1]
button = cmdArray[2]
battery = (cmdArray[5] == "1")
batteryLow = (cmdArray[6] == "2")

self.logger.threaddebug(u"Received a Battery update: {}, battery = {}, batteryLow = {}".format(id, battery, batteryLow))
if not battery: # External power
return

devAddress = "{}:{}.{}".format(gatewayID, id, button)
if devAddress in self.picos:
device = self.picos[devAddress]

devAddress = "{}:{}".format(gatewayID, id)
if devAddress in self.sensors:
device = self.sensors[devAddress]

devAddress = "{}:{}".format(gatewayID, id)
if devAddress in self.shades:
device = self.shades[devAddress]

if battery and not device.pluginProps.get(PROP_SUPPORTS_BATTERY, False):
self.update_plugin_property(device, PROP_SUPPORTS_BATTERY, True)
if batteryLow:
device.updateStateOnServer('batteryLevel', 10)
else:
device.updateStateOnServer('batteryLevel', 90)



# IP comm has not yet been tested with _cmdHvacChange(). Currently left as is -vic13
def _cmdHvacChange(self, cmd, gatewayID):
self.logger.debug(u"Received an HVAC message: " + cmd)
Expand Down Expand Up @@ -1930,6 +1968,30 @@ def sendRawCommand(self, pluginAction):
self._sendCommand(sendCmd, gateway)
self.logger.debug(u"Sent Raw Command: '{}' to gateway {}".format(sendCmd, gateway))

def getBatteryLevels(self, pluginAction):

gateway = pluginAction.props[PROP_GATEWAY]
self.logger.debug(u"Getting Battery Status for gateway {}".format(gateway))

for sensorid in self.sensors:
device = self.sensors[sensorid]
integrationID = device.pluginProps[PROP_INTEGRATION_ID]
sendCmd = ("?DEVICE,{},1,22".format(integrationID))
self._sendCommand(sendCmd, gateway)

for shadeid in self.shades:
device = self.shades[shadeid]
integrationID = device.pluginProps[PROP_INTEGRATION_ID]
sendCmd = ("?DEVICE,{},1,22".format(integrationID))
self._sendCommand(sendCmd, gateway)

for buttonid in self.picos:
device = self.picos[buttonid]
integrationID = device.pluginProps[PROP_INTEGRATION_ID]
componentID = device.pluginProps[PROP_COMPONENT_ID]
sendCmd = ("?DEVICE,{},{},22".format(integrationID, componentID))
self._sendCommand(sendCmd, gateway)

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

def get_gateway_list(self, filter="", valuesDict=None, typeId="", targetId=0):
Expand Down

0 comments on commit 5d1cf01

Please sign in to comment.