Skip to content

Commit

Permalink
feat: added change password functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
shauntarves committed Jan 21, 2024
1 parent b356a6f commit cc58d07
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
30 changes: 29 additions & 1 deletion wyze_sdk/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
ScalesClient, ThermostatsClient,
SwitchesClient, VacuumsClient)
from wyze_sdk.api.events import EventsClient
from wyze_sdk.errors import WyzeClientConfigurationError
from wyze_sdk.errors import WyzeClientConfigurationError, WyzeRequestError
from wyze_sdk.models.devices import Device, DeviceParser
from wyze_sdk.service import (ApiServiceClient, AuthServiceClient,
PlatformServiceClient, WyzeResponse)
from wyze_sdk.signature import MD5Hasher


class Client(object):
Expand Down Expand Up @@ -217,6 +218,33 @@ def user_get_info(self) -> WyzeResponse:
"""
return self._api_client().get_user_info()

def logout(self) -> WyzeResponse:
"""
Destroys the current user's session.
:rtype: WyzeResponse
"""
return self._api_client().logout()

def change_password(self, *, new_password: str, old_password: Optional[str], **kwargs) -> WyzeResponse:
"""
Changes the current user's password.
:rtype: WyzeResponse
"""
if old_password is None:
old_password = self._password
if old_password is None:
raise WyzeRequestError("Must specify old (current) password")

if new_password == old_password:
raise WyzeRequestError("Old and new passwords must be different")

return self._api_client().change_password(
old_password=MD5Hasher().hex(MD5Hasher().hex(old_password)),
new_password=MD5Hasher().hex(MD5Hasher().hex(new_password)),
)

def devices_list(self, **kwargs) -> Sequence[Device]:
"""List the devices available to the current user
Expand Down
6 changes: 6 additions & 0 deletions wyze_sdk/service/api_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ def logout(self, **kwargs) -> WyzeResponse:
kwargs.update({"sv": SV_LOGOUT})
return self.api_call('/app/user/logout', json=kwargs)

def change_password(self, **kwargs) -> WyzeResponse:
SV_CHANGE_PASSWORD = '172431db943a4448a8d818c035df0404'

kwargs.update({"sv": SV_CHANGE_PASSWORD})
return self.api_call('/app/user/change_password', json=kwargs)

def get_device_info(self, *, mac: str, model: str, **kwargs) -> WyzeResponse:
SV_GET_DEVICE_INFO = '81d1abc794ba45a39fdd21233d621e84'

Expand Down

0 comments on commit cc58d07

Please sign in to comment.