Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use {DeviceName} instead of {DeviceID} alternatively for API commands #352

Merged
merged 3 commits into from
May 23, 2023
Merged

Use {DeviceName} instead of {DeviceID} alternatively for API commands #352

merged 3 commits into from
May 23, 2023

Conversation

mschlenstedt
Copy link
Contributor

I added the possibility to use {DeviceName} instead of {DeviceID} in API commands for a more convinient way to set up API calls. If one uses {DeviceName} the Device Names must be absolutely unique, of course.

server/server.py Outdated
Comment on lines 388 to 392
if(id not in deviceslist):
for key in deviceslist:
if deviceslist[key]['name'] == urllib.parse.unquote(id):
id = deviceslist[key]['id']
break
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor note: Since we are repeating this same logic 6 times, should we consider making this a function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, of course. I was unsure to put it into a function... I will change it accordingly.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also pull the urllib.parse.unquote(id) out of the loop and move it to a variable beforehand instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I included both suggestions: getDeviceIdByName as a function and pull urllib.parse.unquote(id) out of the loop.

@jasonacox jasonacox merged commit e3408a1 into jasonacox:master May 23, 2023
@jasonacox
Copy link
Owner

Thanks, @mschlenstedt ! Nice addition.

# by DeviceID
$ curl http://localhost:8888/status/xxxxxxxxxxxxxxxxxx01
{"devId": "xxxxxxxxxxxxxxxxxx01", "dps": {"1": true, "9": 0}}

# by DeviceName
$ curl http://localhost:8888/status/Kitchen%20Light
{"devId": "xxxxxxxxxxxxxxxxxx01", "dps": {"1": true, "9": 0}}
$ curl http://localhost:8888/status/SmartBulb                                
{"devId": "xxxxxxxxxxxxxxxxxx02", "dps": {"20": true, "21": "white", "22": 1000, "24": "000003e803e8", "25":"07464602000003e803e800000000464602007803e803e80000000046460200f003e803e800000000464602003d03e803e80000000046460200ae03e803e800000000464602011303e803e800000000", "26": 0}}

I updated the build to t7 and will push it to dockerhub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants