tlyakhov / python-decora_wifi

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

Fix login errors with shared residences #8

Closed trainman419 closed 5 years ago

trainman419 commented 5 years ago

My Leviton residence is shared with one of my roommates, and they're the primary account holder.

I was getting this error when trying to run the cli-test tool:

Permission: {'invitationId': XXXX, 'personId': 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX', 'status': 'active', 'residentialAccountId': None, 'created': '2018-05-10T05:26:26.000Z', 'residenceId': XXXX, 'id': XXXX, 'access': 'admin', 'lastUpdated': None}
myLeviton API call (/ResidentialAccounts/None/residences) failed: 401, {"error":{"statusCode":401,"name":"Error","message":"Authorization Required"}}

It looks like the residentialAccountId isn't populated for shared accounts, and residenceId is populated instead. This fix detects that scenario and creates the appropriate Residence object, which seems to work.