lucien2k / sonoff-python

Make use of your sonoff smart switches without flashing them via the cloud APIs
MIT License
51 stars 32 forks source link

[Doc request]: more explanation / examples of library usage #19

Open chinezbrun opened 4 years ago

chinezbrun commented 4 years ago

on Python 3.6 I have installed the library: pip install sonoff-python and requirements websocket,requests, websocket-client

running the example "Usage" i get below error:

File "S:\Development\Python_Scripts\teste_nevalidate\sonofflan_test-1.py", line 4, in s = sonoff.Sonoff(config.username, config.password, config.api_region, config.user_apikey, config.bearer_token) AttributeError: module 'config' has no attribute 'username'

Do I missed something?

Dan

dsancheznet commented 4 years ago

I personally dropped the use of config (which by the way is not necessary for the library to work). Try using variables instead of the config module, like so...

username = "my-e@mail.com" # Your username
password = "mypassword" # Your password
api_region = "eu" # Your region { 'eu', 'us', 'cn' }

s = sonoff.Sonoff(username, password, api_region)

User_api and Bearer_token default to none and can be omitted during instantiation. They can be obtained for later use after connection.

The source code is pretty self explanatory, by the way.

Best regards

chinezbrun commented 4 years ago

%Run sonofflan_test.py Grace period activated! devices: []

Thanks for your answer! I tried, seems that is connected but no devices... I have 4 sonoff Basic DYI registered.

Dan

lucien2k commented 4 years ago

%Run sonofflan_test.py Grace period activated! devices: []

Thanks for your answer! I tried, seems that is connected but no devices... I have 4 sonoff Basic DYI registered.

Dan

Hey Dan!

Maybe try the version in develop, I think the no devices found might be fixed there.

Sorry I've had a busy few months and not sorted out a few things.

Alex

marcinlubojanski commented 4 years ago

%Run sonofflan_test.py Grace period activated! devices: []

Thanks for your answer! I tried, seems that is connected but no devices... I have 4 sonoff Basic DYI registered.

Dan

It might be the same issue with "params incomplete" which I was getting. Have a look here to see for a possible solution.

chinezbrun commented 4 years ago

Maybe try the version in develop From where?

chinezbrun commented 4 years ago

It might be the same issue with "params incomplete" which I was getting. Have a look here to see for a possible solution.

Really do not know from where to get all those parameters.

marcinlubojanski commented 4 years ago

It might be the same issue with "params incomplete" which I was getting. Have a look here to see for a possible solution.

Really do not know from where to get all those parameters.

Just try the changed request as I wrote in the other issue. It requires also to add the parameters to do_login method (or slight modification of the request to use app_details). I took it from here: https://github.com/peterbuga/HASS-sonoff-ewelink/blob/master/sonoff/__init__.py