shauntarves / wyze-sdk

A modern Python client for controlling Wyze devices.
The Unlicense
313 stars 49 forks source link

Lost #144

Closed wkrasner closed 1 year ago

wkrasner commented 1 year ago

Hi I am trying to reconfigure my python scripts for the new API authentication model. I am lost as to where to start. Thanks for any help to get me over the hump.

Will

shauntarves commented 1 year ago

Hi Will, there are a few steps now:

First, create a Wyze API key on their website and note/store the key id and the actual key: https://developer-api-console.wyze.com/#/apikey/view

Then, you need to provide these two new strings to the wyze-sdk via your scripts. The exact details will vary depending on how you've configured your scripts that use this wyze-sdk, but essentially, you need to provide them when calling the login method (if you use that) or when creating the client:

response = Client().login(
    email=os.environ['WYZE_EMAIL'],
    password=os.environ['WYZE_PASSWORD'],
    key_id=os.environ['WYZE_KEY_ID'], <-- new key_id data from the first step
    api_key=os.environ['WYZE_API_KEY'] <-- new api_key data from the first step
)

If you don't store these fields as environment variables, then just put the string values in the call above

wkrasner commented 1 year ago

Thank you for the quick reply:

I tried this, it errors out:

import os import wyze_sdk import time from wyze_sdk import Client from wyze_sdk.errors import WyzeApiError

This will be called from Vac1.bat

