tlyakhov / python-decora_wifi

Python Library for Interacting with Leviton Decora Smart WiFi Switches & Dimmers
MIT License
37 stars 21 forks source link

Find or Get Switch by Name Instead of ID #10

Open sundown94 opened 5 years ago

sundown94 commented 5 years ago

Hi! I am new to this code and the Leviton Decora switches, but I think I am a quick learner. That said, I have been trying to modify the cli_test.py script to control a single device at a time without having to iterate through all of them to find the one I want to control. So I used the original cli_test.py script initially to show me the ID for one of my switches, and then used that ID with the find_by_id_iot_switches() function to get the individual device. However, as I expand my system to include more devices, I would rather reference my devices by their names instead of by ID (i.e., be able to pass the name into the script as a command-line arg and then further pass that name to the decora functions to control the switch). Is there a way to do this? I am thinking of a function similar to find_by_id_iot_switches(), but instead it might be called something like find_by_name_iot_switches(). Is this possible?

Thanks in advance for your help (especially since I realize from a recent post that you are no longer using Leviton. Steve-

W0GER commented 5 years ago

In code, it is better to use the ID than the name. The ID is less likely to change. If the user changes the name, then where ever it's referenced in code would also need to change.

sundown94 commented 5 years ago

Thank you, I totally get what you are saying..it makes sense. As background, I am integrating these switches (the mini-plugs actually) with my existing X10 system using HA-Bridge. HA-Bridge allows me to run scripts (shell or python, etc.), so I would only need to change the name of the Decora device in HA-Bridge on the command line of the script. In other words, technically the name would not really be hard coded inside the script. If I'm forced to use ID (where the #s are not intuitive and were never designed to be), then it will be harder to remember what ID # goes with each switch. If I have to use ID, then I will probably have to create a cross-reference table for myself to look at whenever I'm changing my settings. Having said all of that, I can definitely use ID, but I'm still wondering if there is a way to use name instead? Thanks again!! Steve-