Skip to content

Commit

Permalink
Added flag to force rename on device creation
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyingDiver committed Jun 5, 2022
1 parent aa475a1 commit a7da844
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Lutron RadioRA 2.indigoPlugin/Contents/Info.plist
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>PluginVersion</key>
<string>2022.0.3</string>
<string>2022.0.4</string>
<key>ServerApiVersion</key>
<string>3.0</string>
<key>IwsApiVersion</key>
Expand Down
Expand Up @@ -90,6 +90,10 @@
<Label>Create Triggers for all Room Groups:</Label>
</Field>
<Field id="separator2" type="separator" />
<Field id="rename_devices" type="checkbox" defaultValue="false">
<Label>Force rename existing devices:</Label>
</Field>
<Field id="separator3" type="separator" />
<Field id="local_note" type="label">
<Label>To use an existing XML file instead of downloading the XML data from the repeater, check this box and enter the path/name of the file.
You MUST have a repeater selected above.
Expand Down
17 changes: 11 additions & 6 deletions Lutron RadioRA 2.indigoPlugin/Contents/Server Plugin/plugin.py
Expand Up @@ -2254,6 +2254,7 @@ def createRRA2Devices(self, valuesDict):
self.create_unused_phantom = bool(valuesDict["create_unused_phantom"])
self.create_event_triggers = bool(valuesDict["create_event_triggers"])
self.create_group_triggers = bool(valuesDict["create_group_triggers"])
self.rename_devices = bool(valuesDict["rename_devices"])

if bool(valuesDict["use_local"]):
self.logger.info(
Expand Down Expand Up @@ -2758,14 +2759,18 @@ def createLutronDevice(self, devType, name, address, props, room):
# If it does exist, update with the new properties

for dev in indigo.devices.iter("self"):
if dev.address == address:
if dev.pluginProps.get(PROP_ROOM, None):
self.logger.debug(f"Skipping existing device: '{name}' ({address})")
return dev
else:
if dev.address == address: # existing device

if not dev.pluginProps.get(PROP_ROOM, None):
self.logger.debug(f"Adding ROOM property to existing device: '{name}' ({address})")
self.update_plugin_property(dev, PROP_ROOM, new_value=room)
return dev

if self.rename_devices and dev.name != name:
self.logger.debug(f"Renaming '{dev.name}' to '{name}'")
dev.name = name
dev.replaceOnServer()

return dev

# Pick the folder for this device, create it if necessary

Expand Down

0 comments on commit a7da844

Please sign in to comment.