response = Client().login( @.***'], password=os.environ['xxxxxxxx'], key_id=os.environ['xxxxxxxx'], api_key=os.environ['lxxxxxxxxxxxxx'] )

from wyze_sdk.models.devices import VacuumMode

client.vacuums.clean(device_mac='JAxxx', device_model='JA_xx') Will William C. Krasner APN, Esq. JD,MSN,MBA Attorney At Law and Advanced Practice Nurse Specialized in Family Medicine Focusing in Immigration and Provider Defense (Federal Healthcare) Focusing in EMS and Medical Consulting M:609.820.5401 F:609.482.8161 @.

*Licensed by the California Bar **Licensed in NJ,PA,NH,FL member of: The Association of Attorney Nurses(TAANA) The American Bar Association (ABA) The Association of Advanced Practice Nurses(AANP)

On Fri, Jul 28, 2023 at 7:33 AM Shaun Tarves @.***> wrote:

Hi Will, there are a few steps now:

First, create a Wyze API key on their website and note/store the key id and the actual key: https://developer-api-console.wyze.com/#/apikey/view

Then, you need to provide these two new strings to the wyze-sdk via your scripts. The exact details will vary depending on how you've configured your scripts that use this wyze-sdk, but essentially, you need to provide them when calling the login method (if you use that) or when creating the client:

response = Client().login( email=os.environ['WYZE_EMAIL'], password=os.environ['WYZE_PASSWORD'], key_id=os.environ['WYZE_KEY_ID'], <-- new key_id data from the first step api_key=os.environ['WYZE_API_KEY'] <-- new api_key data from the first step )

If you don't store these fields as environment variables, then just put the string values in the call above

— Reply to this email directly, view it on GitHub https://github.com/shauntarves/wyze-sdk/issues/144#issuecomment-1655531366, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIRXCGEVRXZULLZV7QNGTWDXSOPONANCNFSM6AAAAAA23KH5ZE . You are receiving this because you authored the thread.Message ID: @.***>

shauntarves commented 1 year ago

Oh, I think there's some confusion about what the login call does.

There are two ways to make a usable client...you can either call the Client() constructor with all the account parameters or you can do a login() call first to get an access token and then provide that access token to the Client() constructor.

I think the easiest approach for you will be to just create a client and let the SDK do the work for you. Also, just based on what you pasted in your comment, you may not be using environment variables correctly. Start simple, and just set the fields directly in that Client() constructor:

...
client = Client(
    email='<your email>',
    password='<your password>',
    key_id='<your key id>',
    api_key='<your api key>'
)
...
client.vacuum.xxx
wkrasner commented 1 year ago

Thanks Shaun,

I did try that and received the error: TypeError: Client.init() got an unexpected keyword argument 'key_id'

shauntarves commented 1 year ago

Oh, that almost seems like you don't have the latest version of the library. v2.0.0 should be what you're looking for. That has the changes to support all of the latest wyze api key stuff.

On Fri, Jul 28, 2023 at 9:16 AM wkrasner @.***> wrote:

Thanks Shaun,

I did try that and received the error: TypeError: Client.init() got an unexpected keyword argument 'key_id'

— Reply to this email directly, view it on GitHub https://github.com/shauntarves/wyze-sdk/issues/144#issuecomment-1655669563, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABEDBMETNVJZKFWVZGZ5WRTXSO3TZANCNFSM6AAAAAA23KH5ZE . You are receiving this because you modified the open/close state.Message ID: @.***>

wkrasner commented 1 year ago

Shaun

Again Thanks for your help.

Ok I looked for the library in the install directory, Where and how do I update it? I Am a neophyte at python

Thanks Will

On Fri, Jul 28, 2023 at 9:35 AM Shaun Tarves @.***> wrote:

Oh, that almost seems like you don't have the latest version of the library. v2.0.0 should be what you're looking for. That has the changes to support all of the latest wyze api key stuff.

On Fri, Jul 28, 2023 at 9:16 AM wkrasner @.***> wrote:

Thanks Shaun,

I did try that and received the error: TypeError: Client.init() got an unexpected keyword argument 'key_id'

— Reply to this email directly, view it on GitHub < https://github.com/shauntarves/wyze-sdk/issues/144#issuecomment-1655669563>,

or unsubscribe < https://github.com/notifications/unsubscribe-auth/ABEDBMETNVJZKFWVZGZ5WRTXSO3TZANCNFSM6AAAAAA23KH5ZE>

. You are receiving this because you modified the open/close state.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/shauntarves/wyze-sdk/issues/144#issuecomment-1655693558, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIRXCGFXOGNT5NQN77URBY3XSO5ZXANCNFSM6AAAAAA23KH5ZE . You are receiving this because you authored the thread.Message ID: @.***>

wkrasner commented 1 year ago

Shaun

All is working. I reinstalled the sdk and she is back on line. Thank you for your help and thank you for a great reverse engineering project.

Sincerely Will William C. Krasner APN, Esq. JD,MSN,MBA Attorney At Law and Advanced Practice Nurse Specialized in Family Medicine Focusing in Immigration and Provider Defense (Federal Healthcare) Focusing in EMS and Medical Consulting M:609.820.5401 F:609.482.8161 @.

*Licensed by the California Bar **Licensed in NJ,PA,NH,FL member of: The Association of Attorney Nurses(TAANA) The American Bar Association (ABA) The Association of Advanced Practice Nurses(AANP)

On Fri, Jul 28, 2023 at 10:52 AM William Krasner @.***> wrote:

Shaun

Again Thanks for your help.

Ok I looked for the library in the install directory, Where and how do I update it? I Am a neophyte at python

Thanks Will

On Fri, Jul 28, 2023 at 9:35 AM Shaun Tarves @.***> wrote:

Oh, that almost seems like you don't have the latest version of the library. v2.0.0 should be what you're looking for. That has the changes to support all of the latest wyze api key stuff.

On Fri, Jul 28, 2023 at 9:16 AM wkrasner @.***> wrote:

Thanks Shaun,

I did try that and received the error: TypeError: Client.init() got an unexpected keyword argument 'key_id'

— Reply to this email directly, view it on GitHub < https://github.com/shauntarves/wyze-sdk/issues/144#issuecomment-1655669563>,

or unsubscribe < https://github.com/notifications/unsubscribe-auth/ABEDBMETNVJZKFWVZGZ5WRTXSO3TZANCNFSM6AAAAAA23KH5ZE>

. You are receiving this because you modified the open/close state.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/shauntarves/wyze-sdk/issues/144#issuecomment-1655693558, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIRXCGFXOGNT5NQN77URBY3XSO5ZXANCNFSM6AAAAAA23KH5ZE . You are receiving this because you authored the thread.Message ID: @.***>