MisterWil / abodepy

A thin Python wrapper for the Abode alarm API
MIT License
50 stars 17 forks source link

Replace dictionary with elif ladder #17

Closed vickyg3 closed 7 years ago

vickyg3 commented 7 years ago

When using a dictionary to return the value based on generic_type, all the cases are executed when creating the dictionary (i.e. all the objects will be created and the right one will be picked in the end). Which is obviously a waste (and gets buggy because of unintentional calls into _new_sensor). Replace the dictionary with a elif ladder. This is probably a bit more characters, but worth the performance improvement.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-0.02%) to 86.92% when pulling 7b385e85151edc2a96aaaa287beb996d4b9ed9c8 on vickyg3:master into f6284ab70eb6799abe93ff7160b69abb63ebd7b6 on MisterWil:master.

MisterWil commented 7 years ago

Thanks for this! Python isn't my day-job language so I've still got a lot to learn. :-)

vickyg3 commented 7 years ago

Thanks for the quick merge. :)

This was causing trouble with my HomeAssistant instance because it had a nest thermostat and it was failing by the call to _new_sensor() on the thermostat which was unnecessary. Any idea on if you can update pypi with this change so that i can bump up the dependency on HA ?

MisterWil commented 7 years ago

Sure! I pushed 0.11.7 for you. I'll need to make another PR in HA...

vickyg3 commented 7 years ago

Awesome, thanks. I can do the PR on HA.