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

Cant get the list of devices #26

Open jadolg opened 3 years ago

jadolg commented 3 years ago

I managed to correctly log in, but the list of devices is empty. This is what I'm doing:

import sonoff

s = sonoff.Sonoff("email@example.com", "mypassword", "eu")
devices = s.get_devices()

And I'm actively using the devices on the ewelink application and with google home. Maybe something changed in the API?

amiltonjr commented 3 years ago

I am having the same issue. The only thing it prints out is:

WARNING:sonoff.sonoff:Grace period activated!

Does anybody know why it is happening?

import json
import datetime

import logging
logging.basicConfig()
logger = logging.getLogger('logger')

import sonoff

def serialize(obj):
    """JSON serializer for objects not serializable by default json code"""

    if isinstance(obj, datetime.date):
        serial = obj.isoformat()
        return serial

    if isinstance(obj, datetime.time):
        serial = obj.isoformat()
        return serial

    if isinstance(obj, datetime.timedelta):
        return obj.total_seconds()

    return obj.__dict__

username        = 'username_goes_here'
password        = 'password_goes_here'
api_region      = 'us'

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

print ("\nSonoff object: " + json.dumps(s, default=serialize) + "\n")

devices = s.get_devices(True)

if devices:
    device_id = devices[0]['deviceid']
    print("Device example:" + device_id)
else:
    print "No device was found!"
Tahutipai commented 3 years ago

Same issue here. All I get is "Grace period activated!"

laurobmb commented 3 years ago

Does it have to do with the wrong call at ewelink login?

    if 'error' in resp and resp['error'] in [HTTP_BAD_REQUEST, HTTP_UNAUTHORIZED]:
        # @IMPROVE add maybe a service call / switch to deactivate sonoff component
        if self.is_grace_period():
            _LOGGER.warning("Grace period activated!")
marcinlubojanski commented 3 years ago

You can't use app and python at the same time with same credentials. Create another account and share access to your device.

jadolg commented 3 years ago

The new account approach won't work for me either :disappointed: I created a new account, logged out, logged in on mine, and shared the devices with the new one. I get the same behavior.

jadolg commented 3 years ago

I have also tried this one https://github.com/skydiver/ewelink-api/ and it works with the same credentials.

jadolg commented 3 years ago

The problem seems to go a bit further than this grace period message. I do not fully understand the purpose but I decided to wait for it. The code to get the devices list does this:

        # we are in the grace period, no updates to the devices
        if self._skipped_login and self.is_grace_period():
            _LOGGER.info("Grace period active")
            return self._devices

So I decided to wait in my code to see what happens:

s = sonoff.Sonoff("email@example.com", "mypassword", "eu")
while s.is_grace_period():
    print(".")
    time.sleep(1)
devices = s.get_devices(force_update=True)
pprint(devices)

And I got this:

.
Grace period activated!
.
.
.
.
.
.
.
.
{'error': 400, 'msg': 'params incomplete'}
Grace period activated!

Note that I added a . per retry every second. Looks like the API changed and this project is not up to date.

mattmofr commented 3 years ago

Hi everyone, I have the same issue here. Any solution in sight ?

henrykozhaya commented 3 years ago

Same issue here!

bertpig commented 2 years ago

This is most likely due to the app ID and secret not being update - see issue #24 which is direct outreach from the guys at eWelink. If you use a valid app ID / secret then listing and on/off switching appears to work - although this might only apply to VIP/paid accounts now (I don't have an unpaid account to test with).

tvdsluijs commented 2 years ago

So... I guess this project is a dead end? Any other working python Sonoff packages out there?

marcinlubojanski commented 2 years ago

Check #27. I have posted there my code which works for me.